Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#845]: `decoder`: fix println!() records being printed with formatting
- [#843]: `defmt`: Sort IDs of log msgs by severity to allow runtime filtering by severity
- [#822]: `CI`: Run `cargo semver-checks` on every PR
- [#856]: `defmt`: Add a `Format` impl for `PanicInfo` and related types.

[#859]: https://github.com/knurling-rs/defmt/pull/859
[#858]: https://github.com/knurling-rs/defmt/pull/858
Expand All @@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#845]: https://github.com/knurling-rs/defmt/pull/845
[#843]: https://github.com/knurling-rs/defmt/pull/843
[#822]: https://github.com/knurling-rs/defmt/pull/822
[#856]: https://github.com/knurling-rs/defmt/pull/856

## [v0.3.8] - 2024-05-17

Expand Down
1 change: 1 addition & 0 deletions defmt/src/impls/core_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod cell;
mod net;
mod num;
mod ops;
mod panic;
mod ptr;
mod slice;

Expand Down
27 changes: 27 additions & 0 deletions defmt/src/impls/core_/panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use core::panic;

use super::*;

impl<'a> Format for panic::PanicInfo<'a> {
fn format(&self, f: Formatter) {
if let Some(location) = self.location() {
crate::write!(f, "panicked at {}", location);
} else {
crate::write!(f, "panicked");
}
// TODO: consider supporting self.message() once stabilized, or add a crate feature for
// conditional support
}
}

impl<'a> Format for panic::Location<'a> {
fn format(&self, f: Formatter) {
crate::write!(
f,
"{=str}:{=u32}:{=u32}",
self.file(),
self.line(),
self.column()
);
}
}
1 change: 1 addition & 0 deletions firmware/qemu/src/bin/panic_info.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INFO PanicInfo: panicked at qemu/src/bin/panic_info.rs:14:5
23 changes: 23 additions & 0 deletions firmware/qemu/src/bin/panic_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_std]
#![no_main]

use core::panic;
use cortex_m_semihosting::debug;

use defmt_semihosting as _; // global logger

#[cortex_m_rt::entry]
fn main() -> ! {
// Note: this test is a bit brittle in that the line/column number of the following panic is
// included in the test snapshot. Hence, be mindful to update the snapshot if you want to
// add any additional code to this file above the following line!
panic!("aaah!")
}

#[panic_handler]
fn panic(panic_info: &panic::PanicInfo) -> ! {
defmt::info!("PanicInfo: {=?}", panic_info);
loop {
debug::exit(debug::EXIT_SUCCESS)
}
}
1 change: 1 addition & 0 deletions xtask/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub(crate) fn all_snapshot_tests() -> Vec<&'static str> {
"hints_inner",
"dbg",
"net",
"panic_info",
];
const NIGHTLY_SNAPSHOT_TESTS: &[&str] = &["alloc"];

Expand Down