rust-embedded / cortex-m-rt

Minimal startup / runtime for Cortex-M microcontrollers
https://rust-embedded.github.io/cortex-m-rt/
Apache License 2.0
357 stars 85 forks source link

Fix unwinding through `Reset` #337

Closed jonas-schievink closed 2 years ago

jonas-schievink commented 2 years ago

Unwinders may detect the end of the program by seeing 0xFFFFFFFF in lr, which is why code to ensure that it has that value was added in https://github.com/rust-embedded/cortex-m-rt/pull/293. However, the bl main overwrites that value with the current program counter. This PR saves the old lr value on the stack, and adds debuginfo entries to allow an external unwinder to restore the value.

This fixes https://github.com/knurling-rs/probe-run/issues/277

rust-highfive commented 2 years ago

r? @therealprof

(rust-highfive has picked a reviewer for you, use r? to override)

jonathanpallant commented 2 years ago

Can confirm it resolves the upstream issue though:

PS C:\Users\Test\Documents\knurling\app-template> cargo run --bin hello
    Blocking waiting for file lock on build directory
   Compiling cortex-m-rt v0.7.0 (https://github.com/knurling-rs/cortex-m-rt.git?branch=fix-unwind-through-reset#9c88eab9)
   Compiling stm32f4xx-hal v0.10.1
   Compiling my_project v0.1.0 (C:\Users\Test\Documents\knurling\app-template)
    Finished dev [optimized + debuginfo] target(s) in 15.88s
     Running `probe-run --chip STM32F429ZITx target\thumbv7em-none-eabi\debug\hello`
(HOST) INFO  flashing program (7.93 KiB)
(HOST) INFO  success!
────────────────────────────────────────────────────────────────────────────────
Hello, world!
└─ hello::__cortex_m_rt_main @ src\bin\hello.rs:8
────────────────────────────────────────────────────────────────────────────────
(HOST) INFO  device halted without error
jonathanpallant commented 2 years ago

bors r+

bors[bot] commented 2 years ago

:lock: Permission denied

Existing reviewers: click here to make jonathanpallant a reviewer

jonathanpallant commented 2 years ago

Ugh. Wearing the wrong hat.

thejpster commented 2 years ago

bors r+

thejpster commented 2 years ago

^ have switched hats

bors[bot] commented 2 years ago

Build succeeded: