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:
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// CRASH BREADCRUMBS — context that survives a panic reboot (F-070)
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// The coredump summary (see Telemetry::captureCrashReport) only knows the CPU
|
||||
// state at the moment the chip went down. For an abort() — unhandled C++
|
||||
// exception, failed assert, FreeRTOS stack-overflow check — that state is
|
||||
// panic_abort()'s own deliberate write to address 0, so PC/cause/vaddr say
|
||||
// nothing about *why* (see F-055). Two things fill that gap, both kept in
|
||||
// RTC_NOINIT memory, which survives software/panic/watchdog resets but NOT
|
||||
// power-on or brownout:
|
||||
//
|
||||
// 1. The abort reason string — captured by wrapping esp_system_abort() at
|
||||
// link time (-Wl,--wrap=esp_system_abort in platformio.ini). Every abort
|
||||
// path in this SDK funnels through it: abort() ("abort() was called at PC
|
||||
// 0x... on core N" — that PC is abort()'s caller), assert ("assert failed:
|
||||
// func file:line (expr)"), and the FreeRTOS stack-overflow hook.
|
||||
// 2. A heap/uptime snapshot refreshed every second by TelemetryTask — the
|
||||
// last known state right before the reset (fragmentation killed us once).
|
||||
//
|
||||
// Both are consumed once at boot and cleared, so they're reported exactly once.
|
||||
|
||||
struct PreCrashSnapshot {
|
||||
bool available = false;
|
||||
uint32_t uptimeMs = 0; // millis() at the last snapshot before the reset
|
||||
uint32_t freeHeap = 0; // free heap at that snapshot
|
||||
uint32_t largestBlock = 0; // largest allocatable block at that snapshot
|
||||
uint32_t minFreeHeap = 0; // lowest free heap ever seen during that boot
|
||||
char abortMsg[160] = {0}; // empty unless the reset came from esp_system_abort()
|
||||
};
|
||||
|
||||
namespace CrashBreadcrumbs {
|
||||
// Refresh the heap/uptime snapshot. Cheap; called from TelemetryTask every 1s.
|
||||
void updateSnapshot();
|
||||
|
||||
// Read whatever the previous boot left behind, then clear it. Call once,
|
||||
// early in boot, and only trust the result on a fault-class reset — RTC
|
||||
// memory is garbage after a power-on, which the magic check guards against.
|
||||
PreCrashSnapshot consume();
|
||||
}
|
||||
Reference in New Issue
Block a user