4.5.2 Backtraces (‘where’)

A backtrace is essentially the same as the call stack: a summary of how your script got where it is. It shows one line per frame, for many frames, starting with the place that you are stopped at (frame zero), followed by its caller (frame one), and on up the stack.

backtrace
bt
where
T

Print a backtrace of the entire stack: one line per frame for all frames in the stack.

backtrace n
bt n
where n
T n

Similar, but print only the innermost n frames.

The names where and T are additional aliases for backtrace.

Each line in the backtrace shows the frame number and the function name, the source file name and line number, as well as the function name.

Here is an example of a backtrace taken a program in the regression-tests parm.sh.

% ../bashdb -n -L .. parm.sh
Bourne-Again Shell Debugger, release 5.2-1.1.2
Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2011 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(./parm.sh:21):
21:	fn1 5
bashdb<0> continue fn3
One-time breakpoint 1 set in file ./parm.sh, line 17.
fn2: testing 1 2 3
(./parm.sh:17):
17:	fn3() {
bashdb<1> where
->0 in file `./parm.sh' at line 14
##1 fn3() called from file `./parm.sh' at line 14
##2 fn2("testing 1", "2 3") called from file `parm.sh' at line 5
##3 fn1("0") called from file `parm.sh' at line 9
##4 fn1("1") called from file `parm.sh' at line 9
##5 fn1("2") called from file `parm.sh' at line 9
##6 fn1("3") called from file `parm.sh' at line 9
##7 fn1("4") called from file `parm.sh' at line 9
##8 fn1("5") called from file `parm.sh' at line 21
##9 source("parm.sh") called from file `bashdb' at line 143
##10 main("-n", "-L", "..", "parm.sh") called from file `bashdb' at line 0

The display for “frame” zero isn’t a frame at all, although it has the same information minus a function name; it just indicates that your script has stopped at the code for line 14 of ./parm.sh.