Accessing Panic Information

Hello,

From my previous discussion in this section " Panic handler in no_std for Aurix µC"

I now encountered a string that tells what my info in panic holds, like the file name, line number which caused the issue and the message it carries, which is all stored in an memorý block. Now, in an production, this message is too memory costly to analyse and debug what caused. Like in Autosar environment where we have these enums for DTC's, is there any way to make panic handler provide enum values and then you map them to your table which actually holds these information for the codes.

If you see here, at address 0x800004E8 (length 10 bytes) I have the file information (src/lib.rs) and other information which follows that, what I want to achieve is, instead of string some enum values, so that I can write to NVM block to read it after reset.

Thanks for the help.

Best Regards

Rustc doesn't have any string interning support for panic messages. Panic handlers always accept a core::fmt::Arguments value as panic message which is guaranteed to be formatable at runtime without needing any metadata section that could be omitted from the executable.

Something that may work for your use case would be using the defmt crate and then using defmt::panic!() for panicking instead of core::panic!() and using #[defmt::panic_handler] to define your panic handler. The purpose of defmt is to allow string interning and do the formatting of the final log message on the host rather than the microcontroller. You can have your defmt logger implementation write to the NVM.