Replace mbed_mem_tracing_enabled macro with config option

pull/7402/head
kegilbert 2018-07-02 10:43:01 -05:00
parent 1e676f6eda
commit 9b53d1256f
4 changed files with 35 additions and 30 deletions

View File

@ -24,8 +24,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#ifndef MBED_MEM_TRACING_ENABLED #if !MBED_MEM_TRACING_ENABLED
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using utest::v1::Case; using utest::v1::Case;

View File

@ -30,7 +30,7 @@
activated by defining the MBED_HEAP_STATS_ENABLED macro. activated by defining the MBED_HEAP_STATS_ENABLED macro.
- the second can be used to trace each memory call by automatically invoking - the second can be used to trace each memory call by automatically invoking
a callback on each memory operation (see hal/api/mbed_mem_trace.h). It is a callback on each memory operation (see hal/api/mbed_mem_trace.h). It is
activated by defining the MBED_MEM_TRACING_ENABLED macro. activated by setting the configuration option MBED_MEM_TRACING_ENABLED to true.
Both tracers can be activated and deactivated in any combination. If both tracers Both tracers can be activated and deactivated in any combination. If both tracers
are active, the second one (MBED_MEM_TRACING_ENABLED) will trace the first one's are active, the second one (MBED_MEM_TRACING_ENABLED) will trace the first one's
@ -96,7 +96,7 @@ extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)
extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller) extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
{ {
void *ptr = NULL; void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -118,17 +118,17 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = __real__malloc_r(r, size); ptr = __real__malloc_r(r, size);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_malloc(ptr, size, caller); mbed_mem_trace_malloc(ptr, size, caller);
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
return ptr; return ptr;
} }
extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size) extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
{ {
void *new_ptr = NULL; void *new_ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -161,10 +161,10 @@ extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
new_ptr = __real__realloc_r(r, ptr, size); new_ptr = __real__realloc_r(r, ptr, size);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR()); mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
return new_ptr; return new_ptr;
} }
@ -175,7 +175,7 @@ extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller) extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
{ {
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -191,16 +191,16 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
__real__free_r(r, ptr); __real__free_r(r, ptr);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_free(ptr, caller); mbed_mem_trace_free(ptr, caller);
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
} }
extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size) extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
{ {
void *ptr = NULL; void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -213,10 +213,10 @@ extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = __real__calloc_r(r, nmemb, size); ptr = __real__calloc_r(r, nmemb, size);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR()); mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
return ptr; return ptr;
} }
@ -275,7 +275,7 @@ extern "C" void *SUB_MALLOC(size_t size)
extern "C" void *malloc_wrapper(size_t size, void *caller) extern "C" void *malloc_wrapper(size_t size, void *caller)
{ {
void *ptr = NULL; void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -297,10 +297,10 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = SUPER_MALLOC(size); ptr = SUPER_MALLOC(size);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_malloc(ptr, size, caller); mbed_mem_trace_malloc(ptr, size, caller);
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
return ptr; return ptr;
} }
@ -308,7 +308,7 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
extern "C" void *SUB_REALLOC(void *ptr, size_t size) extern "C" void *SUB_REALLOC(void *ptr, size_t size)
{ {
void *new_ptr = NULL; void *new_ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -336,17 +336,17 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
new_ptr = SUPER_REALLOC(ptr, size); new_ptr = SUPER_REALLOC(ptr, size);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR()); mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
return new_ptr; return new_ptr;
} }
extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
{ {
void *ptr = NULL; void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -358,10 +358,10 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = SUPER_CALLOC(nmemb, size); ptr = SUPER_CALLOC(nmemb, size);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR()); mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
return ptr; return ptr;
} }
@ -372,7 +372,7 @@ extern "C" void SUB_FREE(void *ptr)
extern "C" void free_wrapper(void *ptr, void *caller) extern "C" void free_wrapper(void *ptr, void *caller)
{ {
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock(); mbed_mem_trace_lock();
#endif #endif
#ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_HEAP_STATS_ENABLED
@ -388,10 +388,10 @@ extern "C" void free_wrapper(void *ptr, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
SUPER_FREE(ptr); SUPER_FREE(ptr);
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_free(ptr, caller); mbed_mem_trace_free(ptr, caller);
mbed_mem_trace_unlock(); mbed_mem_trace_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #if MBED_MEM_TRACING_ENABLED
} }
#endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED) #endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
@ -402,7 +402,7 @@ extern "C" void free_wrapper(void *ptr, void *caller)
#else #else
#ifdef MBED_MEM_TRACING_ENABLED #if MBED_MEM_TRACING_ENABLED
#error Memory tracing is not supported with the current toolchain. #error Memory tracing is not supported with the current toolchain.
#endif #endif

View File

@ -64,6 +64,11 @@
"max-error-filename-len": { "max-error-filename-len": {
"help": "Sets the maximum length of buffer used for capturing the filename in error context. This needs error-filename-capture-enabled feature.", "help": "Sets the maximum length of buffer used for capturing the filename in error context. This needs error-filename-capture-enabled feature.",
"value": 16 "value": 16
},
"memory-tracing-enabled": {
"macro_name": "MBED_MEM_TRACING_ENABLED",
"help": "Enable tracing of each memory call by invoking a callback on each memory operation. See mbed_mem_trace.h in the HAL API for more information",
"value": false
} }
}, },
"target_overrides": { "target_overrides": {

View File

@ -1469,7 +1469,7 @@ extern "C" void __cxa_guard_abort(int *guard_object_p)
#endif #endif
#if defined(MBED_MEM_TRACING_ENABLED) && (defined(__CC_ARM) || defined(__ICCARM__) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))) #if MBED_MEM_TRACING_ENABLED && (defined(__CC_ARM) || defined(__ICCARM__) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)))
// If the memory tracing is enabled, the wrappers in mbed_alloc_wrappers.cpp // If the memory tracing is enabled, the wrappers in mbed_alloc_wrappers.cpp
// provide the implementation for these. Note: this needs to use the wrappers // provide the implementation for these. Note: this needs to use the wrappers
@ -1515,7 +1515,7 @@ void operator delete[](void *ptr)
free_wrapper(ptr, MBED_CALLER_ADDR()); free_wrapper(ptr, MBED_CALLER_ADDR());
} }
#elif defined(MBED_MEM_TRACING_ENABLED) && defined(__GNUC__) #elif MBED_MEM_TRACING_ENABLED && defined(__GNUC__)
#include <reent.h> #include <reent.h>