Merge pull request #7402 from kegilbert/mem-tracing-config-patch

Replace mbed_mem_tracing_enabled macro with config option
pull/7903/head
Cruz Monrreal 2018-08-27 10:34:24 -05:00 committed by GitHub
commit 1b051c7687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 30 deletions

View File

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

View File

@ -30,7 +30,7 @@
activated by defining the MBED_HEAP_STATS_ENABLED macro.
- 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
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
are active, the second one (MBED_MEM_TRACING_ENABLED) will trace the first one's
@ -91,7 +91,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)
{
void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -113,17 +113,17 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = __real__malloc_r(r, size);
#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_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
#endif // #if MBED_MEM_TRACING_ENABLED
return ptr;
}
extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
{
void *new_ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -156,10 +156,10 @@ extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED
new_ptr = __real__realloc_r(r, ptr, size);
#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_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
#endif // #if MBED_MEM_TRACING_ENABLED
return new_ptr;
}
@ -170,7 +170,7 @@ extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
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();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -186,16 +186,16 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED
__real__free_r(r, ptr);
#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_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)
{
void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -208,10 +208,10 @@ extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = __real__calloc_r(r, nmemb, size);
#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_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
#endif // #if MBED_MEM_TRACING_ENABLED
return ptr;
}
@ -269,7 +269,7 @@ extern "C" void *SUB_MALLOC(size_t size)
extern "C" void *malloc_wrapper(size_t size, void *caller)
{
void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -291,10 +291,10 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = SUPER_MALLOC(size);
#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_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
#endif // #if MBED_MEM_TRACING_ENABLED
return ptr;
}
@ -302,7 +302,7 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
extern "C" void *SUB_REALLOC(void *ptr, size_t size)
{
void *new_ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -330,17 +330,17 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED
new_ptr = SUPER_REALLOC(ptr, size);
#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_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
#endif // #if MBED_MEM_TRACING_ENABLED
return new_ptr;
}
extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
{
void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -352,10 +352,10 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
#else // #ifdef MBED_HEAP_STATS_ENABLED
ptr = SUPER_CALLOC(nmemb, size);
#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_unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
#endif // #if MBED_MEM_TRACING_ENABLED
return ptr;
}
@ -366,7 +366,7 @@ extern "C" void SUB_FREE(void *ptr)
extern "C" void free_wrapper(void *ptr, void *caller)
{
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
@ -382,10 +382,10 @@ extern "C" void free_wrapper(void *ptr, void *caller)
#else // #ifdef MBED_HEAP_STATS_ENABLED
SUPER_FREE(ptr);
#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_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)
@ -396,7 +396,7 @@ extern "C" void free_wrapper(void *ptr, void *caller)
#else
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
#error Memory tracing is not supported with the current toolchain.
#endif

View File

@ -64,6 +64,11 @@
"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.",
"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": {

View File

@ -1469,7 +1469,7 @@ extern "C" void __cxa_guard_abort(int *guard_object_p)
#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
// 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());
}
#elif defined(MBED_MEM_TRACING_ENABLED) && defined(__GNUC__)
#elif MBED_MEM_TRACING_ENABLED && defined(__GNUC__)
#include <reent.h>