Skip to content

Commit 9b53d12

Browse files
committed
Replace mbed_mem_tracing_enabled macro with config option
1 parent 1e676f6 commit 9b53d12

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
@@ -96,7 +96,7 @@ extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)
9696
extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
9797
{
9898
void *ptr = NULL;
99-
#ifdef MBED_MEM_TRACING_ENABLED
99+
#if MBED_MEM_TRACING_ENABLED
100100
mbed_mem_trace_lock();
101101
#endif
102102
#ifdef MBED_HEAP_STATS_ENABLED
@@ -118,17 +118,17 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
118118
#else // #ifdef MBED_HEAP_STATS_ENABLED
119119
ptr = __real__malloc_r(r, size);
120120
#endif // #ifdef MBED_HEAP_STATS_ENABLED
121-
#ifdef MBED_MEM_TRACING_ENABLED
121+
#if MBED_MEM_TRACING_ENABLED
122122
mbed_mem_trace_malloc(ptr, size, caller);
123123
mbed_mem_trace_unlock();
124-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
124+
#endif // #if MBED_MEM_TRACING_ENABLED
125125
return ptr;
126126
}
127127

128128
extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
129129
{
130130
void *new_ptr = NULL;
131-
#ifdef MBED_MEM_TRACING_ENABLED
131+
#if MBED_MEM_TRACING_ENABLED
132132
mbed_mem_trace_lock();
133133
#endif
134134
#ifdef MBED_HEAP_STATS_ENABLED
@@ -161,10 +161,10 @@ extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
161161
#else // #ifdef MBED_HEAP_STATS_ENABLED
162162
new_ptr = __real__realloc_r(r, ptr, size);
163163
#endif // #ifdef MBED_HEAP_STATS_ENABLED
164-
#ifdef MBED_MEM_TRACING_ENABLED
164+
#if MBED_MEM_TRACING_ENABLED
165165
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
166166
mbed_mem_trace_unlock();
167-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
167+
#endif // #if MBED_MEM_TRACING_ENABLED
168168
return new_ptr;
169169
}
170170

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

176176
extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
177177
{
178-
#ifdef MBED_MEM_TRACING_ENABLED
178+
#if MBED_MEM_TRACING_ENABLED
179179
mbed_mem_trace_lock();
180180
#endif
181181
#ifdef MBED_HEAP_STATS_ENABLED
@@ -191,16 +191,16 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
191191
#else // #ifdef MBED_HEAP_STATS_ENABLED
192192
__real__free_r(r, ptr);
193193
#endif // #ifdef MBED_HEAP_STATS_ENABLED
194-
#ifdef MBED_MEM_TRACING_ENABLED
194+
#if MBED_MEM_TRACING_ENABLED
195195
mbed_mem_trace_free(ptr, caller);
196196
mbed_mem_trace_unlock();
197-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
197+
#endif // #if MBED_MEM_TRACING_ENABLED
198198
}
199199

200200
extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
201201
{
202202
void *ptr = NULL;
203-
#ifdef MBED_MEM_TRACING_ENABLED
203+
#if MBED_MEM_TRACING_ENABLED
204204
mbed_mem_trace_lock();
205205
#endif
206206
#ifdef MBED_HEAP_STATS_ENABLED
@@ -213,10 +213,10 @@ extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
213213
#else // #ifdef MBED_HEAP_STATS_ENABLED
214214
ptr = __real__calloc_r(r, nmemb, size);
215215
#endif // #ifdef MBED_HEAP_STATS_ENABLED
216-
#ifdef MBED_MEM_TRACING_ENABLED
216+
#if MBED_MEM_TRACING_ENABLED
217217
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
218218
mbed_mem_trace_unlock();
219-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
219+
#endif // #if MBED_MEM_TRACING_ENABLED
220220
return ptr;
221221
}
222222

