File tree Expand file tree Collapse file tree 3 files changed +27
-12
lines changed Expand file tree Collapse file tree 3 files changed +27
-12
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
41
41
- ` espflash ` will now exit with an error if ` defmt ` is selected but not usable (#524 )
42
42
- Unify configuration methods (#551 )
43
43
- MSRV bumped to ` 1.73.0 ` (#578 )
44
+ - Improved symbol resolving (#581 )
44
45
45
46
### Removed
46
47
Original file line number Diff line number Diff line change @@ -38,14 +38,21 @@ fn resolve_addresses(
38
38
let name = symbols. get_name ( addr) ;
39
39
let location = symbols. get_location ( addr) ;
40
40
41
- let name = name. as_deref ( ) . unwrap_or ( "??" ) ;
42
- let output = if let Some ( ( file, line_num) ) = location {
43
- format ! ( "{matched} - {name}\r \n at {file}:{line_num}\r \n " )
44
- } else {
45
- format ! ( "{matched} - {name}\r \n at ??:??\r \n " )
46
- } ;
41
+ if let Some ( name) = name {
42
+ let output = if line. trim ( ) == format ! ( "0x{:x}" , addr) {
43
+ if let Some ( ( file, line_num) ) = location {
44
+ format ! ( "{name}\r \n at {file}:{line_num}\r \n " )
45
+ } else {
46
+ format ! ( "{name}\r \n at ??:??\r \n " )
47
+ }
48
+ } else if let Some ( ( file, line_num) ) = location {
49
+ format ! ( "{matched} - {name}\r \n at {file}:{line_num}\r \n " )
50
+ } else {
51
+ format ! ( "{matched} - {name}\r \n at ??:??\r \n " )
52
+ } ;
47
53
48
- out. queue ( PrintStyledContent ( output. with ( Color :: Yellow ) ) ) ?;
54
+ out. queue ( PrintStyledContent ( output. with ( Color :: Yellow ) ) ) ?;
55
+ }
49
56
}
50
57
51
58
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::error::Error;
2
2
3
3
use addr2line:: {
4
4
gimli:: { EndianRcSlice , RunTimeEndian } ,
5
- object:: { read:: File , Object } ,
5
+ object:: { read:: File , Object , ObjectSegment } ,
6
6
Context , LookupResult ,
7
7
} ;
8
8
@@ -23,6 +23,13 @@ impl<'sym> Symbols<'sym> {
23
23
24
24
/// Returns the name of the function at the given address, if one can be found.
25
25
pub fn get_name ( & self , addr : u64 ) -> Option < String > {
26
+ // no need to try an address not contained in any segment
27
+ if !self . file . segments ( ) . any ( |segment| {
28
+ ( segment. address ( ) ..( segment. address ( ) + segment. size ( ) ) ) . contains ( & addr)
29
+ } ) {
30
+ return None ;
31
+ }
32
+
26
33
// The basic steps here are:
27
34
// 1. find which frame `addr` is in
28
35
// 2. look up and demangle the function name
@@ -44,10 +51,10 @@ impl<'sym> Symbols<'sym> {
44
51
. and_then ( |name| name. demangle ( ) . map ( |s| s. into_owned ( ) ) . ok ( ) )
45
52
} )
46
53
. or_else ( || {
47
- self . file
48
- . symbol_map ( )
49
- . get ( addr )
50
- . map ( |sym| sym . name ( ) . to_string ( ) )
54
+ self . file . symbol_map ( ) . get ( addr ) . map ( |sym| {
55
+ addr2line :: demangle_auto ( std :: borrow :: Cow :: Borrowed ( sym . name ( ) ) , None )
56
+ . to_string ( )
57
+ } )
51
58
} )
52
59
}
53
60
You can’t perform that action at this time.
0 commit comments