Print registers, stack & other details on unhandled exception #1026
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!1026
Loading…
Reference in a new issue
No description provided.
Delete branch "alastairpatrick/fatal-exception"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This partially fixes issue #228.
If (and only if) pico_debug is linked with a target, when an unhandled exception occurs, before executing BKPT #0, dump some useful state to stdout. This information includes the processor core number, the exception type, most ARM registers and the top few words of the stack, as they were before entry to the exception.
Probably the most useful information is in the PC register, which indicates which function was executing when the exception happened. The hex value can be looked up in the generated .elf.map files. Although most people are probably using GDB for that kind of thing, GDB isn't always possible.
It is RTOS friendly in that it checks whether a process stack is being used or not and doesn't make any assumptions about the location of the stack.
The exception handler still eventually does BKPT #0, so it works well with or without a debugger attached.
Example output:
In the stack memory dump above, white space is output for locations that do not fall in static RAM.
Some more thoughts. I initially thought that, since the default exception handler symbols such as
isr_hardfaultare weak, I could simply provide alternate definitions of those symbols. It seemed no modifications to crt0.s would be needed and this module needn't even be part of the SDK; it could be a separate library.Unfortunately that didn't work. If an alternate definition of
isr_hardfaultis provided, it will indeed be called when a hard fault exception occurs. However, for the purposes of the logic inexception_is_compile_time_default()and similar, it will not be the default exception handler, which is important. The reason it won't be the default exception handler is because that must fall in the range__default_isrs_startto__default_isrs_end. As things stand, it isn't possible to provide an alternateisr_hardfaultthat falls in that range, despite the symbol being weak.Perhaps a better thing to do would be to rework things in crt0.s, exception.c & irq.c to add these new SDK functions:
This would need to be done without impacting the ability to replace weak handler symbols in crt0.s, since there is likely existing software that does that.
Then the debug exception handler could be built on top of that and it needn't be part of the SDK. It could go in pico-extras or a third party library. Actually, it would be awesome if it was in the boot ROM so that it worked regardless of whether flash RAM was accessible.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.