File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
22
3+ # maintain a cross-script trace stack. When a script sources /etc/functions
4+ # this appends the script name/line to TRACE_STACK; the variable is exported so
5+ # it survives into children invoked with exec. TRACE_FUNC will prepend this
6+ # stack to the normal function call stack, giving a full picture from init to
7+ # the current point (even across multiple scripts).
8+ # Only add the current script once to avoid repetition when the same script
9+ # sources this file multiple times or invokes TRACE_FUNC repeatedly.
10+ case " ${TRACE_STACK} " in
11+ * " main($0 :" * )
12+ ;;
13+ * )
14+ TRACE_STACK=" ${TRACE_STACK: +$TRACE_STACK -> } main($0 :0)"
15+ export TRACE_STACK
16+ ;;
17+ esac
18+
319# ------- Start of functions coming from /etc/ash_functions
420
521die () {
@@ -680,8 +696,12 @@ TRACE_FUNC() {
680696 # Append the direct caller (without extra " -> " at the end)
681697 stack_trace+=" ${FUNCNAME[1]} (${BASH_SOURCE[1]} :${BASH_LINENO[0]} )"
682698
683- # Print the final trace output
684- TRACE " ${stack_trace} "
699+ # Print the final trace output, including any inherited script-level stack
700+ if [ -n " $TRACE_STACK " ]; then
701+ TRACE " $TRACE_STACK -> $stack_trace "
702+ else
703+ TRACE " ${stack_trace} "
704+ fi
685705}
686706
687707# Show the entire current call stack in debug output - useful if a catastrophic
You can’t perform that action at this time.
0 commit comments