feat(Telemetry): backtrace, abort reason and pre-crash snapshot in crash reports (F-070)

Crash reports only carried the coredump's PC/cause/vaddr, which for every
abort() is panic_abort()'s own write to 0x0 - so all aborts looked the same.

- Read the coredump backtrace (up to 16 PCs) and crashing ELF SHA prefix
- Wrap esp_system_abort (-Wl,--wrap) to keep the abort/assert/stack-overflow
  message in RTC_NOINIT memory across the reboot
- TelemetryTask snapshots uptime/free heap/largest block/min free heap into
  the same RTC block every second
- Reported in MQTT boot_report and SD boot log as crash.backtrace,
  crash.elf_sha256 and a new pre_crash object (additive)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 16:08:34 +03:00
co-authored by Claude Opus 5.5
parent bf4a04d6f4
commit 09f562cf1d
8 changed files with 217 additions and 8 deletions
+18
View File
@@ -66,6 +66,7 @@
// panic handler automatically on every crash (already enabled in this project's SDK
// build; no custom panic hook needed). See CrashReport below.
#include <esp_core_dump.h>
#include "CrashBreadcrumbs.hpp"
// Most recent crash's coredump summary, captured once at begin() and erased from
// flash immediately after reading so it's reported exactly once. Empty/zeroed
@@ -77,6 +78,13 @@ struct CrashReport {
uint32_t pc = 0; // Program counter at exception
uint32_t excCause = 0; // Xtensa exception cause code
uint32_t excVaddr = 0; // Faulting virtual address
// F-070: backtrace of the faulting task (decode with addr2line against the
// ELF whose SHA matches elfSha). For an abort() the first frames are the
// abort machinery; the real call site follows.
uint32_t backtrace[16] = {0};
uint8_t backtraceDepth = 0;
bool backtraceCorrupted = false;
char elfSha[APP_ELF_SHA256_SZ] = {0}; // first 16 hex chars of the crashing app's ELF SHA-256
};
// Maximum number of boot log entries retained on SD (rotating)
@@ -154,6 +162,10 @@ private:
// Most recent crash's coredump summary, if any — read once at begin().
CrashReport crashReport;
// Abort reason + last heap/uptime snapshot from before a fault reset, if
// the previous boot left them in RTC memory (F-070). See CrashBreadcrumbs.hpp.
PreCrashSnapshot preCrash;
// Diagnostics — CPU temperature sampled locally every 15s, reduced to
// min/max/avg between 5-minute batch reports. See RunningStats above for
// why only temperature needs local sampling (stack high-water and the
@@ -235,6 +247,12 @@ public:
// if one was captured. available == false when the last reset wasn't a crash,
// or no coredump was found for one that was.
const CrashReport& getCrashReport() const { return crashReport; }
const PreCrashSnapshot& getPreCrashSnapshot() const { return preCrash; }
// Serialize the above into the shared JSON shape used by the MQTT
// boot_report and the SD boot log. Callers check .available first.
void writeCrashJson(JsonObject out) const;
void writePreCrashJson(JsonObject out) const;
// Reset reason (captured once at begin(), before anything else can crash again)
esp_reset_reason_t getResetReason() const { return resetReason; }