Stack Trace Rt¶
| Spice | |
|---|---|
StackTraceBuffer struct¶
Fixed-capacity buffer holding one captured stack trace, as raw return addresses (most recent call first). Once the capacity above is hit, the walk stops early - deeper frames are silently dropped rather than overwriting the ones closest to the capture point, which are the most relevant for diagnostics.
Fields¶
| Name | Type | Description |
|---|---|---|
addresses |
byte*[STACK_TRACE_CAPACITY] |
|
count |
int |
Methods¶
capture¶
| Spice | |
|---|---|
Captures the stack trace of the calling function. The first recorded address is the calling function's own current instruction pointer (i.e. the return address capture() will resume at), not one of its parents' - so by default the trace starts exactly at the call site of capture() itself.
The chain's outermost frame is a sentinel, conventionally marked by a zeroed saved-frame-pointer field - but on at least one observed platform (macOS/AArch64) its return-address field reads zero too, one hop before the saved-frame-pointer field does. So termination is checked on the return-address value about to be recorded, not only on the frame pointer itself - a zero return address means this frame is (or already looks like) the sentinel, and the walk stops without recording it, rather than recording a bogus nil entry.
Parameters
| Name | Type | Description |
|---|---|---|
skipFrames |
int |
Number of additional frames to omit above the direct caller, for wrapper functions like sDumpStacktrace() that call capture() on a caller's behalf and want their own frame hidden. (default: 0) |
dump¶
| Spice | |
|---|---|
Prints every recorded frame of this trace to stderr, resolving each address to a symbol name via resolveSymbolName() where possible and falling back to a fixed placeholder otherwise (see stack_trace_symbol_rt.spice for why that is common for a Spice program's own frames today). A no-op if nothing was captured.
No offset from the symbol's own start address is printed alongside the name: Spice has no pointer<->integer cast and no pointer-difference operator today (only pointer +/- integer, which computes a new pointer, not a numeric difference), so there is currently no way to compute one in Spice itself.
Parameters
| Name | Type | Description |
|---|---|---|
includeAddresses |
bool |
Whether to print each frame's raw address alongside its resolved name. Defaults to true; pass false for deterministic output, since addresses vary run to run due to ASLR/PIE and are not meaningful to compare in a test. (default: true) |
Functions¶
sDumpStacktrace¶
| Spice | |
|---|---|
Captures and immediately dumps the calling function's stack trace to stderr - the one-call convenience entry point, auto-imported like the other 's'-prefixed runtime functions (see RuntimeModuleManager.h). Skips its own frame, so the first printed frame is the call site of sDumpStacktrace() itself.
Parameters
| Name | Type | Description |
|---|---|---|
includeAddresses |
bool |
Forwarded to dump() - see there. (default: true) |