mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Fri Feb 16 16:09:33 2018 +0000
Revision:
181:57724642e740
Parent:
180:96ed750bd169
Child:
187:0387e8f68319
mbed-dev library. Release version 159.

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
<> 149:156823d33999 31 /* Operation types for tracer */
<> 149:156823d33999 32 enum {
<> 149:156823d33999 33 MBED_MEM_TRACE_MALLOC,
<> 149:156823d33999 34 MBED_MEM_TRACE_REALLOC,
<> 149:156823d33999 35 MBED_MEM_TRACE_CALLOC,
<> 149:156823d33999 36 MBED_MEM_TRACE_FREE
<> 149:156823d33999 37 };
<> 149:156823d33999 38
AnnaBridge 178:79309dc6340a 39 /**
AnnaBridge 178:79309dc6340a 40 * \defgroup platform_mem_trace mem_trace functions
AnnaBridge 178:79309dc6340a 41 * @{
AnnaBridge 178:79309dc6340a 42 */
AnnaBridge 178:79309dc6340a 43
<> 149:156823d33999 44 /* Prefix for the output of the default tracer */
<> 149:156823d33999 45 #define MBED_MEM_DEFAULT_TRACER_PREFIX "#"
<> 149:156823d33999 46
<> 149:156823d33999 47 /**
<> 149:156823d33999 48 * Type of the callback used by the memory tracer. This callback is called when a memory
<> 149:156823d33999 49 * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled
<> 149:156823d33999 50 * for that memory allocation function.
<> 149:156823d33999 51 *
<> 149:156823d33999 52 * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC,
<> 149:156823d33999 53 * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE).
<> 149:156823d33999 54 * @param res the result that the memory operation returned (NULL for 'free').
<> 149:156823d33999 55 * @param caller the caller of the memory operation. Note that the value of 'caller' might be
<> 149:156823d33999 56 * unreliable.
<> 149:156823d33999 57 *
<> 149:156823d33999 58 * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations
<> 149:156823d33999 59 * that triggered its call (see 'man malloc' for details):
<> 149:156823d33999 60 *
<> 149:156823d33999 61 * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size).
<> 149:156823d33999 62 * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size).
<> 149:156823d33999 63 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
<> 149:156823d33999 64 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr).
<> 149:156823d33999 65 */
<> 149:156823d33999 66 typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...);
<> 149:156823d33999 67
<> 149:156823d33999 68 /**
<> 149:156823d33999 69 * Set the callback used by the memory tracer (use NULL for disable tracing).
<> 149:156823d33999 70 *
<> 149:156823d33999 71 * @param cb the callback to call on each memory operation.
<> 149:156823d33999 72 */
<> 149:156823d33999 73 void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb);
<> 149:156823d33999 74
<> 149:156823d33999 75 /**
Anna Bridge 180:96ed750bd169 76 * Trace lock.
Anna Bridge 180:96ed750bd169 77 * @note Locking prevent recursive tracing of malloc/free inside relloc/calloc
Anna Bridge 180:96ed750bd169 78 */
Anna Bridge 180:96ed750bd169 79 void mbed_mem_trace_lock();
Anna Bridge 180:96ed750bd169 80
Anna Bridge 180:96ed750bd169 81 /**
Anna Bridge 180:96ed750bd169 82 * Trace unlock.
Anna Bridge 180:96ed750bd169 83 */
Anna Bridge 180:96ed750bd169 84 void mbed_mem_trace_unlock();
Anna Bridge 180:96ed750bd169 85
Anna Bridge 180:96ed750bd169 86 /**
<> 149:156823d33999 87 * Trace a call to 'malloc'.
<> 149:156823d33999 88 * @param res the result of running 'malloc'.
<> 149:156823d33999 89 * @param size the 'size' argument given to 'malloc'.
<> 149:156823d33999 90 * @param caller the caller of the memory operation.
<> 149:156823d33999 91 * @return 'res' (the first argument).
<> 149:156823d33999 92 */
<> 149:156823d33999 93 void *mbed_mem_trace_malloc(void *res, size_t size, void *caller);
<> 149:156823d33999 94
<> 149:156823d33999 95 /**
<> 149:156823d33999 96 * Trace a call to 'realloc'.
<> 149:156823d33999 97 * @param res the result of running 'realloc'.
<> 149:156823d33999 98 * @param ptr the 'ptr' argument given to 'realloc'.
<> 149:156823d33999 99 * @param size the 'size' argument given to 'realloc'.
AnnaBridge 167:e84263d55307 100 * @param caller the caller of the memory operation.
<> 149:156823d33999 101 * @return 'res' (the first argument).
<> 149:156823d33999 102 */
<> 149:156823d33999 103 void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller);
<> 149:156823d33999 104
<> 149:156823d33999 105 /**
<> 149:156823d33999 106 * Trace a call to 'calloc'.
<> 149:156823d33999 107 * @param res the result of running 'calloc'.
AnnaBridge 167:e84263d55307 108 * @param num the 'nmemb' argument given to 'calloc'.
<> 149:156823d33999 109 * @param size the 'size' argument given to 'calloc'.
<> 149:156823d33999 110 * @param caller the caller of the memory operation.
AnnaBridge 167:e84263d55307 111 * @return 'res' (the first argument).
<> 149:156823d33999 112 */
<> 149:156823d33999 113 void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller);
<> 149:156823d33999 114
<> 149:156823d33999 115 /**
<> 149:156823d33999 116 * Trace a call to 'free'.
<> 149:156823d33999 117 * @param ptr the 'ptr' argument given to 'free'.
<> 149:156823d33999 118 * @param caller the caller of the memory operation.
<> 149:156823d33999 119 */
<> 149:156823d33999 120 void mbed_mem_trace_free(void *ptr, void *caller);
<> 149:156823d33999 121
<> 149:156823d33999 122 /**
<> 149:156823d33999 123 * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used
<> 149:156823d33999 124 * as the second argument of 'mbed_mem_trace_setup'.
<> 149:156823d33999 125 *
<> 149:156823d33999 126 * The default callback outputs trace data using 'printf', in a format that's
<> 149:156823d33999 127 * easily parsable by an external tool. For each memory operation, the callback
AnnaBridge 167:e84263d55307 128 * outputs a line that begins with "#<op>:<0xresult>;<0xcaller>-":
<> 149:156823d33999 129 *
AnnaBridge 167:e84263d55307 130 * @param op identifies the memory operation ('m' for 'malloc', 'r' for 'realloc',
AnnaBridge 167:e84263d55307 131 * 'c' for 'calloc' and 'f' for 'free').
AnnaBridge 167:e84263d55307 132 * @param res (base 16) is the result of the memor operation. This is always NULL
AnnaBridge 167:e84263d55307 133 * for 'free', since 'free' doesn't return anything.
AnnaBridge 167:e84263d55307 134 * @param caller (base 16) is the caller of the memory operation. Note that the value
AnnaBridge 167:e84263d55307 135 * of 'caller' might be unreliable.
<> 149:156823d33999 136 *
<> 149:156823d33999 137 * The rest of the output depends on the operation being traced:
<> 149:156823d33999 138 *
<> 149:156823d33999 139 * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'.
<> 149:156823d33999 140 * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'.
<> 149:156823d33999 141 * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'.
<> 149:156823d33999 142 * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'.
<> 149:156823d33999 143 *
<> 149:156823d33999 144 * Examples:
<> 149:156823d33999 145 *
AnnaBridge 167:e84263d55307 146 * - "#m:0x20003240;0x600d-50" encodes a 'malloc' that returned 0x20003240, was called
<> 149:156823d33999 147 * by the instruction at 0x600D with a the 'size' argument equal to 50.
AnnaBridge 167:e84263d55307 148 * - "#f:0x0;0x602f-0x20003240" encodes a 'free' that was called by the instruction at
<> 149:156823d33999 149 * 0x602f with the 'ptr' argument equal to 0x20003240.
<> 149:156823d33999 150 */
<> 149:156823d33999 151 void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...);
<> 149:156823d33999 152
AnnaBridge 178:79309dc6340a 153 /** @}*/
AnnaBridge 178:79309dc6340a 154
<> 149:156823d33999 155 #ifdef __cplusplus
<> 149:156823d33999 156 }
<> 149:156823d33999 157 #endif
<> 149:156823d33999 158
<> 149:156823d33999 159 #endif// #ifndef __MBED_MEM_TRACE_H__
<> 149:156823d33999 160
<> 149:156823d33999 161
<> 149:156823d33999 162 /** @}*/