Arduino
Arduino copied to clipboard
Heap: Improve debug caller address reporting
PR Status: ready
Heap: Improve debug caller address reporting to indicate the address in the sketch or library.
Lite refactoring of heap.cpp
and expanded comments
- Lite refactoring of
DEBUG_ESP_OOM
printing - Overall refactoring to make it easier to follow.
- Changes to support atomic save of OOM debug info
- Debug support for C++ "delete" operator - support reporting caller address
Overall avoid identifying the wrapper code as the source of the Heap call. Each outer wrapper passes the caller's address down to the next level.
Improves "caller" address reporting for OOM and Poison events. Previously, some OOM and Poison events reported info pointing to the thick heap wrapper rather than back to the caller. Update abi.cpp
, heap.cpp
and umm_local.c
(umm_poison
) to support caller parameters.
Enhanced DEBUG_ESP_OOM
to track OOM events when C++ Exceptions: "enabled" is selected. Report more interesting higher-level code addresses as the caller instead of GCC C++ module.
Added DEBUG_ESP_WITHINISR
to provide notification for ISRs using C++ "new"/"delete" operators or LIBC
calls using _malloc_r
, ...
Enhanced poison neighbor reporting to distinguish between allocation vs. neighbor failing poison check.
Support for specifying both UMM_POISON_CHECK and UMM_POISON_CHECK_LITE at the same time did not work as expected. UMM_POISON_CHECK_LITE dominated in the build. Fix: Keep things simple and prevent combining UMM_POISON_CHECK and UMM_POISON_CHECK_LITE. Defines for UMM_POISON_CHECK, UMM_POISON_CHECK_LITE, and UMM_POISON_NONE are checked for mutual exclusivity.
For sketches with extremely limited resources, added UMM_POISON_NONE to prevent UMM_POISON_CHECK_LITE from being added to debug builds.
Moved port related changes for UMM_POISON...
from umm_malloc_cfg.h
to umm_malloc_cfgport.h
.
Added support for aligned allocations. To preserve smaller build sizes, aligned allocations default to disable. When required, supply build option -DUMM_ENABLE_MEMALIGN=1
.
If you see the linker error message: "
.../gcc-gnu/libstdc++-v3/libsupc++/new_opa.cc:86: undefined reference to 'memalign'
" your Arduino Sketch is using an operation that requires an aligned allocation. Then, add the line-DUMM_ENABLE_MEMALIGN=1
to the build options.
Heap Changes
Enhancements to the UMM_MALLOC library
- Support for default 8-byte aligned data addresses. (previously was 4-byte)
- To accommodate any libraries or Sketches that may have workarounds for the old 4-byte alignment, a deprecated build option
-DUMM_LEGACY_ALIGN_4BYTE=1
was added. - Support the memalign() function needed for the C++17 "new" aligned operator. Enable with build option
-DUMM_ENABLE_MEMALIGN=1
. - Build options
-DUMM_LEGACY_ALIGN_4BYTE=1
and-DUMM_ENABLE_MEMALIGN=1
are mutually exclusive. - Allocations from
memalign()
internally appear and are handled like any otherUMM_MALLOC
memory allocation. - The existing
free()
function handles releasingmemalign()
memory allocations. - Function
realloc()
should not be called for aligned memory allocations. It can break the alignment. At worst, the alignment falls back tosizeof(umm_block)
, 8 bytes. - The UMM_POISON build option was extended to support memalign().
Modules heap.cpp and abi.cpp updated for build option -DUMM_ENABLE_MEMALIGN=1
. C++ "new" operator overloads were updated to support the alignment argument.
(Keep this description updated to reflect the current PR )