Skip to content

Commit 2b6423e

Browse files
committed
new w/ OOM raises an exception, shows the caller address for decoders
1 parent 11f7d17 commit 2b6423e

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

cores/esp8266/abi.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
3232
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
3333

3434

35-
#if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
35+
#if !defined(__cpp_exceptions)
36+
37+
// overwrite weak operators new/new[] definitions
38+
3639
void *operator new(size_t size)
3740
{
3841
void *ret = malloc(size);
3942
if (0 != size && 0 == ret) {
4043
umm_last_fail_alloc_addr = __builtin_return_address(0);
4144
umm_last_fail_alloc_size = size;
45+
#if defined(NEW_OOM_ABORT)
46+
__unhandled_exception(PSTR("OOM"));
47+
#endif
4248
}
4349
return ret;
4450
}
@@ -49,10 +55,14 @@ void *operator new[](size_t size)
4955
if (0 != size && 0 == ret) {
5056
umm_last_fail_alloc_addr = __builtin_return_address(0);
5157
umm_last_fail_alloc_size = size;
58+
#if defined(NEW_OOM_ABORT)
59+
__unhandled_exception(PSTR("OOM"));
60+
#endif
5261
}
5362
return ret;
5463
}
55-
#endif // arduino's std::new legacy
64+
65+
#endif // !defined(__cpp_exceptions)
5666

5767
void __cxa_pure_virtual(void)
5868
{

cores/esp8266/core_esp8266_postmortem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ void __wrap_system_restart_local() {
220220

221221
cut_here();
222222

223+
// now outside from the "cut-here" zone, print correctly the malloc address,
224+
// idf-monitor.py will be able to decode this one and show exact location in sources
225+
ets_printf_P(PSTR("\nlast failed alloc call: 0x%08x\n"), (uint32_t)umm_last_fail_alloc_addr);
226+
223227
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
224228

225229
ets_delay_us(10000);

cores/esp8266/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols);
2222
extern "C" {
2323
#endif
2424

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

0 commit comments

Comments
 (0)