Skip to content

Commit

Permalink
Merge branch 'main' into fix/flash-26mhz
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez authored Feb 15, 2024
2 parents dd4b6fb + 9592c92 commit 8076852
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `espflash` will now exit with an error if `defmt` is selected but not usable (#524)
- Unify configuration methods (#551)
- MSRV bumped to `1.73.0` (#578)
- Improved symbol resolving (#581)
- Update ESP32 and ESP32-C2 stubs (#584)

### Removed
Expand Down
21 changes: 14 additions & 7 deletions espflash/src/cli/monitor/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ fn resolve_addresses(
let name = symbols.get_name(addr);
let location = symbols.get_location(addr);

let name = name.as_deref().unwrap_or("??");
let output = if let Some((file, line_num)) = location {
format!("{matched} - {name}\r\n at {file}:{line_num}\r\n")
} else {
format!("{matched} - {name}\r\n at ??:??\r\n")
};
if let Some(name) = name {
let output = if line.trim() == format!("0x{:x}", addr) {
if let Some((file, line_num)) = location {
format!("{name}\r\n at {file}:{line_num}\r\n")
} else {
format!("{name}\r\n at ??:??\r\n")
}
} else if let Some((file, line_num)) = location {
format!("{matched} - {name}\r\n at {file}:{line_num}\r\n")
} else {
format!("{matched} - {name}\r\n at ??:??\r\n")
};

out.queue(PrintStyledContent(output.with(Color::Yellow)))?;
out.queue(PrintStyledContent(output.with(Color::Yellow)))?;
}
}

Ok(())
Expand Down
17 changes: 12 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},
object::{read::File, Object, ObjectSegment},
Context, LookupResult,
};

Expand All @@ -23,6 +23,13 @@ impl<'sym> Symbols<'sym> {

/// Returns the name of the function at the given address, if one can be found.
pub fn get_name(&self, addr: u64) -> Option<String> {
// no need to try an address not contained in any segment
if !self.file.segments().any(|segment| {
(segment.address()..(segment.address() + segment.size())).contains(&addr)
}) {
return None;
}

// The basic steps here are:
// 1. find which frame `addr` is in
// 2. look up and demangle the function name
Expand All @@ -44,10 +51,10 @@ 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| sym.name().to_string())
self.file.symbol_map().get(addr).map(|sym| {
addr2line::demangle_auto(std::borrow::Cow::Borrowed(sym.name()), None)
.to_string()
})
})
}

Expand Down

0 comments on commit 8076852

Please sign in to comment.