Debugging

If F_MEMORY_DEBUG is enabled, the memory debugging system will create macros that replace malloc, free and realloc and allows the system to keppt track of and report where memory is beeing allocated, how much and if the memory is beeing freed. This is very useful for finding memory leaks in large applications. The system can also over allocate memory and fill it with a magic number and can therfor detect if the application writes outside of the allocated memory. if F_EXIT_CRASH is defined, then exit(); will be replaced with a funtion that writes to NULL. This will make it trivial ti find out where an application exits using any debugger.,

f_debug_memory_init

void f_debug_memory_init(void (*lock)(void *mutex), void (*unlock)(void *mutex), void *mutex);

Description: Required for memory debugger to be thread safe

f_debug_mem_malloc

void *f_debug_mem_malloc(uint size, char *file, uint line);

Description: Replaces malloc and records the c file and line where it was called

f_debug_mem_realloc

void *f_debug_mem_realloc(void *pointer, uint size, char *file, uint line);

Description: Replaces realloc and records the c file and line where it was called

f_debug_mem_free

void f_debug_mem_free(void *buf, char *file, uint line);

Description: Replaces free and records the c file and line where it was called

f_debug_mem_comment

boolean f_debug_mem_comment(void *buf, char *comment);

Description: add a comment to an allocation that can help identyfy its use.

f_debug_mem_print

void f_debug_mem_print(uint min_allocs);

Description: Prints§ out a list of all allocations made, their location, how much memorey each has allocated, freed, and how many allocations have been made. The min_allocs parameter can be set to avoid printing any allocations that have been made fewer times then min_allocs

f_debug_mem_reset

void f_debug_mem_reset(void);

Description: f_debug_mem_reset allows you to clear all memory stored in the debugging system if you only want to record allocations after a specific point in your code

f_debug_mem_consumption

size_t f_debug_mem_consumption(void);

Description: add up all memory consumed by mallocsd and reallocs coverd by the memory debugger .

f_debug_mem_query

boolean f_debug_mem_query(void *pointer, uint *line, char **file, uint64 *size);

Description: query the size and place of allocation of a pointer

f_debug_mem_test

boolean f_debug_mem_test(void *pointer, uint64 size, boolean ignore_not_found);

Description: query if a bit of memory is safe to access.

f_debug_memory

boolean f_debug_memory();

Description: f_debug_memory checks if any of the bounds of any allocation has been over written and reports where to standard out. The function returns TRUE if any error was found

f_debug_memory_fopen

void *f_debug_memory_fopen(const char *file_name, const char *mode, char *file, uint line);

f_debug_memory_fclose

void f_debug_memory_fclose(void *f, char *file, uint line);

exit_crash

void exit_crash(uint i);

Description: finction guaranteed to crash (Writes to NULL).