Skip to content

Commit c37f96d

Browse files
committed
functions: add full track tracing when doing TRACE_FUNC when DEBUG is enabled
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent fc2a52d commit c37f96d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

initrd/etc/functions

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
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

521
die() {
@@ -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

0 commit comments

Comments
 (0)