Skip to content

Commit 8353080

Browse files
authored
Improve resolving non-code addresses (#603)
* Improve resolving non-code addresses * CHANGELOG.md entry
1 parent 39e9611 commit 8353080

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

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

1718
### Changed
1819
- Non-linux-musl: Only list the available USB Ports by default (#590)

espflash/src/cli/monitor/symbols.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22

33
use addr2line::{
44
gimli::{EndianRcSlice, RunTimeEndian},
5-
object::{read::File, Object, ObjectSegment},
5+
object::{read::File, Object, ObjectSegment, ObjectSymbol},
66
Context, LookupResult,
77
};
88

@@ -51,10 +51,22 @@ impl<'sym> Symbols<'sym> {
5151
.and_then(|name| name.demangle().map(|s| s.into_owned()).ok())
5252
})
5353
.or_else(|| {
54-
self.file.symbol_map().get(addr).map(|sym| {
55-
addr2line::demangle_auto(std::borrow::Cow::Borrowed(sym.name()), None)
56-
.to_string()
57-
})
54+
// Don't use `symbol_map().get(addr)` - it's documentation says "Get the symbol before the given address." which might be totally wrong
55+
let symbol = self.file.symbols().find(|symbol| {
56+
(symbol.address()..=(symbol.address() + symbol.size())).contains(&addr)
57+
});
58+
59+
if let Some(symbol) = symbol {
60+
match symbol.name() {
61+
Ok(name) if !name.is_empty() => Some(
62+
addr2line::demangle_auto(std::borrow::Cow::Borrowed(name), None)
63+
.to_string(),
64+
),
65+
_ => None,
66+
}
67+
} else {
68+
None
69+
}
5870
})
5971
}
6072

0 commit comments

Comments
 (0)