Skip to content

Commit b083043

Browse files
committed
refactored print_loc()
removed experimental debug extension as requested added forgotten OOM count to the postmortem report
1 parent 4717dcf commit b083043

File tree

4 files changed

+16
-166
lines changed

4 files changed

+16
-166
lines changed

cores/esp8266/core_esp8266_postmortem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "gdb_hooks.h"
3434
#include "StackThunk.h"
3535
#include "coredecls.h"
36+
#include "umm_malloc/umm_malloc.h"
3637

3738
extern "C" {
3839

@@ -284,6 +285,11 @@ static void postmortem_report(uint32_t sp_dump) {
284285
ets_printf_P(PSTR("\nlast failed alloc caller: 0x%08x\n"), (uint32_t)_umm_last_fail_alloc.addr);
285286
}
286287

288+
size_t oom_count = umm_get_oom_count();
289+
if (oom_count) {
290+
ets_printf_P(PSTR("\nOOM Count: %u\n"), oom_count);
291+
}
292+
287293
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
288294

289295
ets_delay_us(10000);

cores/esp8266/heap.cpp

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ extern "C" void z2EapFree(void *ptr, const char* file, int line) __attribute__((
124124
#include <sys/reent.h>
125125
#include <user_interface.h>
126126

127-
#include "heap_cb.h"
128-
129127
extern "C" {
130128

131129
///////////////////////////////////////////////////////////////////////////////
@@ -271,41 +269,26 @@ struct umm_last_fail_alloc {
271269
// OOM - Debug printing
272270
//
273271
// IRQ/ISR safe printing macros. Printing is controled according to the results
274-
// of system_get_os_print(). Also, being in a IRQ will prevent the printing of
272+
// of system_get_os_print(). Also, being in an IRQ may prevent the printing of
275273
// file names stored in PROGMEM. The PROGMEM address to the string is printed in
276274
// its place.
277275
#define DEBUG_HEAP_PRINTF ets_uart_printf
278-
279-
static ALWAYS_INLINE bool withinISR(uint32_t ps) {
280-
return (0 != (ps & 0x0fu));
276+
inline bool withinISR(uint32_t ps) {
277+
return ((ps & 0x0f) != 0);
281278
}
282279

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-
295280
static void IRAM_ATTR print_loc(bool inISR, size_t size, const char* file, int line, const void* caller) {
296281
if (system_get_os_print()) {
297282
DEBUG_HEAP_PRINTF(":oom %p(%d), File: ", caller, (int)size);
298283
if (file) {
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-
}
284+
// Small code reduction by assuming file address is in PROGMEM
285+
if (inISR) {
286+
DEBUG_HEAP_PRINTF("%p", file);
307287
} else {
308-
DEBUG_HEAP_PRINTF(file);
288+
size_t sz = strlen_P(file);
289+
char buf[sz + 1];
290+
strcpy_P(buf, file);
291+
DEBUG_HEAP_PRINTF(buf);
309292
}
310293
} else {
311294
DEBUG_HEAP_PRINTF("??");
@@ -326,7 +309,6 @@ static bool IRAM_ATTR oom_check__log_last_fail_atomic_psflc(void *ptr, size_t si
326309
_umm_last_fail_alloc.line = line;
327310
print_loc(withinISR(saved_ps), size, file, line, caller);
328311
xt_wsr_ps(saved_ps);
329-
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_oom_cb_id, ptr, size, file, line, caller);
330312
return false;
331313
}
332314
return true;
@@ -342,7 +324,6 @@ static bool IRAM_ATTR oom_check__log_last_fail_atomic_psc(void *ptr, size_t size
342324
_umm_last_fail_alloc.addr = caller;
343325
_umm_last_fail_alloc.size = size;
344326
xt_wsr_ps(saved_ps);
345-
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_oom_cb_id, ptr, size, NULL, 0, caller);
346327
return false;
347328
}
348329
return true;
@@ -358,7 +339,6 @@ static bool oom_check__log_last_fail_psc(void *ptr, size_t size, const void* cal
358339
if (0 != (size) && 0 == ptr) {
359340
_umm_last_fail_alloc.addr = caller;
360341
_umm_last_fail_alloc.size = size;
361-
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_oom_cb_id, ptr, size, NULL, 0, caller);
362342
return false;
363343
}
364344
return true;
@@ -423,7 +403,6 @@ void* IRAM_ATTR _heap_pvPortMalloc(size_t size, const char* file, int line, cons
423403
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
424404
POISON_CHECK__PANIC_FL(file, line, caller);
425405
void* ret = UMM_MALLOC_FL(size, file, line, caller);
426-
ret = _HEAP_DEBUG_PROBE_PSFLC_CB(heap_malloc_cb_id, ret, size, file, line, caller);
427406
OOM_CHECK__LOG_LAST_FAIL_FL(ret, size, file, line, caller);
428407
return ret;
429408
}
@@ -434,7 +413,6 @@ void* IRAM_ATTR _heap_pvPortCalloc(size_t count, size_t size, const char* file,
434413
POISON_CHECK__PANIC_FL(file, line, caller);
435414
size_t total_size = umm_umul_sat(count, size);
436415
void* ret = UMM_CALLOC_FL(1, total_size, file, line, caller);
437-
ret = _HEAP_DEBUG_PROBE_PSFLC_CB(heap_calloc_cb_id, ret, size, file, line, caller);
438416
OOM_CHECK__LOG_LAST_FAIL_FL(ret, total_size, file, line, caller);
439417
return ret;
440418
}
@@ -443,9 +421,7 @@ void* IRAM_ATTR _heap_pvPortRealloc(void *ptr, size_t size, const char* file, in
443421
{
444422
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
445423
POISON_CHECK__PANIC_FL(file, line, caller);
446-
ptr = _HEAP_DEBUG_PROBE_PSFLC_CB(heap_realloc_in_cb_id, ptr, size, file, line, caller);
447424
void* ret = UMM_REALLOC_FL(ptr, size, file, line, caller);
448-
ret = _HEAP_DEBUG_PROBE_PSFLC_CB(heap_realloc_out_cb_id, ret, size, file, line, caller);
449425
OOM_CHECK__LOG_LAST_FAIL_FL(ret, size, file, line, caller);
450426
return ret;
451427
}
@@ -454,7 +430,6 @@ void IRAM_ATTR _heap_vPortFree(void *ptr, const char* file, int line, [[maybe_un
454430
{
455431
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
456432
POISON_CHECK__PANIC_FL(file, line, caller);
457-
ptr = _HEAP_DEBUG_PROBE_PSFLC_CB(heap_free_cb_id, ptr, 0, file, line, caller);
458433
UMM_FREE_FL(ptr, file, line, caller);
459434
}
460435

@@ -672,7 +647,6 @@ void* _heap_abi_malloc(size_t size, bool unhandled, const void* caller)
672647
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
673648
POISON_CHECK__PANIC_FL(file, line, caller);
674649
void* ret = UMM_MALLOC_FL(size, file, line, caller);
675-
ret = _HEAP_DEBUG_PROBE_PSFLC_CB(heap_abi_malloc_cb_id, ret, size, file, line, caller);
676650
bool ok = OOM_CHECK__LOG_LAST_FAIL_FL(ret, size, file, line, caller);
677651
#else
678652
void* ret = UMM_MALLOC(size);

cores/esp8266/heap_cb.h

Lines changed: 0 additions & 126 deletions
This file was deleted.

cores/esp8266/umm_malloc/umm_local.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static bool check_poison_neighbors(umm_heap_context_t *_context, uint16_t cur) {
8383
}
8484

8585
/* ------------------------------------------------------------------------ */
86-
#include "heap_cb.h"
8786

8887
static void *get_unpoisoned_check_neighbors(const void *vptr, const char *file, int line, const void *caller) {
8988
uintptr_t ptr = (uintptr_t)vptr;
@@ -105,18 +104,15 @@ static void *get_unpoisoned_check_neighbors(const void *vptr, const char *file,
105104
if (!check_poison_block(&UMM_BLOCK(c))) {
106105
DBGLOG_ERROR("Allocation address %p\n", vptr);
107106
size_t size = *(size_t *)ptr;
108-
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_poison_lite_cb_id, (void *)ptr, size, file, line, caller);
109107
poison = false;
110108
} else
111109
if (!check_poison_neighbors(_context, c)) {
112110
DBGLOG_ERROR("This bad block is in a neighbor allocation near: %p\n", vptr);
113-
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_poison_lite_neighbor_cb_id, (void *)ptr, 0, file, line, caller);
114111
poison = false;
115112
}
116113
UMM_CRITICAL_EXIT(id_poison);
117114
} else {
118115
DBGLOG_ERROR("\nPointer %p is not a Heap address.\n", vptr);
119-
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_poison_lite_addr_cb_id, (void *)ptr, 0, file, line, caller);
120116
poison = false;
121117
}
122118

0 commit comments

Comments
 (0)