Skip to content

Commit

Permalink
Merge rtic-rs#131
Browse files Browse the repository at this point in the history
131: Allow GDB to unwind HardFault callstacks r=therealprof a=adamgreen

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
rtic-rs#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
rtic-rs#1  0x08003fe8 in HardFault ()
rtic-rs#2  <signal handler called>
rtic-rs#3  0x08002820 in core::ptr::read_volatile (src=0x48001800) at libcore/ptr.rs:472
rtic-rs#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.

Co-authored-by: Adam Green <adamgreen@users.noreply.github.com>
  • Loading branch information
bors[bot] and adamgreen committed Oct 23, 2018
2 parents 6c4689d + f501d5a commit a531ee2
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions asm.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
.global HardFault
.thumb_func
HardFault:
push {r0, lr}
mrs r0, MSP
bl UserHardFault
pop {r0, pc}
Binary file modified bin/thumbv6m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi.a
Binary file not shown.

0 comments on commit a531ee2

Please sign in to comment.