Stack Trace Rt¶
| Spice | |
|---|---|
StackTraceEntry struct¶
One frame of a stack trace.
Fields¶
| Name | Type | Description |
|---|---|---|
address |
byte* |
return address within the function |
offset |
unsigned long |
bytes from the start of that function, 0 if unresolved |
functionName |
String |
demangled, empty if the symbol could not be resolved |
fileName |
String |
source file, empty unless the program carries debug info |
lineNumber |
unsigned int |
line within that file, 0 if unknown |
isSpice |
bool |
Spice code, as opposed to C, C++ or other native code; false if it could not be told |
Methods¶
dump¶
| Spice | |
|---|---|
Prints this frame to stderr, as '#
Parameters
| Name | Type | Description |
|---|---|---|
frameIndex |
unsigned long |
Position of this frame in its trace, counted from the most recent call |
includeAddress |
bool |
Whether to print the raw address. Pass false for deterministic output - addresses move between runs under ASLR/PIE. (default: true) |
StackTrace struct¶
Implements: IIterable<StackTraceEntry>
A captured stack trace: the frames of one call stack, most recent call first.
Methods¶
getSize¶
| Spice | |
|---|---|
Retrieve number of frames in this trace.
Returns: long — Number of frames
isEmpty¶
| Spice | |
|---|---|
Check if this trace is empty.
Returns: bool — Empty or not
getEntry¶
| Spice | |
|---|---|
Retrieve frame at the given index, counted from the most recent call.
Parameters
| Name | Type | Description |
|---|---|---|
index |
unsigned long |
Returns: StackTraceEntry& — Frame at the given index
capture¶
| Spice | |
|---|---|
Captures the stack of the calling function, resolving each frame as it goes. In an optimized build a function that was inlined into another still gets a frame of its own, since libbacktrace recovers it from the debug info; its offset is then counted from the start of the function it was inlined into.
Parameters
| Name | Type | Description |
|---|---|---|
skipFrames |
unsigned int |
Frames to omit above the direct caller, for wrappers that capture on a caller's behalf (default: 0u) |
dump¶
| Spice | |
|---|---|
Prints the whole trace to stderr, one line per frame, numbered from '#0' at the most recent call. A no-op when nothing was captured.
Parameters
| Name | Type | Description |
|---|---|---|
includeAddresses |
bool |
Forwarded to StackTraceEntry.dump() (default: true) |
hideNonSpiceFrames |
bool |
Leave out the frames that are not Spice code (see StackTraceEntry.isSpice), such as the C runtime below main. The frames that remain keep the number they have in the trace, so a gap in the numbering marks where frames were hidden, and every number still matches getEntry(). (default: false) |
getIterator¶
| Spice | |
|---|---|
Retrieve a forward iterator over the frames of this trace, so it can be walked with a foreach loop
Returns: StackTraceIterator<StackTraceEntry>
StackTraceIterator<T> struct¶
Implements: IIterator<StackTraceEntry>
Iterator over the frames of a stack trace, most recent call first.
A trace hands this out rather than the iterator of the Vector it currently keeps its frames in, so that how a trace stores them stays its own business. 'T' is always StackTraceEntry - see the type definitions at the top of this file for why it is spelled as a generic argument at all.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a stack trace iterator over the given trace
Parameters
| Name | Type | Description |
|---|---|---|
trace |
StackTrace& |
Stack trace to iterate over |
Methods¶
get¶
| Spice | |
|---|---|
Returns the current frame of the trace
Returns: StackTraceEntry& — Reference to the current frame
getIdx¶
| Spice | |
|---|---|
Returns the current frame number and the current frame of the trace
Returns: Pair<unsigned long, StackTraceEntry&> — Pair of current frame number and reference to the current frame
isValid¶
| Spice | |
|---|---|
Check if the iterator is valid
Returns: bool — true or false
next¶
| Spice | |
|---|---|
Moves the cursor to the next frame
Functions¶
sGetStacktrace¶
| Spice | |
|---|---|
Returns the calling function's stack trace. Auto-imported like the other 's'-prefixed runtime functions, so it needs no explicit import.
Returns: StackTrace
sDumpStacktrace¶
| Spice | |
|---|---|
Captures and immediately dumps the calling function's stack trace to stderr. The compiler calls it, with the default arguments, at every panic and failed assertion, right before the program exits.
Capturing and printing a trace use the std, and a panic raised in there (say, running out of memory for a String) would come back here and start over, until the stack is used up. A call made while a dump is under way therefore prints nothing, which lets that panic end the program as it would without stack traces. The flag is not atomic, so two threads dumping at the same time may cost one of them its trace, or let a nested panic through.
Parameters
| Name | Type | Description |
|---|---|---|
includeAddresses |
bool |
Forwarded to StackTrace.dump() (default: true) |
hideNonSpiceFrames |
bool |
Forwarded to StackTrace.dump() (default: false) |
Operators¶
operator[]¶
| Spice | |
|---|---|
Retrieve frame at the given index, counted from the most recent call.
Parameters
| Name | Type | Description |
|---|---|---|
trace |
StackTrace& |
|
index |
unsigned long |
Returns: StackTraceEntry& — Frame at the given index
operator++¶
| Spice | |
|---|---|
Advances the cursor by one
Parameters
| Name | Type | Description |
|---|---|---|
it |
StackTraceIterator<T>& |
StackTraceIterator |
operator--¶
| Spice | |
|---|---|
Move the cursor back by one
Parameters
| Name | Type | Description |
|---|---|---|
it |
StackTraceIterator<T>& |
StackTraceIterator |
operator+=¶
| Spice | |
|---|---|
Advances the cursor by the given offset
Parameters
| Name | Type | Description |
|---|---|---|
it |
StackTraceIterator<T>& |
StackTraceIterator |
offset |
Numeric |
Offset |
operator-=¶
| Spice | |
|---|---|
Move the cursor back by the given offset
Parameters
| Name | Type | Description |
|---|---|---|
it |
StackTraceIterator<T>& |
StackTraceIterator |
offset |
Numeric |
Offset |