27
27
/* There are two memory tracers in mbed OS:
28
28
29
29
- the first can be used to detect the maximum heap usage at runtime. It is
30
- activated by defining the MBED_HEAP_STATS_ENABLED macro .
30
+ activated by setting the configuration option MBED_HEAP_STATS_ENABLED to true .
31
31
- the second can be used to trace each memory call by automatically invoking
32
32
a callback on each memory operation (see hal/api/mbed_mem_trace.h). It is
33
33
activated by setting the configuration option MBED_MEM_TRACING_ENABLED to true.
@@ -99,7 +99,7 @@ extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)
99
99
extern " C" void *malloc_wrapper (struct _reent *r, size_t size, void *caller)
100
100
{
101
101
void *ptr = NULL ;
102
- #if MBED_MEM_TRACING_ENABLED
102
+ #ifdef MBED_MEM_TRACING_ENABLED
103
103
mbed_mem_trace_lock ();
104
104
#endif
105
105
#ifdef MBED_HEAP_STATS_ENABLED
@@ -123,17 +123,17 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
123
123
#else // #ifdef MBED_HEAP_STATS_ENABLED
124
124
ptr = __real__malloc_r (r, size);
125
125
#endif // #ifdef MBED_HEAP_STATS_ENABLED
126
- #if MBED_MEM_TRACING_ENABLED
126
+ #ifdef MBED_MEM_TRACING_ENABLED
127
127
mbed_mem_trace_malloc (ptr, size, caller);
128
128
mbed_mem_trace_unlock ();
129
- #endif // #if MBED_MEM_TRACING_ENABLED
129
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
130
130
return ptr;
131
131
}
132
132
133
133
extern " C" void *__wrap__realloc_r (struct _reent *r, void *ptr, size_t size)
134
134
{
135
135
void *new_ptr = NULL ;
136
- #if MBED_MEM_TRACING_ENABLED
136
+ #ifdef MBED_MEM_TRACING_ENABLED
137
137
mbed_mem_trace_lock ();
138
138
#endif
139
139
#ifdef MBED_HEAP_STATS_ENABLED
@@ -166,10 +166,10 @@ extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
166
166
#else // #ifdef MBED_HEAP_STATS_ENABLED
167
167
new_ptr = __real__realloc_r (r, ptr, size);
168
168
#endif // #ifdef MBED_HEAP_STATS_ENABLED
169
- #if MBED_MEM_TRACING_ENABLED
169
+ #ifdef MBED_MEM_TRACING_ENABLED
170
170
mbed_mem_trace_realloc (new_ptr, ptr, size, MBED_CALLER_ADDR ());
171
171
mbed_mem_trace_unlock ();
172
- #endif // #if MBED_MEM_TRACING_ENABLED
172
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
173
173
return new_ptr;
174
174
}
175
175
@@ -180,7 +180,7 @@ extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
180
180
181
181
extern " C" void free_wrapper (struct _reent *r, void *ptr, void *caller)
182
182
{
183
- #if MBED_MEM_TRACING_ENABLED
183
+ #ifdef MBED_MEM_TRACING_ENABLED
184
184
mbed_mem_trace_lock ();
185
185
#endif
186
186
#ifdef MBED_HEAP_STATS_ENABLED
@@ -205,16 +205,16 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
205
205
#else // #ifdef MBED_HEAP_STATS_ENABLED
206
206
__real__free_r (r, ptr);
207
207
#endif // #ifdef MBED_HEAP_STATS_ENABLED
208
- #if MBED_MEM_TRACING_ENABLED
208
+ #ifdef MBED_MEM_TRACING_ENABLED
209
209
mbed_mem_trace_free (ptr, caller);
210
210
mbed_mem_trace_unlock ();
211
- #endif // #if MBED_MEM_TRACING_ENABLED
211
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
212
212
}
213
213
214
214
extern " C" void *__wrap__calloc_r (struct _reent *r, size_t nmemb, size_t size)
215
215
{
216
216
void *ptr = NULL ;
217
- #if MBED_MEM_TRACING_ENABLED
217
+ #ifdef MBED_MEM_TRACING_ENABLED
218
218
mbed_mem_trace_lock ();
219
219
#endif
220
220
#ifdef MBED_HEAP_STATS_ENABLED
@@ -227,10 +227,10 @@ extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
227
227
#else // #ifdef MBED_HEAP_STATS_ENABLED
228
228
ptr = __real__calloc_r (r, nmemb, size);
229
229
#endif // #ifdef MBED_HEAP_STATS_ENABLED
230
- #if MBED_MEM_TRACING_ENABLED
230
+ #ifdef MBED_MEM_TRACING_ENABLED
231
231
mbed_mem_trace_calloc (ptr, nmemb, size, MBED_CALLER_ADDR ());
232
232
mbed_mem_trace_unlock ();
233
- #endif // #if MBED_MEM_TRACING_ENABLED
233
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
234
234
return ptr;
235
235
}
236
236
@@ -286,7 +286,7 @@ extern "C" void *SUB_MALLOC(size_t size)
286
286
extern " C" void *malloc_wrapper (size_t size, void *caller)
287
287
{
288
288
void *ptr = NULL ;
289
- #if MBED_MEM_TRACING_ENABLED
289
+ #ifdef MBED_MEM_TRACING_ENABLED
290
290
mbed_mem_trace_lock ();
291
291
#endif
292
292
#ifdef MBED_HEAP_STATS_ENABLED
@@ -310,18 +310,18 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
310
310
#else // #ifdef MBED_HEAP_STATS_ENABLED
311
311
ptr = SUPER_MALLOC (size);
312
312
#endif // #ifdef MBED_HEAP_STATS_ENABLED
313
- #if MBED_MEM_TRACING_ENABLED
313
+ #ifdef MBED_MEM_TRACING_ENABLED
314
314
mbed_mem_trace_malloc (ptr, size, caller);
315
315
mbed_mem_trace_unlock ();
316
- #endif // #if MBED_MEM_TRACING_ENABLED
316
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
317
317
return ptr;
318
318
}
319
319
320
320
321
321
extern " C" void *SUB_REALLOC (void *ptr, size_t size)
322
322
{
323
323
void *new_ptr = NULL ;
324
- #if MBED_MEM_TRACING_ENABLED
324
+ #ifdef MBED_MEM_TRACING_ENABLED
325
325
mbed_mem_trace_lock ();
326
326
#endif
327
327
#ifdef MBED_HEAP_STATS_ENABLED
@@ -349,17 +349,17 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
349
349
#else // #ifdef MBED_HEAP_STATS_ENABLED
350
350
new_ptr = SUPER_REALLOC (ptr, size);
351
351
#endif // #ifdef MBED_HEAP_STATS_ENABLED
352
- #if MBED_MEM_TRACING_ENABLED
352
+ #ifdef MBED_MEM_TRACING_ENABLED
353
353
mbed_mem_trace_realloc (new_ptr, ptr, size, MBED_CALLER_ADDR ());
354
354
mbed_mem_trace_unlock ();
355
- #endif // #if MBED_MEM_TRACING_ENABLED
355
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
356
356
return new_ptr;
357
357
}
358
358
359
359
extern " C" void *SUB_CALLOC (size_t nmemb, size_t size)
360
360
{
361
361
void *ptr = NULL ;
362
- #if MBED_MEM_TRACING_ENABLED
362
+ #ifdef MBED_MEM_TRACING_ENABLED
363
363
mbed_mem_trace_lock ();
364
364
#endif
365
365
#ifdef MBED_HEAP_STATS_ENABLED
@@ -371,10 +371,10 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
371
371
#else // #ifdef MBED_HEAP_STATS_ENABLED
372
372
ptr = SUPER_CALLOC (nmemb, size);
373
373
#endif // #ifdef MBED_HEAP_STATS_ENABLED
374
- #if MBED_MEM_TRACING_ENABLED
374
+ #ifdef MBED_MEM_TRACING_ENABLED
375
375
mbed_mem_trace_calloc (ptr, nmemb, size, MBED_CALLER_ADDR ());
376
376
mbed_mem_trace_unlock ();
377
- #endif // #if MBED_MEM_TRACING_ENABLED
377
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
378
378
return ptr;
379
379
}
380
380
@@ -385,7 +385,7 @@ extern "C" void SUB_FREE(void *ptr)
385
385
386
386
extern " C" void free_wrapper (void *ptr, void *caller)
387
387
{
388
- #if MBED_MEM_TRACING_ENABLED
388
+ #ifdef MBED_MEM_TRACING_ENABLED
389
389
mbed_mem_trace_lock ();
390
390
#endif
391
391
#ifdef MBED_HEAP_STATS_ENABLED
@@ -410,10 +410,10 @@ extern "C" void free_wrapper(void *ptr, void *caller)
410
410
#else // #ifdef MBED_HEAP_STATS_ENABLED
411
411
SUPER_FREE (ptr);
412
412
#endif // #ifdef MBED_HEAP_STATS_ENABLED
413
- #if MBED_MEM_TRACING_ENABLED
413
+ #ifdef MBED_MEM_TRACING_ENABLED
414
414
mbed_mem_trace_free (ptr, caller);
415
415
mbed_mem_trace_unlock ();
416
- #endif // #if MBED_MEM_TRACING_ENABLED
416
+ #endif // #ifdef MBED_MEM_TRACING_ENABLED
417
417
}
418
418
419
419
#endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
@@ -424,7 +424,7 @@ extern "C" void free_wrapper(void *ptr, void *caller)
424
424
425
425
#else
426
426
427
- #if MBED_MEM_TRACING_ENABLED
427
+ #ifdef MBED_MEM_TRACING_ENABLED
428
428
#error Memory tracing is not supported with the current toolchain.
429
429
#endif
430
430
0 commit comments