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