Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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