Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit f501d5a

Browse files
committed
Allow GDB to unwind HardFault callstacks
When I currently request GDB to dump a hard fault stack, I see something like this: (gdb) bt #0 UserHardFault_ (ef=0x10001fb8) at /depots/cortex-m-rt/src/lib.rs:537 #1 0x08003fe6 in HardFault () Backtrace stopped: previous frame identical to this frame (corrupt stack?) GDB can't unwind past HardFault since the current implementation of this function overwrites the Link Register (LR) value. This change pushes LR and R0 (to maintain 8-byte stack alignment) to the stack before transferring execution to UserHardFault(). After this change, I see a callstack like this from GDB: (gdb) bt #0 UserHardFault_ (ef=0x10001fb0) at /depots/cortex-m-rt/src/lib.rs:537 #1 0x08003fe8 in HardFault () #2 <signal handler called> #3 0x08002820 in core::ptr::read_volatile (src=0x48001800) at libcore/ptr.rs:472 #4 0x080001a2 in main () at src/07-registers/src/main.rs:14 Notes: * This code uses 8 more stack bytes. * Increases the size of the HardFault handler by 2 narrow instructions or 4 bytes. This could be decreased to 2 bytes by removing the pop since UserHardFault() doesn't currently return but it just looks too odd for me to do as an initial attempt.
1 parent 6c4689d commit f501d5a

File tree

5 files changed

+2
-0
lines changed

5 files changed

+2
-0
lines changed

asm.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
.global HardFault
33
.thumb_func
44
HardFault:
5+
push {r0, lr}
56
mrs r0, MSP
67
bl UserHardFault
8+
pop {r0, pc}

bin/thumbv6m-none-eabi.a

34 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi.a

34 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf.a

34 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi.a

34 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)