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:
@@ -82,6 +82,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
|
||||
| F-067 | Specific `playback.play` / `playback.stop` ACK messages (busy, invalid params, not found, load failed, bells disabled, overload…) instead of a generic "Playback command failed"; `url` no longer sticky | v2.3.0 | Stable |
|
||||
| F-068 | `loading` playback state while a melody downloads (MQTT `status/playback`), cancellable by `playback.stop`; `playback_failed` event on `control/reports` when an ACKed play never starts | v2.3.0 | Stable |
|
||||
| F-069 | RF remote disabled on Vesper Standard builds (`HAS_RF=0`) — no fielded unit has a receiver; `rf.*` now only on agnus | v2.3.0 | Stable |
|
||||
| F-070 | Richer crash reports — coredump backtrace + ELF SHA, abort() reason string, and last pre-crash heap/uptime snapshot in `boot_report` and the SD boot log | v2.3.0 | Stable |
|
||||
|
||||
---
|
||||
|
||||
@@ -1358,3 +1359,66 @@ build. Agnus keeps RF. `status/playback` `source: "rf"` can therefore only appea
|
||||
Verified: `pio run -e vesper-std-v1` builds clean.
|
||||
|
||||
Subsystem: `variants/vesper-std.hpp`
|
||||
|
||||
---
|
||||
|
||||
### F-070 — Richer crash reports: backtrace, abort reason, pre-crash snapshot
|
||||
|
||||
**Why.** Crashes kept arriving on the console as `task async_tcp, PC 0x40083ed5, cause 29, vaddr 0x0`.
|
||||
That PC is `panic_abort()` (IDF `panic.c:408`), which *deliberately* writes to address 0 to halt the
|
||||
chip, so every `abort()` looks identical no matter what caused it (see F-055's note on this). The
|
||||
actual reason, and the call chain that led to it, were only ever on the serial port.
|
||||
|
||||
**What's added.**
|
||||
|
||||
1. **Backtrace + ELF SHA from the coredump** (`Telemetry::captureCrashReport()`). The coredump summary
|
||||
already carried `exc_bt_info` (up to 16 PCs) and the crashing app's ELF SHA-256 prefix; they're now
|
||||
read and reported. For an `abort()` the first 2–4 frames are the abort machinery (`panic_abort`,
|
||||
`esp_system_abort`, `abort`, `std::terminate`…); the frames after that are the real call site.
|
||||
Also logged at boot in the same `0x… 0x…` format as the serial panic output, ready for `addr2line`.
|
||||
2. **Abort reason string** (`src/Telemetry/CrashBreadcrumbs.cpp`). `platformio.ini` links with
|
||||
`-Wl,--wrap=esp_system_abort`, so every abort path in this SDK (`abort()`, `assert`, `configASSERT`,
|
||||
the FreeRTOS stack-overflow hook, stack-smashing protection) passes through
|
||||
`__wrap_esp_system_abort()` first. It copies the message (≤159 chars) into `RTC_NOINIT` memory and
|
||||
hands off to the real function. Typical values: `abort() was called at PC 0x400d1234 on core 0`
|
||||
(that PC is `abort()`'s caller; decode it), `assert failed: tcp_update_rcv_ann_wnd tcp.c:951 (...)`,
|
||||
`***ERROR*** A stack overflow in task async_tcp has been detected.` The wrapper is IRAM-only, copies
|
||||
bytes by hand, and takes no locks, since it can run with the heap lock held or the cache disabled.
|
||||
3. **Pre-crash snapshot.** TelemetryTask writes `millis()`, free heap, largest free block and the
|
||||
boot's minimum-ever free heap into the same RTC block every second, regardless of the OTA pause
|
||||
flag. Enough to tell "heap exhaustion again" (F-055) apart from a genuine bug.
|
||||
|
||||
RTC memory survives panic/watchdog/software resets but not power-on or brownout; magic words guard
|
||||
against garbage. `CrashBreadcrumbs::consume()` runs once in `Telemetry::begin()` and clears the block;
|
||||
the result is kept only when `isFaultReset()`, so a clean reboot/OTA never reports the previous boot's
|
||||
snapshot.
|
||||
|
||||
**Where it shows up.** MQTT `boot_report` (`system/info`) and each SD boot-log entry
|
||||
(`telemetry.get_boot_history`), same shape in both, built by `Telemetry::writeCrashJson()` /
|
||||
`writePreCrashJson()`:
|
||||
|
||||
```json
|
||||
"crash": {
|
||||
"task": "async_tcp", "pc": 1074282197, "exc_cause": 29, "exc_vaddr": 0,
|
||||
"backtrace": [1074282194, 1074340312, 1074348122, 1074606712],
|
||||
"backtrace_corrupted": false,
|
||||
"elf_sha256": "3f9a1c0be7d2a441"
|
||||
},
|
||||
"pre_crash": {
|
||||
"uptime_ms": 5412000, "free_heap": 21480, "largest_block": 9716, "min_free_heap": 18112,
|
||||
"abort_msg": "abort() was called at PC 0x400d8a3f on core 0"
|
||||
}
|
||||
```
|
||||
|
||||
All new `crash` keys are additive. `pre_crash` is independent of `crash`: it can appear without a
|
||||
coredump (e.g. a task-watchdog reset whose dump failed), and `abort_msg` is omitted when the reset
|
||||
wasn't an abort (a real hardware exception, a watchdog).
|
||||
|
||||
**Decoding.** `elf_sha256` is the first 16 hex chars of the SHA-256 of the crashing build's
|
||||
`firmware.elf`. Keep each release's `.elf`: `xtensa-esp32-elf-addr2line -pfiaC -e firmware.elf <pc> <backtrace...> <PC from abort_msg>`.
|
||||
|
||||
Verified: `pio run -e vesper-std-v1`, `-e agnus-v1` and `-e bespoke-rs485-v1` build clean; `objdump`
|
||||
confirms `abort()` now calls `__wrap_esp_system_abort` (IRAM) and the breadcrumb block lives in RTC slow
|
||||
memory (`0x5000xxxx`). Not yet exercised with a deliberate crash on hardware.
|
||||
|
||||
Subsystem: `src/Telemetry/CrashBreadcrumbs.hpp`, `src/Telemetry/CrashBreadcrumbs.cpp`, `src/Telemetry/Telemetry.hpp`, `src/Telemetry/Telemetry.cpp`, `src/Communication/CommunicationRouter/CommunicationRouter.cpp`, `platformio.ini`
|
||||
|
||||
@@ -284,12 +284,23 @@ Published once, the first time MQTT connects after boot (guarded, not repeated o
|
||||
"reset_reason": "PANIC",
|
||||
"is_fault": true,
|
||||
"free_heap": 187234,
|
||||
"crash": { "task": "TelemetryTask", "pc": 1074111832, "exc_cause": 1, "exc_vaddr": 0 }
|
||||
"crash": {
|
||||
"task": "async_tcp", "pc": 1074282197, "exc_cause": 29, "exc_vaddr": 0,
|
||||
"backtrace": [1074282194, 1074340312, 1074348122, 1074606712],
|
||||
"backtrace_corrupted": false,
|
||||
"elf_sha256": "3f9a1c0be7d2a441"
|
||||
},
|
||||
"pre_crash": {
|
||||
"uptime_ms": 5412000, "free_heap": 21480, "largest_block": 9716, "min_free_heap": 18112,
|
||||
"abort_msg": "abort() was called at PC 0x400d8a3f on core 0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`crash` is present only when a coredump was found for the crash that caused this boot — omitted on a clean/expected reset or a fault reset with no coredump (e.g. brownout). A fault-class reset additionally publishes a `system/alerts` WARNING (see above) — `system/info`'s `boot_report` is published unconditionally, fault or not.
|
||||
`crash` is present only when a coredump was found for the crash that caused this boot — omitted on a clean/expected reset or a fault reset with no coredump (e.g. brownout). `backtrace` (up to 16 PCs, decimal) and `elf_sha256` (first 16 hex chars of the crashing build's ELF SHA-256) identify the call chain; decode with `addr2line` against that exact `.elf`.
|
||||
|
||||
`pre_crash` (F-070) is present only on a fault reset where RTC memory survived (not power-on/brownout): the last once-per-second heap/uptime snapshot before the reset, plus `abort_msg` when the reset came from `abort()`/`assert`/a stack-overflow check. For those resets `pc`/`exc_cause 29`/`exc_vaddr 0` are the abort mechanism itself; `abort_msg` and the later `backtrace` frames are the real cause. A fault-class reset additionally publishes a `system/alerts` WARNING (see above) — `system/info`'s `boot_report` is published unconditionally, fault or not.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user