Skip to content

Commit 1b051c7

Browse files
author
Cruz Monrreal
authored
Merge pull request #7402 from kegilbert/mem-tracing-config-patch
Replace mbed_mem_tracing_enabled macro with config option
2 parents 7ac4bf4 + 9b53d12 commit 1b051c7

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

TESTS/mbed_drivers/mem_trace/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <stdio.h>
2525
#include <stdarg.h>
2626

27-
#ifndef MBED_MEM_TRACING_ENABLED
28-
#error [NOT_SUPPORTED] test not supported
27+
#if !MBED_MEM_TRACING_ENABLED
28+
#error [NOT_SUPPORTED] test not supported
2929
#endif
3030

3131
using utest::v1::Case;

platform/mbed_alloc_wrappers.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
activated by defining the MBED_HEAP_STATS_ENABLED macro.
3131
- the second can be used to trace each memory call by automatically invoking
3232
a callback on each memory operation (see hal/api/mbed_mem_trace.h). It is
33-
activated by defining the MBED_MEM_TRACING_ENABLED macro.
33+
activated by setting the configuration option MBED_MEM_TRACING_ENABLED to true.
3434
3535
Both tracers can be activated and deactivated in any combination. If both tracers
3636
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)
9191
extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
9292
{
9393
void *ptr = NULL;
94-
#ifdef MBED_MEM_TRACING_ENABLED
94+
#if MBED_MEM_TRACING_ENABLED
9595
mbed_mem_trace_lock();
9696
#endif
9797
#ifdef MBED_HEAP_STATS_ENABLED
@@ -113,17 +113,17 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
113113
#else // #ifdef MBED_HEAP_STATS_ENABLED
114114
ptr = __real__malloc_r(r, size);
115115
#endif // #ifdef MBED_HEAP_STATS_ENABLED
116-
#ifdef MBED_MEM_TRACING_ENABLED
116+
#if MBED_MEM_TRACING_ENABLED
117117
mbed_mem_trace_malloc(ptr, size, caller);
118118
mbed_mem_trace_unlock();
119-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
119+
#endif // #if MBED_MEM_TRACING_ENABLED
120120
return ptr;
121121
}
122122

123123
extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
124124
{
125125
void *new_ptr = NULL;
126-
#ifdef MBED_MEM_TRACING_ENABLED
126+
#if MBED_MEM_TRACING_ENABLED
127127
mbed_mem_trace_lock();
128128
#endif
129129
#ifdef MBED_HEAP_STATS_ENABLED
@@ -156,10 +156,10 @@ extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
156156
#else // #ifdef MBED_HEAP_STATS_ENABLED
157157
new_ptr = __real__realloc_r(r, ptr, size);
158158
#endif // #ifdef MBED_HEAP_STATS_ENABLED
159-
#ifdef MBED_MEM_TRACING_ENABLED
159+
#if MBED_MEM_TRACING_ENABLED
160160
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
161161
mbed_mem_trace_unlock();
162-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
162+
#endif // #if MBED_MEM_TRACING_ENABLED
163163
return new_ptr;
164164
}
165165

@@ -170,7 +170,7 @@ extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
170170

171171
extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
172172
{
173-
#ifdef MBED_MEM_TRACING_ENABLED
173+
#if MBED_MEM_TRACING_ENABLED
174174
mbed_mem_trace_lock();
175175
#endif
176176
#ifdef MBED_HEAP_STATS_ENABLED
@@ -186,16 +186,16 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
186186
#else // #ifdef MBED_HEAP_STATS_ENABLED
187187
__real__free_r(r, ptr);
188188
#endif // #ifdef MBED_HEAP_STATS_ENABLED
189-
#ifdef MBED_MEM_TRACING_ENABLED
189+
#if MBED_MEM_TRACING_ENABLED
190190
mbed_mem_trace_free(ptr, caller);
191191
mbed_mem_trace_unlock();
192-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
192+
#endif // #if MBED_MEM_TRACING_ENABLED
193193
}
194194

195195
extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
196196
{
197197
void *ptr = NULL;
198-
#ifdef MBED_MEM_TRACING_ENABLED
198+
#if MBED_MEM_TRACING_ENABLED
199199
mbed_mem_trace_lock();
200200
#endif
201201
#ifdef MBED_HEAP_STATS_ENABLED
@@ -208,10 +208,10 @@ extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
208208
#else // #ifdef MBED_HEAP_STATS_ENABLED
209209
ptr = __real__calloc_r(r, nmemb, size);
210210
#endif // #ifdef MBED_HEAP_STATS_ENABLED
211-
#ifdef MBED_MEM_TRACING_ENABLED
211+
#if MBED_MEM_TRACING_ENABLED
212212
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
213213
mbed_mem_trace_unlock();
214-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
214+
#endif // #if MBED_MEM_TRACING_ENABLED
215215
return ptr;
216216
}
217217

