Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up defmt-print #758

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- [#756] Switch from bors to merge queue
- [#753]: Add `defmt::Format` impls for `core::ptr::NonNull` and `fn(Args...) -> Ret` (up to 12 arguments)
- [#757]: `defmt-print`: Allow reading from a tcp port.
- [#758]: `defmt-print`: Tidy up
- [#757]: `defmt-print`: Allow reading from a tcp port
- [#756]: `CI`: Switch from bors to merge queue
- [#753]: `demft` Add `Format` impls for `core::ptr::NonNull` and `fn(Args...) -> Ret` (up to 12 arguments)

[#758]: https://github.com/knurling-rs/defmt/pull/758
[#757]: https://github.com/knurling-rs/defmt/pull/757
[#756]: https://github.com/knurling-rs/defmt/pull/756
[#753]: https://github.com/knurling-rs/defmt/pull/753
[#757]: https://github.com/knurling-rs/defmt/pull/757


## [v0.3.5] - 2023-05-05
Expand Down
14 changes: 5 additions & 9 deletions print/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ fn main() -> anyhow::Result<()> {
true => true, // We display *all* frames.
});

// read and parse elf file
let bytes = fs::read(elf.unwrap())?;

let table = Table::parse(&bytes)?.ok_or_else(|| anyhow!(".defmt data not found"))?;
let locs = table.get_locations(&bytes)?;

// check if the locations info contains all the indicies
let locs = if table.indices().all(|idx| locs.contains_key(&(idx as u64))) {
Some(locs)
} else {
Expand All @@ -109,12 +110,10 @@ fn main() -> anyhow::Result<()> {

let mut buf = [0; READ_BUFFER_SIZE];
let mut stream_decoder = table.new_stream_decoder();

let current_dir = env::current_dir()?;

let mut source = match command {
None => Source::stdin(),
Some(Command::Stdin) => Source::stdin(),
None | Some(Command::Stdin) => Source::stdin(),
Some(Command::Tcp { host, port }) => Source::tcp(host, port)?,
};

Expand Down Expand Up @@ -183,10 +182,7 @@ fn location_info(locs: &Option<Locations>, frame: &Frame, current_dir: &Path) ->
#[allow(clippy::unnecessary_wraps)]
fn print_version() -> anyhow::Result<()> {
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
println!(
"supported defmt version{}: {}",
if DEFMT_VERSIONS.len() > 1 { "s" } else { "" },
DEFMT_VERSIONS.join(", ")
);
let s = if DEFMT_VERSIONS.len() > 1 { "s" } else { "" };
println!("supported defmt version{s}: {}", DEFMT_VERSIONS.join(", "));
Ok(())
}