1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef _DEBUG_H 17 #define _DEBUG_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** 24 * @brief Initialization of the memory debug function, including the output method of memory debug information 25 * and signal registration. You can use command line parameters, "--mwatch" or "--mrecord <full path>", to 26 * call mem_check_init(char *) when executing your program. 27 * 28 * @param f_path The full path of the file to be created where the memory debug information will be written. 29 * If the param is NULL or the file creation fails, the memory debug information will be output via serial 30 * port. 31 * 32 * @return void. 33 */ 34 void mem_check_init(char *f_path); 35 36 /** 37 * @brief View thread-level heap memory usage information, signal registration index is 35, you can use "kill -35 pid" 38 * to call watch_mem() when your program is running. The output way of memory debug information is determined by how 39 * the mem_check_init(char *) interface is called. 40 * 41 * @param void. 42 * 43 * @return void. 44 */ 45 void watch_mem(void); 46 47 /** 48 * @brief Check whether the heap memory leak is exist or not, signal registration index is 36, you can use "kill -36 49 * pid" to call check_leak() when your program is running. The output way of memory debug information is determined by 50 * how the mem_check_init(char *) interface is called. 51 * 52 * @param void. 53 * 54 * @return void. 55 */ 56 void check_leak(void); 57 58 /** 59 * @brief Check whether the heap memory is integrited or not, signal registration index is 37, you can use "kill -37 60 * pid" to call check_heap_integrity() when your program is running. The output way of memory debug information is 61 * determined by how the mem_check_init(char *) interface is called. 62 * 63 * @param void. 64 * 65 * @return void. 66 */ 67 void check_heap_integrity(void); 68 69 /** 70 * @brief Store the address of the call stack information, the max number is param size. 71 * 72 * @param buffer The array to store address of the call stack information. 73 * @param size The size of buffer. 74 * 75 * @return The exact number of the address. 76 */ 77 int backtrace(void **buffer, int size); 78 79 /** 80 * @brief Find the symbol information corresponding to the address stored in the buffer for dynamic linking. 81 * 82 * @param buffer The array stored address of the exact number. 83 * @param size The exact number of the address stored in the buffer. 84 * 85 * @return The pointer to the memory allocated from heap holds the symbol information corresponding to the address 86 * stored in the buffer. You should free the memory the pointer points to after calling backtrace_symbols(). 87 */ 88 char **backtrace_symbols(void *const *buffer, int size); 89 90 /** 91 * @brief Print the call stack information of the function calling print_trace(). 92 * 93 * @param void. 94 * 95 * @return void. 96 */ 97 void print_trace(void); 98 99 #ifdef __cplusplus 100 } 101 #endif 102 103 #endif 104