Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Handle reset vector not pointing to ELF symbol
Browse files Browse the repository at this point in the history
Closes #391
  • Loading branch information
jannic committed May 2, 2023
1 parent b57e3a6 commit e404395
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]

- [#399] Update link shown in error message
- [#398] Handle reset vector not pointing to ELF symbol

[#399]: https://github.com/knurling-rs/probe-run/pull/399
[#398]: https://github.com/knurling-rs/probe-run/pull/398

## [v0.3.8] - 2023-04-12

Expand Down
7 changes: 5 additions & 2 deletions src/backtrace/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ pub fn target(core: &mut Core, elf: &Elf, target_info: &TargetInfo) -> Output {
// If the frame didn't move, and the program counter didn't change, bail out
// (otherwise we might print the same frame over and over).
if !cfa_changed && !program_counter_changed {
// If we do not end up in the reset function the stack is corrupted
output.corrupted = !elf.reset_fn_range().contains(&pc);
// If we do not end up in the reset function the stack is corrupted.
// If reset_fn_range is empty, we can't detect this and just assume that
// the stack was not corrupted.
let reset_fn_range = elf.reset_fn_range();
output.corrupted = !(reset_fn_range.contains(&pc) || reset_fn_range.is_empty());
break;
}

Expand Down
17 changes: 10 additions & 7 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,16 @@ fn extract_symbols(elf: &ObjectFile, reset_fn_address: u32) -> anyhow::Result<Sy

let main_fn_address = main_fn_address.ok_or(anyhow!("`main` symbol not found"))?;
let reset_fn_range = {
let reset = match reset_symbols.len() {
1 => reset_symbols.remove(0),
_ => bail!("unable to determine reset handler"),
};
let addr = reset.address().try_into().expect("expected 32-bit ELF");
let size: u32 = reset.size().try_into().expect("expected 32-bit ELF");
addr..addr + size
if reset_symbols.len() == 1 {
let reset = reset_symbols.remove(0);
let addr = reset.address().try_into().expect("expected 32-bit ELF");
let size: u32 = reset.size().try_into().expect("expected 32-bit ELF");
addr..addr + size
} else {
log::debug!("unable to determine reset handler");
// The length of the reset handler is not known as it's not part of the ELF file
reset_fn_address..reset_fn_address
}
};

Ok(Symbols {
Expand Down

0 comments on commit e404395

Please sign in to comment.