Crate esp_backtrace

Crate esp_backtrace 

Source
Expand description

This is a lightweight crate for obtaining backtraces on Espressif devices.

It provides an optional panic handler and supports a range of output options, all configurable through feature flags.

Please note that you need to force frame pointers (i.e. "-C", "force-frame-pointers", in your .cargo/config.toml). Otherwise the panic handler will emit a stack dump which needs tooling to decode it.

You can get an array of backtrace addresses (limited to 10 entries by default) via arch::backtrace() if you want to create a backtrace yourself (i.e. not using the panic handler).

§Features

  • println — Use esp-println

  • defmt — Use defmt

    Please note that defmt does not provide MSRV guarantees with releases, and as such we are not able to make any MSRV guarantees when this feature is enabled. For more information refer to the MSRV section of defmt’s README: https://github.com/knurling-rs/defmt?tab=readme-ov-file#msrv

  • colors (enabled by default) — Print messages in red

  • custom-halt — Invoke the extern function custom_halt() instead of doing a loop {} in case of a panic. This feature does not imply the halt-cores feature.

  • custom-pre-backtrace — Invoke the extern function custom_pre_backtrace() before handling a panic

  • halt-cores — Halt both CPUs on ESP32 / ESP32-S3 instead of doing a loop {} in case of a panic

  • semihosting — Exit with a semihosting call in case of a panic

  • panic-handler — Include a panic handler

§Additional configuration

We’ve exposed some configuration options that don’t fit into cargo features. These can be set via environment variables, or via cargo’s [env] section inside .cargo/config.toml. Below is a table of tunable parameters for this crate:

OptionStabilityDefault valueAllowed values

ESP_BACKTRACE_CONFIG_BACKTRACE_FRAMES

The maximum number of frames that will be printed in a backtrace.

⚠️ Unstable10

ESP_BACKTRACE_CONFIG_STACK_DUMP_MAX_SIZE

Max amount of stack to dump.

⚠️ Unstable8KOne of:
  • 4K
  • 8K
  • 16K
  • 32K

Structs§

Backtrace
BacktraceFrame