mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Thu Nov 08 11:46:34 2018 +0000
Revision:
188:bcfe06ba3d64
Parent:
187:0387e8f68319
Child:
189:f392fc9709a3
mbed-dev library. Release version 164

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