Skip to content

Commit 4717dcf

Browse files
committed
Use the same format for printing caller, file, line details
in postmortem and printing OOM from Heap wrappers. Fixed crash within postmortem when OOM file is NULL Fixed printing OOM file name when not in ISR.
1 parent 0ce295e commit 4717dcf

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

cores/esp8266/core_esp8266_postmortem.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ static void postmortem_report(uint32_t sp_dump) {
266266
// Use cap-X formatting to ensure the standard EspExceptionDecoder doesn't match the address
267267
if (_umm_last_fail_alloc.addr) {
268268
#if defined(DEBUG_ESP_OOM)
269-
ets_printf_P(PSTR("\nlast failed alloc call: %08X(%d)@%S:%d\n"),
270-
(uint32_t)_umm_last_fail_alloc.addr, _umm_last_fail_alloc.size,
271-
_umm_last_fail_alloc.file, _umm_last_fail_alloc.line);
269+
ets_printf_P(PSTR("\nlast failed alloc call: 0x%08X(%d), File: %S:%d\n"),
270+
(uint32_t)_umm_last_fail_alloc.addr,
271+
_umm_last_fail_alloc.size,
272+
(_umm_last_fail_alloc.file) ? _umm_last_fail_alloc.file : "??",
273+
_umm_last_fail_alloc.line);
272274
#else
273275
ets_printf_P(PSTR("\nlast failed alloc call: %08X(%d)\n"), (uint32_t)_umm_last_fail_alloc.addr, _umm_last_fail_alloc.size);
274276
#endif

cores/esp8266/heap.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,42 @@ struct umm_last_fail_alloc {
275275
// file names stored in PROGMEM. The PROGMEM address to the string is printed in
276276
// its place.
277277
#define DEBUG_HEAP_PRINTF ets_uart_printf
278-
static void IRAM_ATTR print_loc(size_t size, const char* file, int line, const void* caller)
279-
{
280-
if (system_get_os_print()) {
281-
DEBUG_HEAP_PRINTF(":oom(%d)@", (int)size);
282278

279+
static ALWAYS_INLINE bool withinISR(uint32_t ps) {
280+
return (0 != (ps & 0x0fu));
281+
}
282+
283+
#if 0
284+
/*
285+
ICACHE should be accessable from an ISR "IF" it has not been disabled for a
286+
SPI bus transfer. TODO investagate further - `if (inISR && ! isCacheReady())`
287+
*/
288+
#define SPIRDY ESP8266_DREG(0x0C) // CACHE_FLASH_CTRL_REG
289+
#define CACHE_READ_EN_BIT BIT8 // eagle_soc.h in RTOS_SDK
290+
static ALWAYS_INLINE bool isCacheReady(void) {
291+
return 0 != (SPIRDY & CACHE_READ_EN_BIT);
292+
}
293+
#endif
294+
295+
static void IRAM_ATTR print_loc(bool inISR, size_t size, const char* file, int line, const void* caller) {
296+
if (system_get_os_print()) {
297+
DEBUG_HEAP_PRINTF(":oom %p(%d), File: ", caller, (int)size);
283298
if (file) {
284-
bool inISR = ETS_INTR_WITHINISR();
285-
if (inISR && (uint32_t)file >= 0x40200000) {
286-
DEBUG_HEAP_PRINTF("%p, File: %p", caller, file);
287-
} else if (!inISR && (uint32_t)file >= 0x40200000) {
288-
char buf[strlen_P(file) + 1];
289-
strcpy_P(buf, file);
290-
DEBUG_HEAP_PRINTF("%p, File: %s", caller, buf);
299+
if ((uint32_t)file >= 0x40200000) {
300+
if (inISR) {
301+
DEBUG_HEAP_PRINTF("%p", file);
302+
} else {
303+
char buf[strlen_P(file) + 1];
304+
strcpy_P(buf, file);
305+
DEBUG_HEAP_PRINTF(buf);
306+
}
291307
} else {
292308
DEBUG_HEAP_PRINTF(file);
293309
}
294-
DEBUG_HEAP_PRINTF(":%d\n", line);
295310
} else {
296-
DEBUG_HEAP_PRINTF("%p\n", caller);
311+
DEBUG_HEAP_PRINTF("??");
297312
}
313+
DEBUG_HEAP_PRINTF(":%d\n", line);
298314
}
299315
}
300316

@@ -308,7 +324,7 @@ static bool IRAM_ATTR oom_check__log_last_fail_atomic_psflc(void *ptr, size_t si
308324
_umm_last_fail_alloc.size = size;
309325
_umm_last_fail_alloc.file = file;
310326
_umm_last_fail_alloc.line = line;
311-
print_loc(size, file, line, caller);
327+
print_loc(withinISR(saved_ps), size, file, line, caller);
312328
xt_wsr_ps(saved_ps);
313329
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_oom_cb_id, ptr, size, file, line, caller);
314330
return false;

0 commit comments

Comments
 (0)