Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed_mem_trace.h
00001 00002 /** \addtogroup platform */ 00003 /** @{*/ 00004 00005 /* mbed Microcontroller Library 00006 * Copyright (c) 2006-2016 ARM Limited 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 */ 00020 00021 #ifndef __MBED_MEM_TRACE_H__ 00022 #define __MBED_MEM_TRACE_H__ 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 #include <stdint.h> 00029 #include <stddef.h> 00030 00031 /* Operation types for tracer */ 00032 enum { 00033 MBED_MEM_TRACE_MALLOC, 00034 MBED_MEM_TRACE_REALLOC, 00035 MBED_MEM_TRACE_CALLOC, 00036 MBED_MEM_TRACE_FREE 00037 }; 00038 00039 /** 00040 * \defgroup platform_mem_trace mem_trace functions 00041 * @{ 00042 */ 00043 00044 /* Prefix for the output of the default tracer */ 00045 #define MBED_MEM_DEFAULT_TRACER_PREFIX "#" 00046 00047 /** 00048 * Type of the callback used by the memory tracer. This callback is called when a memory 00049 * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled 00050 * for that memory allocation function. 00051 * 00052 * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC, 00053 * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE). 00054 * @param res the result that the memory operation returned (NULL for 'free'). 00055 * @param caller the caller of the memory operation. Note that the value of 'caller' might be 00056 * unreliable. 00057 * 00058 * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations 00059 * that triggered its call (see 'man malloc' for details): 00060 * 00061 * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size). 00062 * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size). 00063 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size). 00064 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr). 00065 */ 00066 typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...); 00067 00068 /** 00069 * Set the callback used by the memory tracer (use NULL for disable tracing). 00070 * 00071 * @param cb the callback to call on each memory operation. 00072 */ 00073 void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb); 00074 00075 /** 00076 * Trace lock. 00077 * @note Locking prevent recursive tracing of malloc/free inside relloc/calloc 00078 */ 00079 void mbed_mem_trace_lock(); 00080 00081 /** 00082 * Trace unlock. 00083 */ 00084 void mbed_mem_trace_unlock(); 00085 00086 /** 00087 * Trace a call to 'malloc'. 00088 * @param res the result of running 'malloc'. 00089 * @param size the 'size' argument given to 'malloc'. 00090 * @param caller the caller of the memory operation. 00091 * @return 'res' (the first argument). 00092 */ 00093 void *mbed_mem_trace_malloc(void *res, size_t size, void *caller); 00094 00095 /** 00096 * Trace a call to 'realloc'. 00097 * @param res the result of running 'realloc'. 00098 * @param ptr the 'ptr' argument given to 'realloc'. 00099 * @param size the 'size' argument given to 'realloc'. 00100 * @param caller the caller of the memory operation. 00101 * @return 'res' (the first argument). 00102 */ 00103 void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller); 00104 00105 /** 00106 * Trace a call to 'calloc'. 00107 * @param res the result of running 'calloc'. 00108 * @param num the 'nmemb' argument given to 'calloc'. 00109 * @param size the 'size' argument given to 'calloc'. 00110 * @param caller the caller of the memory operation. 00111 * @return 'res' (the first argument). 00112 */ 00113 void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller); 00114 00115 /** 00116 * Trace a call to 'free'. 00117 * @param ptr the 'ptr' argument given to 'free'. 00118 * @param caller the caller of the memory operation. 00119 */ 00120 void mbed_mem_trace_free(void *ptr, void *caller); 00121 00122 /** 00123 * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used 00124 * as the second argument of 'mbed_mem_trace_setup'. 00125 * 00126 * The default callback outputs trace data using 'printf', in a format that's 00127 * easily parsable by an external tool. For each memory operation, the callback 00128 * outputs a line that begins with "#<op>:<0xresult>;<0xcaller>-": 00129 * 00130 * @param op identifies the memory operation ('m' for 'malloc', 'r' for 'realloc', 00131 * 'c' for 'calloc' and 'f' for 'free'). 00132 * @param res (base 16) is the result of the memor operation. This is always NULL 00133 * for 'free', since 'free' doesn't return anything. 00134 * @param caller (base 16) is the caller of the memory operation. Note that the value 00135 * of 'caller' might be unreliable. 00136 * 00137 * The rest of the output depends on the operation being traced: 00138 * 00139 * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'. 00140 * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'. 00141 * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'. 00142 * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'. 00143 * 00144 * Examples: 00145 * 00146 * - "#m:0x20003240;0x600d-50" encodes a 'malloc' that returned 0x20003240, was called 00147 * by the instruction at 0x600D with a the 'size' argument equal to 50. 00148 * - "#f:0x0;0x602f-0x20003240" encodes a 'free' that was called by the instruction at 00149 * 0x602f with the 'ptr' argument equal to 0x20003240. 00150 */ 00151 void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...); 00152 00153 /** @}*/ 00154 00155 #ifdef __cplusplus 00156 } 00157 #endif 00158 00159 #endif// #ifndef __MBED_MEM_TRACE_H__ 00160 00161 00162 /** @}*/
Generated on Tue Jul 12 2022 14:24:26 by
