Skip to content
Prev Previous commit
Next Next commit
new w/ OOM raises an exception, shows the caller address for decoders
  • Loading branch information
d-a-v committed Aug 24, 2020
commit 2b6423edccfb9edd696a573af9698547a66b2dd1
14 changes: 12 additions & 2 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));


#if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
#if !defined(__cpp_exceptions)

// overwrite weak operators new/new[] definitions

void *operator new(size_t 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;
#if defined(NEW_OOM_ABORT)
__unhandled_exception(PSTR("OOM"));
#endif
}
return ret;
}
Expand All @@ -49,10 +55,14 @@ void *operator new[](size_t size)
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
#if defined(NEW_OOM_ABORT)
__unhandled_exception(PSTR("OOM"));
#endif
}
return ret;
}
#endif // arduino's std::new legacy

#endif // !defined(__cpp_exceptions)

void __cxa_pure_virtual(void)
{
Expand Down
4 changes: 4 additions & 0 deletions cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ void __wrap_system_restart_local() {

cut_here();

// now outside from the "cut-here" zone, print correctly the malloc address,
// idf-monitor.py will be able to decode this one and show exact location in sources
ets_printf_P(PSTR("\nlast failed alloc call: 0x%08x\n"), (uint32_t)umm_last_fail_alloc_addr);

custom_crash_callback( &rst_info, sp_dump + offset, stack_end );

ets_delay_us(10000);
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols);
extern "C" {
#endif

void __unhandled_exception(const char *str) __attribute__((noreturn));
void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
#define panic() __panic_func(PSTR(__FILE__), __LINE__, __func__)

Expand Down