Skip to content

Update mbed_mem_tracing config option #8487

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
Oct 29, 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
2 changes: 1 addition & 1 deletion TESTS/mbed_drivers/mem_trace/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdio.h>
#include <stdarg.h>

#if !MBED_MEM_TRACING_ENABLED
#ifndef MBED_MEM_TRACING_ENABLED
#error [NOT_SUPPORTED] test not supported
#endif

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 @@ -27,7 +27,7 @@
/* There are two memory tracers in mbed OS:

- the first can be used to detect the maximum heap usage at runtime. It is
activated by defining the MBED_HEAP_STATS_ENABLED macro.
activated by setting the configuration option MBED_HEAP_STATS_ENABLED to true.
- 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 setting the configuration option MBED_MEM_TRACING_ENABLED to true.
Expand Down Expand Up @@ -99,7 +99,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;
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -123,17 +123,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_malloc(ptr, size, caller);
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return ptr;
}

extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
{
void *new_ptr = NULL;
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand Down Expand Up @@ -166,10 +166,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return new_ptr;
}

Expand All @@ -180,7 +180,7 @@ extern "C" void __wrap__free_r(struct _reent *r, void *ptr)

extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
{
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -205,16 +205,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_free(ptr, caller);
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
}

extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
{
void *ptr = NULL;
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -227,10 +227,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return ptr;
}

Expand Down Expand Up @@ -286,7 +286,7 @@ extern "C" void *SUB_MALLOC(size_t size)
extern "C" void *malloc_wrapper(size_t size, void *caller)
{
void *ptr = NULL;
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -310,18 +310,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_malloc(ptr, size, caller);
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return ptr;
}


extern "C" void *SUB_REALLOC(void *ptr, size_t size)
{
void *new_ptr = NULL;
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand Down Expand Up @@ -349,17 +349,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return new_ptr;
}

extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
{
void *ptr = NULL;
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -371,10 +371,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return ptr;
}

Expand All @@ -385,7 +385,7 @@ extern "C" void SUB_FREE(void *ptr)

extern "C" void free_wrapper(void *ptr, void *caller)
{
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_lock();
#endif
#ifdef MBED_HEAP_STATS_ENABLED
Expand All @@ -410,10 +410,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
#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mbed_mem_trace_free(ptr, caller);
mbed_mem_trace_unlock();
#endif // #if MBED_MEM_TRACING_ENABLED
#endif // #ifdef MBED_MEM_TRACING_ENABLED
}

#endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
Expand All @@ -424,7 +424,7 @@ extern "C" void free_wrapper(void *ptr, void *caller)

#else

#if MBED_MEM_TRACING_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
#error Memory tracing is not supported with the current toolchain.
#endif

Expand Down
2 changes: 1 addition & 1 deletion platform/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"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
"value": null
},
"sys-stats-enabled": {
"macro_name": "MBED_SYS_STATS_ENABLED",
Expand Down
4 changes: 2 additions & 2 deletions platform/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ extern "C" void __cxa_guard_abort(int *guard_object_p)

#endif

#if MBED_MEM_TRACING_ENABLED && (defined(__CC_ARM) || defined(__ICCARM__) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)))
#if defined(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 @@ -1485,7 +1485,7 @@ void operator delete[](void *ptr)
free_wrapper(ptr, MBED_CALLER_ADDR());
}

#elif MBED_MEM_TRACING_ENABLED && defined(__GNUC__)
#elif defined(MBED_MEM_TRACING_ENABLED) && defined(__GNUC__)

#include <reent.h>

Expand Down