mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

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