Add ability to call user function from panic #256
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#256
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Panics are, of course, fatal errors, so it makes sense to halt the processor, but a lot of the time, panics are unexpected when they happen (They should get caught or prevented before actual deployment, but things always have a way of going not as planned) and leave the pico in an undefined state. Since the pico does not shut down and stays in the state it was before the panic, it can be useful to reset the pico's outputs or provide other functionality to safely enter the panicked state.
I have little expertise with C and all its linker magic/tools, but I was envisioning a feature much like the
#[panic_handler]attribute of rust that would be called in place of the provided panic function.If achieving this with a macro or some linker tomfoolery is not feasible or elegant, it could also be possible to let the user provide a function pointer that will be called first thing the panic function is entered. Something like:
yup, we should implement this... it's been on my list for a while, but not quite made it!
I actually had this same thought, but I was thinking it would be easiest to make the panic handler just be a
__weak(or__attribute__((weak))) declaration.That way the user can implement their own panic function that doesn't even do any of the usual panic code, which would be desirable for some.
Right now we only support gcc but with a mind to the use of clang, can someone confirm whether weak works with arm-none-eabi clang? I seem to recall trying it in the past, and it not working, but i don't quite remember.
Note also, there should be a trivial way to add a breakpoint at the start of the function via the build which is more useful when debugging
merged