Stacktrace
stacktrace¶
Print a human-readable call stack to stderr. Frame 0 is the stacktrace function itself (always skipped). Frame 1 is the caller of stacktrace.
Example¶
my_function() {
stacktrace
}
Arguments¶
- $1 (int): Starting frame offset (default: 1, skip stacktrace itself)
Exit codes¶
- 0: Always
Output on stdout¶
- Call stack to stderr, one frame per line
stacktrace_array¶
Populate a named array with call-stack frame strings. Requires bash 4.3+ for namerefs. Each element is "func file:line". Frame 0 is always stacktrace_array itself (skipped).
Example¶
declare -a frames
stacktrace_array frames
printf '%s\n' "${frames[@]}"
Arguments¶
- $1 (string): Name of the caller's array variable to populate
- $2 (int): Starting frame offset (default: 1)
Exit codes¶
- 0: Always; 1 Missing array name argument