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

new w/ OOM raises an exception, shows the caller address for decoders

This commit is contained in:
david gauchard 2020-08-24 22:15:33 +02:00
parent 11f7d1766e
commit 2b6423edcc
3 changed files with 17 additions and 2 deletions

View File

@ -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;
}
@ -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)
{

View File

@ -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);

View File

@ -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__)