Skip to content

Replace mbed_mem_tracing_enabled macro with config option #7402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TESTS/mbed_drivers/mem_trace/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 26 additions & 26 deletions platform/mbed_alloc_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
void *ptr = NULL;
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -118,17 +118,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
Expand Down Expand Up @@ -161,10 +161,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;
}

Expand All @@ -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)
{
#ifdef MBED_MEM_TRACING_ENABLED
#if MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -191,16 +191,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
Expand All @@ -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
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;
}

Expand Down Expand Up @@ -275,7 +275,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
Expand All @@ -297,18 +297,18 @@ 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;
}


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
Expand Down Expand Up @@ -336,17 +336,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
Expand All @@ -358,10 +358,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;
}

Expand All @@ -372,7 +372,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
Expand All @@ -388,10 +388,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)
Expand All @@ -402,7 +402,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

Expand Down
5 changes: 5 additions & 0 deletions platform/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions platform/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>

Expand Down