DeterministicESPAsyncWebServer
v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
exc_decoder.h
Go to the documentation of this file.
1
// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2
// SPDX-License-Identifier: AGPL-3.0-or-later
3
4
/**
5
* @file exc_decoder.h
6
* @brief ESP32 panic / exception decoder for a live diagnostics panel (DETWS_ENABLE_EXC_DECODER).
7
*
8
* When an ESP32 panics it prints a Guru Meditation dump: a cause ("LoadProhibited"), a per-core register
9
* dump (PC, EXCVADDR, ...), and a backtrace of `PC:SP` frame pairs. To resolve those PCs to file:line an
10
* addr2line-style panel needs the firmware ELF, which lives off-device - so the on-device job is to
11
* *extract and present* the raw decode: the cause, the faulting PC + data address, and the ordered
12
* backtrace PC list, served as JSON for a live "/exception" panel (the browser or a build server then
13
* resolves symbols). This is that extractor.
14
*
15
* It parses the panic text an app captures (from the console, a saved crash line, or a text rendering of
16
* the core-dump partition) into a structured ExcInfo, and serializes it. Pure, zero heap, no stdlib
17
* (hand-rolled hex/decimal parsing), host-testable against a captured panic string.
18
*/
19
20
#ifndef DETERMINISTICESPASYNCWEBSERVER_EXC_DECODER_H
21
#define DETERMINISTICESPASYNCWEBSERVER_EXC_DECODER_H
22
23
#include "
ServerConfig.h
"
24
#include <stddef.h>
25
#include <stdint.h>
26
27
#if DETWS_ENABLE_EXC_DECODER
28
29
#ifndef DETWS_EXC_MAX_FRAMES
30
#define DETWS_EXC_MAX_FRAMES 32
///< backtrace frames retained (Xtensa panics rarely exceed this).
31
#endif
32
33
/** @brief One backtrace frame: a program counter and its stack pointer. */
34
struct
ExcFrame
35
{
36
uint32_t pc;
37
uint32_t sp;
38
};
39
40
/** @brief A decoded panic. Fields not found in the input are left at their zeroed / -1 defaults. */
41
struct
ExcInfo
42
{
43
int
core;
///< panicking core number, or -1 if not present.
44
char
cause[32];
///< exception cause text (e.g. "LoadProhibited"), "" if absent.
45
uint32_t pc;
///< faulting PC (register-dump PC, else first backtrace frame).
46
uint32_t excvaddr;
///< faulting data address (EXCVADDR), 0 if absent.
47
bool
has_excvaddr;
///< true if an EXCVADDR field was present.
48
ExcFrame frames[DETWS_EXC_MAX_FRAMES];
///< backtrace, outermost-first as printed.
49
size_t
frame_count;
50
};
51
52
/**
53
* @brief Parse an ESP32 panic dump into @p out.
54
*
55
* Recognizes the Guru Meditation cause, the core number, the register-dump PC + EXCVADDR, and the
56
* `Backtrace: pc:sp pc:sp ...` frame list. Tolerant of missing fields and of a trailing "|<-CORRUPTED".
57
* @return true if at least one of {cause, pc, a backtrace frame} was found.
58
*/
59
bool
detws_exc_parse(
const
char
*text, ExcInfo *out);
60
61
/**
62
* @brief Serialize a decoded panic as
63
* `{"core":N,"cause":"..","pc":"0x..","excvaddr":"0x..","backtrace":["0x..",...]}`.
64
* `core` is omitted when -1; `excvaddr` is omitted when absent.
65
* @return length written (excl NUL), or 0 on overflow / bad args.
66
*/
67
size_t
detws_exc_json(
const
ExcInfo *info,
char
*out,
size_t
cap);
68
69
#endif
// DETWS_ENABLE_EXC_DECODER
70
#endif
// DETERMINISTICESPASYNCWEBSERVER_EXC_DECODER_H
ServerConfig.h
User-facing configuration for DeterministicESPAsyncWebServer.
src
services
exc_decoder
exc_decoder.h
Generated by
1.9.8