@@ -269,7 +269,7 @@ extern "C" void *SUB_MALLOC(size_t size)
269269
extern "C" void *malloc_wrapper(size_t size, void *caller)
270270
{
271271
void *ptr = NULL;
272-
#ifdef MBED_MEM_TRACING_ENABLED
272+
#if MBED_MEM_TRACING_ENABLED
273273
mbed_mem_trace_lock();
274274
#endif
275275
#ifdef MBED_HEAP_STATS_ENABLED
@@ -291,18 +291,18 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
291291
#else // #ifdef MBED_HEAP_STATS_ENABLED
292292
ptr = SUPER_MALLOC(size);
293293
#endif // #ifdef MBED_HEAP_STATS_ENABLED
294-
#ifdef MBED_MEM_TRACING_ENABLED
294+
#if MBED_MEM_TRACING_ENABLED
295295
mbed_mem_trace_malloc(ptr, size, caller);
296296
mbed_mem_trace_unlock();
297-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
297+
#endif // #if MBED_MEM_TRACING_ENABLED
298298
return ptr;
299299
}
300300

301301

302302
extern "C" void *SUB_REALLOC(void *ptr, size_t size)
303303
{
304304
void *new_ptr = NULL;
305-
#ifdef MBED_MEM_TRACING_ENABLED
305+
#if MBED_MEM_TRACING_ENABLED
306306
mbed_mem_trace_lock();
307307
#endif
308308
#ifdef MBED_HEAP_STATS_ENABLED
@@ -330,17 +330,17 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
330330
#else // #ifdef MBED_HEAP_STATS_ENABLED
331331
new_ptr = SUPER_REALLOC(ptr, size);
332332
#endif // #ifdef MBED_HEAP_STATS_ENABLED
333-
#ifdef MBED_MEM_TRACING_ENABLED
333+
#if MBED_MEM_TRACING_ENABLED
334334
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
335335
mbed_mem_trace_unlock();
336-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
336+
#endif // #if MBED_MEM_TRACING_ENABLED
337337
return new_ptr;
338338
}
339339

340340
extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
341341
{
342342
void *ptr = NULL;
343-
#ifdef MBED_MEM_TRACING_ENABLED
343+
#if MBED_MEM_TRACING_ENABLED
344344
mbed_mem_trace_lock();
345345
#endif
346346
#ifdef MBED_HEAP_STATS_ENABLED
@@ -352,10 +352,10 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
352352
#else // #ifdef MBED_HEAP_STATS_ENABLED
353353
ptr = SUPER_CALLOC(nmemb, size);
354354
#endif // #ifdef MBED_HEAP_STATS_ENABLED
355-
#ifdef MBED_MEM_TRACING_ENABLED
355+
#if MBED_MEM_TRACING_ENABLED
356356
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
357357
mbed_mem_trace_unlock();
358-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
358+
#endif // #if MBED_MEM_TRACING_ENABLED
359359
return ptr;
360360
}
361361

@@ -366,7 +366,7 @@ extern "C" void SUB_FREE(void *ptr)
366366

367367
extern "C" void free_wrapper(void *ptr, void *caller)
368368
{
369-
#ifdef MBED_MEM_TRACING_ENABLED
369+
#if MBED_MEM_TRACING_ENABLED
370370
mbed_mem_trace_lock();
371371
#endif
372372
#ifdef MBED_HEAP_STATS_ENABLED
@@ -382,10 +382,10 @@ extern "C" void free_wrapper(void *ptr, void *caller)
382382
#else // #ifdef MBED_HEAP_STATS_ENABLED
383383
SUPER_FREE(ptr);
384384
#endif // #ifdef MBED_HEAP_STATS_ENABLED
385-
#ifdef MBED_MEM_TRACING_ENABLED
385+
#if MBED_MEM_TRACING_ENABLED
386386
mbed_mem_trace_free(ptr, caller);
387387
mbed_mem_trace_unlock();
388-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
388+
#endif // #if MBED_MEM_TRACING_ENABLED
389389
}
390390

391391
#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)
396396

397397
#else
398398

399-
#ifdef MBED_MEM_TRACING_ENABLED
399+
#if MBED_MEM_TRACING_ENABLED
400400
#error Memory tracing is not supported with the current toolchain.
401401
#endif
402402

platform/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
"max-error-filename-len": {
6565
"help": "Sets the maximum length of buffer used for capturing the filename in error context. This needs error-filename-capture-enabled feature.",
6666
"value": 16
67+
},
68+
"memory-tracing-enabled": {
69+
"macro_name": "MBED_MEM_TRACING_ENABLED",
70+
"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",
71+
"value": false
6772
}
6873
},
6974
"target_overrides": {

platform/mbed_retarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ extern "C" void __cxa_guard_abort(int *guard_object_p)
14691469

14701470
#endif
14711471

1472-
#if defined(MBED_MEM_TRACING_ENABLED) && (defined(__CC_ARM) || defined(__ICCARM__) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)))
1472+
#if MBED_MEM_TRACING_ENABLED && (defined(__CC_ARM) || defined(__ICCARM__) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)))
14731473

14741474
// If the memory tracing is enabled, the wrappers in mbed_alloc_wrappers.cpp
14751475
// provide the implementation for these. Note: this needs to use the wrappers
@@ -1515,7 +1515,7 @@ void operator delete[](void *ptr)
15151515
free_wrapper(ptr, MBED_CALLER_ADDR());
15161516
}
15171517

1518-
#elif defined(MBED_MEM_TRACING_ENABLED) && defined(__GNUC__)
1518+
#elif MBED_MEM_TRACING_ENABLED && defined(__GNUC__)
15191519

15201520
#include <reent.h>
15211521

0 commit comments

Comments
 (0)