Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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