8000 Heap: Improve debug caller address reporting by mhightower83 · Pull Request #8720 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Heap: Improve debug caller address reporting #8720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4ec3c81
Lite refactoring and expanded comments
mhightower83 Nov 11, 2022
6088147
Improve caller address reporting to indicate address in
mhightower83 Nov 18, 2022
a716193
missed items
mhightower83 Nov 21, 2022
1102256
improve comments
mhightower83 Nov 22, 2022
6dfd46a
Merge branch 'master' into pr-heap-refactor3
mhightower83 Dec 5, 2022
8b3bb1f
Merge branch 'master' into pr-heap-refactor3
mhightower83 Dec 17, 2022
ea9befa
Finish merge cleanuo
mhightower83 Dec 17, 2022
3dd08be
requested changes
mhightower83 Dec 17, 2022
45f1c3b
Added missing DRAM fallback to pvPortCallocIram, pvPortZallocIram, and
mhightower83 Dec 18, 2022
57eb2b3
Add nothrow to aliases
mhightower83 Dec 18, 2022
c2590a7
Merge branch 'master' into pr-heap-refactor3
mhightower83 Dec 19, 2022
0619034
Merge branch 'pr-heap-refactor3' of github.com:mhightower83/Arduino i…
mhightower83 Dec 19, 2022
19da675
Merge branch 'master' into pr-heap-refactor3
mhightower83 Dec 19, 2022
af7b962
Merge branch 'pr-heap-refactor3' of github.com:mhightower83/Arduino i…
mhightower83 Dec 19, 2022
9423c8e
Merge branch 'master' into pr-heap-refactor3
mhightower83 Dec 22, 2022
471f838
Merge branch 'pr-heap-refactor3' of github.com:mhightower83/Arduino i…
mhightower83 Dec 22, 2022
d829540
Merge branch 'master' into pr-heap-refactor3
mhightower83 Jan 20, 2023
4c96365
Merge branch 'pr-heap-refactor3' of github.com:mhightower83/Arduino i…
mhightower83 Jan 20, 2023
840e55a
Merge branch 'master' into pr-heap-refactor3
mhightower83 Apr 18, 2023
95c7e2c
Merge branch 'master' into pr-heap-refactor3
mhightower83 Apr 27, 2023
0ce295e
Merge branch 'master' into pr-heap-refactor3
mhightower83 Apr 28, 2023
4717dcf
Use the same format for printing caller, file, line details
mhightower83 Apr 29, 2023
b083043
refactored print_loc()
mhightower83 Apr 29, 2023
ecc1b14
Merge branch 'master' into pr-heap-refactor3
mhightower83 May 2, 2023
a0044d6
Merge branch 'master' into pr-heap-refactor3
mhightower83 Jun 16, 2023
01b238a
Merge branch 'master' into pr-heap-refactor3
mhightower83 Jul 21, 2023
b5aa1de
removed unused variable from umm_local.c
mhightower83 Jul 21, 2023
1c99daf
Merge branch 'master' into pr-heap-refactor3
mhightower83 Feb 6, 2024
2bbadca
Merge branch 'master' into pr-heap-refactor3
mhightower83 Aug 30, 2024
49b48fb
Requested changes
mhightower83 Sep 3, 2024
3786ce6
Added missing "new" operators
mhightower83 Sep 5, 2024
b9a0e55
Added missing delete array operators
mhightower83 Sep 6, 2024
a5f6d7d
malloc align build cleanup - fully builds
mhightower83 Sep 8, 2024
54b034b
Correct possition of UMM_ENABLE_MEMALIGN handling in umm_malloc/umm_m…
mhightower83 Sep 12, 2024
e948329
remove static_assert checks on alignment
mhightower83 Sep 15, 2024
5653249
Updated changes to match upstream style using uncrustify.
mhightower83 Sep 17, 2024
d303d01
update comments
mhightower83 Oct 15, 2024
01a89fd
Added test Sketch for "new" and "delete" operators
mhightower83 Oct 21, 2024
0574c1a
Oops, remove external debug libary from example.
mhightower83 Oct 22, 2024
31217f6
Improved build coverage of DEV_DEBUG_ABI_CPP option and operator dele…
mhightower83 Oct 24, 2024
ecc7eed
Changed printf format from %S => %s
mhightower83 Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
mhightower83 committed Apr 29, 2023
commit 4717dcfa771dd80be4eb20fbd1612bc33251f324
8 changes: 5 additions & 3 deletions cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ static void postmortem_report(uint32_t sp_dump) {
// Use cap-X formatting to ensure the standard EspExceptionDecoder doesn't match the address
if (_umm_last_fail_alloc.addr) {
#if defined(DEBUG_ESP_OOM)
ets_printf_P(PSTR("\nlast failed alloc call: %08X(%d)@%S:%d\n"),
(uint32_t)_umm_last_fail_alloc.addr, _umm_last_fail_alloc.size,
_umm_last_fail_alloc.file, _umm_last_fail_alloc.line);
ets_printf_P(PSTR("\nlast failed alloc call: 0x%08X(%d), File: %S:%d\n"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%s not %S?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%S, umm_last_fail_alloc_file can be a PROGMEM string
At least some SDK file name strings are in .irom.text.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No special case in newlib here? Implementation thinks of both 's' and 'S' as exactly same
https://github.com/earlephilhower/newlib-xtensa/blob/ebc967552ce827f21fc579fd8c437037c1b472ab/newlib/libc/stdio/nano-vfprintf_i.c#L217

printf(3) says it is '%ls', which is wide-char ('wchar_t') and non-applicable here

Synonym for ls. Don't use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have always been confused about this duality. Some print functions give an error (or is it a warning?) about %S and PROGMEM strings while other functions don't, like Serial.printf_P.

%S is used throughout core_esp_8266_postmortem.cpp for handling the printing of PROGMEM strings.

The comment for the code you pointed out reads to me that Arduino intends to have %S for PROGMEM strings.

case 'S': // TODO: Verify cap-S under Arduino is "PROGMEM char*", not wchar_t

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6280e98 / #5376
requested in #4223 (...which I would guess gets dragged down from AVR Core?)
merged in the original newlib 3.x.x code via igrr/newlib-xtensa#5

Add "%S" (capital-S) format that I've been told, but cannot verify, is used in Arduino to specify a PROGMEM string parameter in printfs, as an alias for "%s" since plain "%s" can now handle PROGMEM.

as-is both '%s' and even '%.*s' work seamlessly, no need for extra care
but it is true that it is used across the file, probably better served in a separate PR. at the very least for consistency

(uint32_t)_umm_last_fail_alloc.addr,
_umm_last_fail_alloc.size,
(_umm_last_fail_alloc.file) ? _umm_last_fail_alloc.file : "??",
_umm_last_fail_alloc.line);
#else
ets_printf_P(PSTR("\nlast failed alloc call: %08X(%d)\n"), (uint32_t)_umm_last_fail_alloc.addr, _umm_last_fail_alloc.size);
#endif
Expand Down
44 changes: 30 additions & 14 deletions cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,42 @@ struct umm_last_fail_alloc {
// file names stored in PROGMEM. The PROGMEM address to the string is printed in
// its place.
#define DEBUG_HEAP_PRINTF ets_uart_printf
static void IRAM_ATTR print_loc(size_t size, const char* file, int line, const void* caller)
{
if (system_get_os_print()) {
DEBUG_HEAP_PRINTF(":oom(%d)@", (int)size);

static ALWAYS_INLINE bool withinISR(uint32_t ps) {
return (0 != (ps & 0x0fu));
}

#if 0
/*
ICACHE should be accessable from an ISR "IF" it has not been disabled for a
SPI bus transfer. TODO investagate further - `if (inISR && ! isCacheReady())`
*/
#define SPIRDY ESP8266_DREG(0x0C) // CACHE_FLASH_CTRL_REG
#define CACHE_READ_EN_BIT BIT8 // eagle_soc.h in RTOS_SDK
static ALWAYS_INLINE bool isCacheReady(void) {
return 0 != (SPIRDY & CACHE_READ_EN_BIT);
}
#endif

static void IRAM_ATTR print_loc(bool inISR, size_t size, const char* file, int line, const void* caller) {
if (system_get_os_print()) {
DEBUG_HEAP_PRINTF(":oom %p(%d), File: ", caller, (int)size);
if (file) {
bool inISR = ETS_INTR_WITHINISR();
if (inISR && (uint32_t)file >= 0x40200000) {
DEBUG_HEAP_PRINTF("%p, File: %p", caller, file);
} else if (!inISR && (uint32_t)file >= 0x40200000) {
char buf[strlen_P(file) + 1];
strcpy_P(buf, file);
DEBUG_HEAP_PRINTF("%p, File: %s", caller, buf);
if ((uint32_t)file >= 0x40200000) {
if (inISR) {
DEBUG_HEAP_PRINTF("%p", file);
} else {
char buf[strlen_P(file) + 1];
strcpy_P(buf, file);
DEBUG_HEAP_PRINTF(buf);
}
} else {
DEBUG_HEAP_PRINTF(file);
}
DEBUG_HEAP_PRINTF(":%d\n", line);
} else {
DEBUG_HEAP_PRINTF("%p\n", caller);
DEBUG_HEAP_PRINTF("??");
}
DEBUG_HEAP_PRINTF(":%d\n", line);
}
}

Expand All @@ -308,7 +324,7 @@ static bool IRAM_ATTR oom_check__log_last_fail_atomic_psflc(void *ptr, size_t si
_umm_last_fail_alloc.size = size;
_umm_last_fail_alloc.file = file;
_umm_last_fail_alloc.line = line;
print_loc(size, file, line, caller);
print_loc(withinISR(saved_ps), size, file, line, caller);
xt_wsr_ps(saved_ps);
_HEAP_DEBUG_PROBE_PSFLC_CB(heap_oom_cb_id, ptr, size, file, line, caller);
return false;
Expand Down
0