Skip to content

Commit

Permalink
Improve resolving non-code addresses (#603)
Browse files Browse the repository at this point in the history
* Improve resolving non-code addresses

* CHANGELOG.md entry
  • Loading branch information
bjoernQ committed Feb 26, 2024
1 parent 39e9611 commit 8353080
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Change the `hard_reset` sequence to fix Windows issues (#594)
- Improve resolving non-code addresses (#603)

### Changed
- Non-linux-musl: Only list the available USB Ports by default (#590)
Expand Down
22 changes: 17 additions & 5 deletions espflash/src/cli/monitor/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error::Error;

use addr2line::{
gimli::{EndianRcSlice, RunTimeEndian},
object::{read::File, Object, ObjectSegment},
object::{read::File, Object, ObjectSegment, ObjectSymbol},
Context, LookupResult,
};

Expand Down Expand Up @@ -51,10 +51,22 @@ impl<'sym> Symbols<'sym> {
.and_then(|name| name.demangle().map(|s| s.into_owned()).ok())
})
.or_else(|| {
self.file.symbol_map().get(addr).map(|sym| {
addr2line::demangle_auto(std::borrow::Cow::Borrowed(sym.name()), None)
.to_string()
})
// Don't use `symbol_map().get(addr)` - it's documentation says "Get the symbol before the given address." which might be totally wrong
let symbol = self.file.symbols().find(|symbol| {
(symbol.address()..=(symbol.address() + symbol.size())).contains(&addr)
});

if let Some(symbol) = symbol {
match symbol.name() {
Ok(name) if !name.is_empty() => Some(
addr2line::demangle_auto(std::borrow::Cow::Borrowed(name), None)
.to_string(),
),
_ => None,
}
} else {
None
}
})
}

Expand Down

0 comments on commit 8353080

Please sign in to comment.