The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
platform/mbed_mem_trace.h@169:a7c7b631e539, 2018-06-22 (annotated)
- Committer:
- Anna Bridge
- Date:
- Fri Jun 22 15:38:59 2018 +0100
- Revision:
- 169:a7c7b631e539
- Parent:
- 160:5571c4ff569f
- Child:
- 170:e95d10626187
mbed library. Release version 162
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 156:ff21514d8981 | 1 | |
AnnaBridge | 156:ff21514d8981 | 2 | /** \addtogroup platform */ |
AnnaBridge | 156:ff21514d8981 | 3 | /** @{*/ |
AnnaBridge | 158:1c57384330a6 | 4 | |
AnnaBridge | 156:ff21514d8981 | 5 | /* mbed Microcontroller Library |
AnnaBridge | 156:ff21514d8981 | 6 | * Copyright (c) 2006-2016 ARM Limited |
AnnaBridge | 156:ff21514d8981 | 7 | * |
AnnaBridge | 156:ff21514d8981 | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 156:ff21514d8981 | 9 | * you may not use this file except in compliance with the License. |
AnnaBridge | 156:ff21514d8981 | 10 | * You may obtain a copy of the License at |
AnnaBridge | 156:ff21514d8981 | 11 | * |
AnnaBridge | 156:ff21514d8981 | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 156:ff21514d8981 | 13 | * |
AnnaBridge | 156:ff21514d8981 | 14 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 156:ff21514d8981 | 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 156:ff21514d8981 | 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 156:ff21514d8981 | 17 | * See the License for the specific language governing permissions and |
AnnaBridge | 156:ff21514d8981 | 18 | * limitations under the License. |
AnnaBridge | 156:ff21514d8981 | 19 | */ |
AnnaBridge | 156:ff21514d8981 | 20 | |
AnnaBridge | 156:ff21514d8981 | 21 | #ifndef __MBED_MEM_TRACE_H__ |
AnnaBridge | 156:ff21514d8981 | 22 | #define __MBED_MEM_TRACE_H__ |
AnnaBridge | 156:ff21514d8981 | 23 | |
AnnaBridge | 156:ff21514d8981 | 24 | #ifdef __cplusplus |
AnnaBridge | 156:ff21514d8981 | 25 | extern "C" { |
AnnaBridge | 156:ff21514d8981 | 26 | #endif |
AnnaBridge | 156:ff21514d8981 | 27 | |
AnnaBridge | 156:ff21514d8981 | 28 | #include <stdint.h> |
AnnaBridge | 156:ff21514d8981 | 29 | #include <stddef.h> |
AnnaBridge | 156:ff21514d8981 | 30 | |
AnnaBridge | 156:ff21514d8981 | 31 | /* Operation types for tracer */ |
AnnaBridge | 156:ff21514d8981 | 32 | enum { |
AnnaBridge | 156:ff21514d8981 | 33 | MBED_MEM_TRACE_MALLOC, |
AnnaBridge | 156:ff21514d8981 | 34 | MBED_MEM_TRACE_REALLOC, |
AnnaBridge | 156:ff21514d8981 | 35 | MBED_MEM_TRACE_CALLOC, |
AnnaBridge | 156:ff21514d8981 | 36 | MBED_MEM_TRACE_FREE |
AnnaBridge | 156:ff21514d8981 | 37 | }; |
AnnaBridge | 156:ff21514d8981 | 38 | |
AnnaBridge | 158:1c57384330a6 | 39 | /** |
AnnaBridge | 158:1c57384330a6 | 40 | * \defgroup platform_mem_trace mem_trace functions |
AnnaBridge | 158:1c57384330a6 | 41 | * @{ |
AnnaBridge | 158:1c57384330a6 | 42 | */ |
AnnaBridge | 158:1c57384330a6 | 43 | |
AnnaBridge | 156:ff21514d8981 | 44 | /* Prefix for the output of the default tracer */ |
AnnaBridge | 156:ff21514d8981 | 45 | #define MBED_MEM_DEFAULT_TRACER_PREFIX "#" |
AnnaBridge | 156:ff21514d8981 | 46 | |
AnnaBridge | 156:ff21514d8981 | 47 | /** |
AnnaBridge | 156:ff21514d8981 | 48 | * Type of the callback used by the memory tracer. This callback is called when a memory |
AnnaBridge | 156:ff21514d8981 | 49 | * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled |
AnnaBridge | 156:ff21514d8981 | 50 | * for that memory allocation function. |
AnnaBridge | 156:ff21514d8981 | 51 | * |
AnnaBridge | 156:ff21514d8981 | 52 | * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC, |
AnnaBridge | 156:ff21514d8981 | 53 | * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE). |
AnnaBridge | 156:ff21514d8981 | 54 | * @param res the result that the memory operation returned (NULL for 'free'). |
AnnaBridge | 156:ff21514d8981 | 55 | * @param caller the caller of the memory operation. Note that the value of 'caller' might be |
AnnaBridge | 156:ff21514d8981 | 56 | * unreliable. |
AnnaBridge | 156:ff21514d8981 | 57 | * |
AnnaBridge | 156:ff21514d8981 | 58 | * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations |
AnnaBridge | 156:ff21514d8981 | 59 | * that triggered its call (see 'man malloc' for details): |
AnnaBridge | 156:ff21514d8981 | 60 | * |
AnnaBridge | 156:ff21514d8981 | 61 | * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size). |
AnnaBridge | 156:ff21514d8981 | 62 | * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size). |
AnnaBridge | 156:ff21514d8981 | 63 | * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size). |
AnnaBridge | 156:ff21514d8981 | 64 | * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr). |
AnnaBridge | 156:ff21514d8981 | 65 | */ |
AnnaBridge | 156:ff21514d8981 | 66 | typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...); |
AnnaBridge | 156:ff21514d8981 | 67 | |
AnnaBridge | 156:ff21514d8981 | 68 | /** |
AnnaBridge | 156:ff21514d8981 | 69 | * Set the callback used by the memory tracer (use NULL for disable tracing). |
AnnaBridge | 156:ff21514d8981 | 70 | * |
AnnaBridge | 156:ff21514d8981 | 71 | * @param cb the callback to call on each memory operation. |
AnnaBridge | 156:ff21514d8981 | 72 | */ |
AnnaBridge | 156:ff21514d8981 | 73 | void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb); |
AnnaBridge | 156:ff21514d8981 | 74 | |
AnnaBridge | 156:ff21514d8981 | 75 | /** |
Anna Bridge |
160:5571c4ff569f | 76 | * Trace lock. |
Anna Bridge |
160:5571c4ff569f | 77 | * @note Locking prevent recursive tracing of malloc/free inside relloc/calloc |
Anna Bridge |
160:5571c4ff569f | 78 | */ |
Anna Bridge |
160:5571c4ff569f | 79 | void mbed_mem_trace_lock(); |
Anna Bridge |
160:5571c4ff569f | 80 | |
Anna Bridge |
160:5571c4ff569f | 81 | /** |
Anna Bridge |
160:5571c4ff569f | 82 | * Trace unlock. |
Anna Bridge |
160:5571c4ff569f | 83 | */ |
Anna Bridge |
160:5571c4ff569f | 84 | void mbed_mem_trace_unlock(); |
Anna Bridge |
160:5571c4ff569f | 85 | |
Anna Bridge |
160:5571c4ff569f | 86 | /** |
AnnaBridge | 156:ff21514d8981 | 87 | * Trace a call to 'malloc'. |
AnnaBridge | 156:ff21514d8981 | 88 | * @param res the result of running 'malloc'. |
AnnaBridge | 156:ff21514d8981 | 89 | * @param size the 'size' argument given to 'malloc'. |
AnnaBridge | 156:ff21514d8981 | 90 | * @param caller the caller of the memory operation. |
AnnaBridge | 156:ff21514d8981 | 91 | * @return 'res' (the first argument). |
AnnaBridge | 156:ff21514d8981 | 92 | */ |
AnnaBridge | 156:ff21514d8981 | 93 | void *mbed_mem_trace_malloc(void *res, size_t size, void *caller); |
AnnaBridge | 156:ff21514d8981 | 94 | |
AnnaBridge | 156:ff21514d8981 | 95 | /** |
AnnaBridge | 156:ff21514d8981 | 96 | * Trace a call to 'realloc'. |
AnnaBridge | 156:ff21514d8981 | 97 | * @param res the result of running 'realloc'. |
AnnaBridge | 156:ff21514d8981 | 98 | * @param ptr the 'ptr' argument given to 'realloc'. |
AnnaBridge | 156:ff21514d8981 | 99 | * @param size the 'size' argument given to 'realloc'. |
AnnaBridge | 156:ff21514d8981 | 100 | * @param caller the caller of the memory operation. |
AnnaBridge | 156:ff21514d8981 | 101 | * @return 'res' (the first argument). |
AnnaBridge | 156:ff21514d8981 | 102 | */ |
AnnaBridge | 156:ff21514d8981 | 103 | void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller); |
AnnaBridge | 156:ff21514d8981 | 104 | |
AnnaBridge | 156:ff21514d8981 | 105 | /** |
AnnaBridge | 156:ff21514d8981 | 106 | * Trace a call to 'calloc'. |
AnnaBridge | 156:ff21514d8981 | 107 | * @param res the result of running 'calloc'. |
AnnaBridge | 156:ff21514d8981 | 108 | * @param num the 'nmemb' argument given to 'calloc'. |
AnnaBridge | 156:ff21514d8981 | 109 | * @param size the 'size' argument given to 'calloc'. |
AnnaBridge | 156:ff21514d8981 | 110 | * @param caller the caller of the memory operation. |
AnnaBridge | 156:ff21514d8981 | 111 | * @return 'res' (the first argument). |
AnnaBridge | 156:ff21514d8981 | 112 | */ |
AnnaBridge | 156:ff21514d8981 | 113 | void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller); |
AnnaBridge | 156:ff21514d8981 | 114 | |
AnnaBridge | 156:ff21514d8981 | 115 | /** |
AnnaBridge | 156:ff21514d8981 | 116 | * Trace a call to 'free'. |
AnnaBridge | 156:ff21514d8981 | 117 | * @param ptr the 'ptr' argument given to 'free'. |
AnnaBridge | 156:ff21514d8981 | 118 | * @param caller the caller of the memory operation. |
AnnaBridge | 156:ff21514d8981 | 119 | */ |
AnnaBridge | 156:ff21514d8981 | 120 | void mbed_mem_trace_free(void *ptr, void *caller); |
AnnaBridge | 156:ff21514d8981 | 121 | |
AnnaBridge | 156:ff21514d8981 | 122 | /** |
AnnaBridge | 156:ff21514d8981 | 123 | * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used |
AnnaBridge | 156:ff21514d8981 | 124 | * as the second argument of 'mbed_mem_trace_setup'. |
AnnaBridge | 156:ff21514d8981 | 125 | * |
AnnaBridge | 156:ff21514d8981 | 126 | * The default callback outputs trace data using 'printf', in a format that's |
AnnaBridge | 156:ff21514d8981 | 127 | * easily parsable by an external tool. For each memory operation, the callback |
AnnaBridge | 156:ff21514d8981 | 128 | * outputs a line that begins with "#<op>:<0xresult>;<0xcaller>-": |
AnnaBridge | 156:ff21514d8981 | 129 | * |
AnnaBridge | 156:ff21514d8981 | 130 | * @param op identifies the memory operation ('m' for 'malloc', 'r' for 'realloc', |
AnnaBridge | 156:ff21514d8981 | 131 | * 'c' for 'calloc' and 'f' for 'free'). |
AnnaBridge | 156:ff21514d8981 | 132 | * @param res (base 16) is the result of the memor operation. This is always NULL |
AnnaBridge | 156:ff21514d8981 | 133 | * for 'free', since 'free' doesn't return anything. |
AnnaBridge | 156:ff21514d8981 | 134 | * @param caller (base 16) is the caller of the memory operation. Note that the value |
AnnaBridge | 156:ff21514d8981 | 135 | * of 'caller' might be unreliable. |
AnnaBridge | 156:ff21514d8981 | 136 | * |
AnnaBridge | 156:ff21514d8981 | 137 | * The rest of the output depends on the operation being traced: |
AnnaBridge | 156:ff21514d8981 | 138 | * |
AnnaBridge | 156:ff21514d8981 | 139 | * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'. |
AnnaBridge | 156:ff21514d8981 | 140 | * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'. |
AnnaBridge | 156:ff21514d8981 | 141 | * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'. |
AnnaBridge | 156:ff21514d8981 | 142 | * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'. |
AnnaBridge | 156:ff21514d8981 | 143 | * |
AnnaBridge | 156:ff21514d8981 | 144 | * Examples: |
AnnaBridge | 156:ff21514d8981 | 145 | * |
AnnaBridge | 156:ff21514d8981 | 146 | * - "#m:0x20003240;0x600d-50" encodes a 'malloc' that returned 0x20003240, was called |
AnnaBridge | 156:ff21514d8981 | 147 | * by the instruction at 0x600D with a the 'size' argument equal to 50. |
AnnaBridge | 156:ff21514d8981 | 148 | * - "#f:0x0;0x602f-0x20003240" encodes a 'free' that was called by the instruction at |
AnnaBridge | 156:ff21514d8981 | 149 | * 0x602f with the 'ptr' argument equal to 0x20003240. |
AnnaBridge | 156:ff21514d8981 | 150 | */ |
AnnaBridge | 156:ff21514d8981 | 151 | void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...); |
AnnaBridge | 156:ff21514d8981 | 152 | |
AnnaBridge | 158:1c57384330a6 | 153 | /** @}*/ |
AnnaBridge | 158:1c57384330a6 | 154 | |
AnnaBridge | 156:ff21514d8981 | 155 | #ifdef __cplusplus |
AnnaBridge | 156:ff21514d8981 | 156 | } |
AnnaBridge | 156:ff21514d8981 | 157 | #endif |
AnnaBridge | 156:ff21514d8981 | 158 | |
AnnaBridge | 156:ff21514d8981 | 159 | #endif// #ifndef __MBED_MEM_TRACE_H__ |
AnnaBridge | 156:ff21514d8981 | 160 | |
AnnaBridge | 156:ff21514d8981 | 161 | |
AnnaBridge | 156:ff21514d8981 | 162 | /** @}*/ |