@@ -275,7 +275,7 @@ extern "C" void *SUB_MALLOC(size_t size)
275275
extern "C" void *malloc_wrapper(size_t size, void *caller)
276276
{
277277
void *ptr = NULL;
278-
#ifdef MBED_MEM_TRACING_ENABLED
278+
#if MBED_MEM_TRACING_ENABLED
279279
mbed_mem_trace_lock();
280280
#endif
281281
#ifdef MBED_HEAP_STATS_ENABLED
@@ -297,18 +297,18 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
297297
#else // #ifdef MBED_HEAP_STATS_ENABLED
298298
ptr = SUPER_MALLOC(size);
299299
#endif // #ifdef MBED_HEAP_STATS_ENABLED
300-
#ifdef MBED_MEM_TRACING_ENABLED
300+
#if MBED_MEM_TRACING_ENABLED
301301
mbed_mem_trace_malloc(ptr, size, caller);
302302
mbed_mem_trace_unlock();
303-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
303+
#endif // #if MBED_MEM_TRACING_ENABLED
304304
return ptr;
305305
}
306306

307307

308308
extern "C" void *SUB_REALLOC(void *ptr, size_t size)
309309
{
310310
void *new_ptr = NULL;
311-
#ifdef MBED_MEM_TRACING_ENABLED
311+
#if MBED_MEM_TRACING_ENABLED
312312
mbed_mem_trace_lock();
313313
#endif
314314
#ifdef MBED_HEAP_STATS_ENABLED
@@ -336,17 +336,17 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
336336
#else // #ifdef MBED_HEAP_STATS_ENABLED
337337
new_ptr = SUPER_REALLOC(ptr, size);
338338
#endif // #ifdef MBED_HEAP_STATS_ENABLED
339-
#ifdef MBED_MEM_TRACING_ENABLED
339+
#if MBED_MEM_TRACING_ENABLED
340340
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
341341
mbed_mem_trace_unlock();
342-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
342+
#endif // #if MBED_MEM_TRACING_ENABLED
343343
return new_ptr;
344344
}
345345

346346
extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
347347
{
348348
void *ptr = NULL;
349-
#ifdef MBED_MEM_TRACING_ENABLED
349+
#if MBED_MEM_TRACING_ENABLED
350350
mbed_mem_trace_lock();
351351
#endif
352352
#ifdef MBED_HEAP_STATS_ENABLED
@@ -358,10 +358,10 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
358358
#else // #ifdef MBED_HEAP_STATS_ENABLED
359359
ptr = SUPER_CALLOC(nmemb, size);
360360
#endif // #ifdef MBED_HEAP_STATS_ENABLED
361-
#ifdef MBED_MEM_TRACING_ENABLED
361+
#if MBED_MEM_TRACING_ENABLED
362362
mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
363363
mbed_mem_trace_unlock();
364-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
364+
#endif // #if MBED_MEM_TRACING_ENABLED
365365
return ptr;
366366
}
367367

@@ -372,7 +372,7 @@ extern "C" void SUB_FREE(void *ptr)
372372

373373
extern "C" void free_wrapper(void *ptr, void *caller)
374374
{
375-
#ifdef MBED_MEM_TRACING_ENABLED
375+
#if MBED_MEM_TRACING_ENABLED
376376
mbed_mem_trace_lock();
377377
#endif
378378
#ifdef MBED_HEAP_STATS_ENABLED
@@ -388,10 +388,10 @@ extern "C" void free_wrapper(void *ptr, void *caller)
388388
#else // #ifdef MBED_HEAP_STATS_ENABLED
389389
SUPER_FREE(ptr);
390390
#endif // #ifdef MBED_HEAP_STATS_ENABLED
391-
#ifdef MBED_MEM_TRACING_ENABLED
391+
#if MBED_MEM_TRACING_ENABLED
392392
mbed_mem_trace_free(ptr, caller);
393393
mbed_mem_trace_unlock();
394-
#endif // #ifdef MBED_MEM_TRACING_ENABLED
394+
#endif // #if MBED_MEM_TRACING_ENABLED
395395
}
396396

397397
#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)
402402

403403
#else
404404

405-
#ifdef MBED_MEM_TRACING_ENABLED
405+
#if MBED_MEM_TRACING_ENABLED
406406
#error Memory tracing is not supported with the current toolchain.
407407
#endif
408408

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)