[liba] Enable malloc/free logging

Change-Id: I65ab731091440854c6db486078fef49901f855fd
This commit is contained in:
Romain Goyet
2017-02-14 11:12:36 +01:00
parent 6343a84735
commit 61e48981ef
2 changed files with 28 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ CXX=clang++
LD=clang++
SIZE=size
SFLAGS += -DLOG_DYNAMIC_MEMORY
SFLAGS += -DLIBA_LOG_DYNAMIC_MEMORY
USE_LIBA=1
EXE=elf

View File

@@ -2,6 +2,20 @@
#include <string.h>
#include <private/memconfig.h>
#if LIBA_LOG_DYNAMIC_MEMORY
#include <stdint.h>
#include <ion/c.h>
void write_uint32_in_buffer(uint32_t n, char * buffer) {
for (int i=0; i<2*sizeof(uint32_t); i++) {
unsigned char v = (n & 0xF);
char c = (v>9) ? 'A'+v-10 : '0'+v;
buffer[2*sizeof(uint32_t)-1-i] = c;
n = n >> 4;
}
}
#endif
extern char _heap_start;
extern char _heap_end;
@@ -26,6 +40,11 @@ static void configure_heap() {
}
void free(void *ptr) {
#if LIBA_LOG_DYNAMIC_MEMORY
char message[5+2*sizeof(uint32_t)+1] = {'F', 'R', 'E', 'E', '-'};
write_uint32_in_buffer((uint32_t)ptr, message+5);
ion_log_print(message);
#endif
if (ptr != NULL) {
memsys5FreeUnsafe(ptr);
}
@@ -39,6 +58,14 @@ void * malloc(size_t size) {
if (size > 0) {
p = memsys5MallocUnsafe(memsys5Roundup(size));
}
#if LIBA_LOG_DYNAMIC_MEMORY
char message[7+2*sizeof(uint32_t)+1+2*sizeof(uint32_t)+1] = {'M','A','L','L','O','C','-'};
write_uint32_in_buffer((uint32_t)p, message+7);
message[7+2*sizeof(uint32_t)] = '-';
write_uint32_in_buffer(size, message+7+2*sizeof(uint32_t)+1);
message[7+2*sizeof(uint32_t)+1+2*sizeof(uint32_t)] = 0;
ion_log_print(message);
#endif
return p;
}