1570af302Sopenharmony_ci/* 2570af302Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4570af302Sopenharmony_ci * you may not use this file except in compliance with the License. 5570af302Sopenharmony_ci * You may obtain a copy of the License at 6570af302Sopenharmony_ci * 7570af302Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8570af302Sopenharmony_ci * 9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12570af302Sopenharmony_ci * See the License for the specific language governing permissions and 13570af302Sopenharmony_ci * limitations under the License. 14570af302Sopenharmony_ci */ 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci#ifndef _DEBUG_H 17570af302Sopenharmony_ci#define _DEBUG_H 18570af302Sopenharmony_ci 19570af302Sopenharmony_ci#ifdef __cplusplus 20570af302Sopenharmony_ciextern "C" { 21570af302Sopenharmony_ci#endif 22570af302Sopenharmony_ci 23570af302Sopenharmony_ci/** 24570af302Sopenharmony_ci * @brief Initialization of the memory debug function, including the output method of memory debug information 25570af302Sopenharmony_ci * and signal registration. You can use command line parameters, "--mwatch" or "--mrecord <full path>", to 26570af302Sopenharmony_ci * call mem_check_init(char *) when executing your program. 27570af302Sopenharmony_ci * 28570af302Sopenharmony_ci * @param f_path The full path of the file to be created where the memory debug information will be written. 29570af302Sopenharmony_ci * If the param is NULL or the file creation fails, the memory debug information will be output via serial 30570af302Sopenharmony_ci * port. 31570af302Sopenharmony_ci * 32570af302Sopenharmony_ci * @return void. 33570af302Sopenharmony_ci */ 34570af302Sopenharmony_civoid mem_check_init(char *f_path); 35570af302Sopenharmony_ci 36570af302Sopenharmony_ci/** 37570af302Sopenharmony_ci * @brief View thread-level heap memory usage information, signal registration index is 35, you can use "kill -35 pid" 38570af302Sopenharmony_ci * to call watch_mem() when your program is running. The output way of memory debug information is determined by how 39570af302Sopenharmony_ci * the mem_check_init(char *) interface is called. 40570af302Sopenharmony_ci * 41570af302Sopenharmony_ci * @param void. 42570af302Sopenharmony_ci * 43570af302Sopenharmony_ci * @return void. 44570af302Sopenharmony_ci */ 45570af302Sopenharmony_civoid watch_mem(void); 46570af302Sopenharmony_ci 47570af302Sopenharmony_ci/** 48570af302Sopenharmony_ci * @brief Check whether the heap memory leak is exist or not, signal registration index is 36, you can use "kill -36 49570af302Sopenharmony_ci * pid" to call check_leak() when your program is running. The output way of memory debug information is determined by 50570af302Sopenharmony_ci * how the mem_check_init(char *) interface is called. 51570af302Sopenharmony_ci * 52570af302Sopenharmony_ci * @param void. 53570af302Sopenharmony_ci * 54570af302Sopenharmony_ci * @return void. 55570af302Sopenharmony_ci */ 56570af302Sopenharmony_civoid check_leak(void); 57570af302Sopenharmony_ci 58570af302Sopenharmony_ci/** 59570af302Sopenharmony_ci * @brief Check whether the heap memory is integrited or not, signal registration index is 37, you can use "kill -37 60570af302Sopenharmony_ci * pid" to call check_heap_integrity() when your program is running. The output way of memory debug information is 61570af302Sopenharmony_ci * determined by how the mem_check_init(char *) interface is called. 62570af302Sopenharmony_ci * 63570af302Sopenharmony_ci * @param void. 64570af302Sopenharmony_ci * 65570af302Sopenharmony_ci * @return void. 66570af302Sopenharmony_ci */ 67570af302Sopenharmony_civoid check_heap_integrity(void); 68570af302Sopenharmony_ci 69570af302Sopenharmony_ci/** 70570af302Sopenharmony_ci * @brief Store the address of the call stack information, the max number is param size. 71570af302Sopenharmony_ci * 72570af302Sopenharmony_ci * @param buffer The array to store address of the call stack information. 73570af302Sopenharmony_ci * @param size The size of buffer. 74570af302Sopenharmony_ci * 75570af302Sopenharmony_ci * @return The exact number of the address. 76570af302Sopenharmony_ci */ 77570af302Sopenharmony_ciint backtrace(void **buffer, int size); 78570af302Sopenharmony_ci 79570af302Sopenharmony_ci/** 80570af302Sopenharmony_ci * @brief Find the symbol information corresponding to the address stored in the buffer for dynamic linking. 81570af302Sopenharmony_ci * 82570af302Sopenharmony_ci * @param buffer The array stored address of the exact number. 83570af302Sopenharmony_ci * @param size The exact number of the address stored in the buffer. 84570af302Sopenharmony_ci * 85570af302Sopenharmony_ci * @return The pointer to the memory allocated from heap holds the symbol information corresponding to the address 86570af302Sopenharmony_ci * stored in the buffer. You should free the memory the pointer points to after calling backtrace_symbols(). 87570af302Sopenharmony_ci */ 88570af302Sopenharmony_cichar **backtrace_symbols(void *const *buffer, int size); 89570af302Sopenharmony_ci 90570af302Sopenharmony_ci/** 91570af302Sopenharmony_ci * @brief Print the call stack information of the function calling print_trace(). 92570af302Sopenharmony_ci * 93570af302Sopenharmony_ci * @param void. 94570af302Sopenharmony_ci * 95570af302Sopenharmony_ci * @return void. 96570af302Sopenharmony_ci */ 97570af302Sopenharmony_civoid print_trace(void); 98570af302Sopenharmony_ci 99570af302Sopenharmony_ci#ifdef __cplusplus 100570af302Sopenharmony_ci} 101570af302Sopenharmony_ci#endif 102570af302Sopenharmony_ci 103570af302Sopenharmony_ci#endif 104