test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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