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 Jan 30, 2023
1 parent 0025915 commit f9c613d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion components/heap/heap_caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ 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 cat(char* dest, const char* src)
{
size_t sLen = strlen(src);
size_t dLen = strlen(dest);
memcpy(dest + dLen, src, sLen + 1);
}

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);
cat(dest, "Memory allocation failed. size: ");
cat(dest, sSize);
cat(dest, " caps: 0x");
cat(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 +82,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[70];
memset(buf, 0, sizeof(buf));
fmt_abort_str(buf, requested_size, caps);
esp_system_abort(buf);
#endif
}

Expand Down

0 comments on commit f9c613d

Please sign in to comment.