1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-10-30 04:26:50 +03:00

Record last failed alloc, dump on a panic (#4220)

At runtime, whenever a realloc, malloc, calloc, or new call fails to
find enough memory, record the calling function and size requested.
Does not print anything or call any heavyweight functions on this, as it
is legal to return NULL to an alloc-type call.

If the main application handles this NULL properly, there should be no
panic and nothing different will happen.

If the main application panics() at any later point in time, this record
will be printed out as part of the crash log for processing with an
updated EspExceptionDecoder.java.

This adds 2-3 instructions overhead in the normal case, and around 10-12
instructions in the failing case, and requires an additional 8 bytes of
.BSS to function.

Only a single address is kept, the final failing malloc-type function call
before a panic, but it is trivial to extend to a fifo with little overhead
in the common, non-failing case.
This commit is contained in:
Earle F. Philhower, III
2018-03-17 07:51:32 -07:00
committed by GitHub
parent 06352ab0e1
commit 4a958c8444
4 changed files with 64 additions and 5 deletions

View File

@@ -24,14 +24,28 @@
using __cxxabiv1::__guard;
// Debugging helper, last allocation which returned NULL
extern void *umm_last_fail_alloc_addr;
extern int umm_last_fail_alloc_size;
void *operator new(size_t size)
{
return malloc(size);
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}
void *operator new[](size_t size)
{
return malloc(size);
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}
void operator delete(void * ptr)