Skip to content

Commit

Permalink
[Logs] print size and caps when malloc fails
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Feb 1, 2023
1 parent 0025915 commit 526a73e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/heap/heap_caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ IRAM_ATTR static void *dram_alloc_to_iram_addr(void *addr, size_t len)
return iptr + 1;
}

#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
static void fmt_abort_str(char* dest, size_t requested_size, uint32_t caps)
{
char sSize[11];
char sCaps[9];
itoa(requested_size, sSize, 10);
itoa(caps, sCaps, 16);
strcat(dest, "Mem alloc fail. size ");
strcat(dest, sSize);
strcat(dest, " caps 0x");
strcat(dest, sCaps);
}
#endif

IRAM_ATTR NOINLINE_ATTR static void heap_caps_alloc_failed(size_t requested_size, uint32_t caps, const char *function_name)
{
Expand All @@ -62,7 +75,10 @@ IRAM_ATTR NOINLINE_ATTR static void heap_caps_alloc_failed(size_t requested_size
}

#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
esp_system_abort("Memory allocation failed");
static char buf[48];
memset(buf, 0, sizeof(buf));
fmt_abort_str(buf, requested_size, caps);
esp_system_abort(buf);
#endif
}

Expand Down

0 comments on commit 526a73e

Please sign in to comment.