1 #ifndef _DEBUG_H 2 #define _DEBUG_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 /** 9 * @brief Initialization of the memory debug function, including the output method of memory debug information 10 * and signal registration. You can use command line parameters, "--mwatch" or "--mrecord <full path>", to 11 * call mem_check_init(char *) when executing your program. 12 * 13 * @param f_path The full path of the file to be created where the memory debug information will be written. 14 * If the param is NULL or the file creation fails, the memory debug information will be output via serial 15 * port. 16 * 17 * @return void. 18 */ 19 void mem_check_init(char *f_path); 20 21 /** 22 * @brief View thread-level heap memory usage information, signal registration index is 35, you can use "kill -35 pid" 23 * to call watch_mem() when your program is running. The output way of memory debug information is determined by how 24 * the mem_check_init(char *) interface is called. 25 * 26 * @param void. 27 * 28 * @return void. 29 */ 30 void watch_mem(void); 31 32 /** 33 * @brief Check whether the heap memory leak is exist or not, signal registration index is 36, you can use "kill -36 34 * pid" to call check_leak() when your program is running. The output way of memory debug information is determined by 35 * how the mem_check_init(char *) interface is called. 36 * 37 * @param void. 38 * 39 * @return void. 40 */ 41 void check_leak(void); 42 43 /** 44 * @brief Check whether the heap memory is integrited or not, signal registration index is 37, you can use "kill -37 45 * pid" to call check_heap_integrity() when your program is running. The output way of memory debug information is 46 * determined by how the mem_check_init(char *) interface is called. 47 * 48 * @param void. 49 * 50 * @return void. 51 */ 52 void check_heap_integrity(void); 53 54 /** 55 * @brief Store the address of the call stack information, the max number is param size. 56 * 57 * @param buffer The array to store address of the call stack information. 58 * @param size The size of buffer. 59 * 60 * @return The exact number of the address. 61 */ 62 int backtrace(void **buffer, int size); 63 64 /** 65 * @brief Find the symbol information corresponding to the address stored in the buffer for dynamic linking. 66 * 67 * @param buffer The array stored address of the exact number. 68 * @param size The exact number of the address stored in the buffer. 69 * 70 * @return The pointer to the memory allocated from heap holds the symbol information corresponding to the address 71 * stored in the buffer. You should free the memory the pointer points to after calling backtrace_symbols(). 72 */ 73 char **backtrace_symbols(void *const *buffer, int size); 74 75 /** 76 * @brief Print the call stack information of the function calling print_trace(). 77 * 78 * @param void. 79 * 80 * @return void. 81 */ 82 void print_trace(void); 83 84 #ifdef __cplusplus 85 } 86 #endif 87 88 #endif 89