Clone this wiki locally
Invoking kshdb initially
Calling kshdb from the outside is probably the most straight-forward thing to do. For example:
$ kshdb /etc/init.d/networking status ksh93 Shell Debugger, release 0.01 Copyright 2008 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. (/etc/init.d/networking:11): PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin kshdb<1>
Invoking from inside your program
Running your program while the debugger is watching can cause the program being debugged to slow down. I’ve not used kshdb enough to know how bad it is in practice. But I know for the bash version it is noticeable.
Another approach that gets around this feature is to load the debugger just before you need it by modifying your source code to include a call to the debugger. Let’s say kshdb is installed in
/usr/local/share/kshdb. Then first you pull in the debugger routines like this:
Sourcing the routines does not cause any significant slowdown in the running of the program, although that one file will pull in a number of other debugger files. Debugger routines start with
_Dbg_ so you should avoid using in your code for own variables. One of the important functions that
dbg-trace.sh defines is
So sometime later at the place where you you call the debugger just add a command to call it like this:
Like any other shell command you can put this inside a conditional command which might test various specific conditions under which you might want to enter the debugger.
Invoking from an interrupt handler
trap '_Dbg_debugger' USR1; . /usr/local/share/kshdb/dbg-trace.sh
Debugging doesn’t slow the program down until you run
_Dbg_debugger which installs a
trap DEBUG hook.
The above makes sense only you have access to a tty where you can then give interactive commands and see the results. There is a debugger command “set inferior tty” which allows you to specify a tty for debugger input output. (The bash debugger has a command to allow you redirect output to a file, but I haven’t ported that over.)
If you want to run a one-shot list of debugger commands, create a file with debugger commands and then specify that as option -x in dbg-trace.sh. For example, in file mykshdb.cmds put:
list where continue # or perhaps "quit" or "kill"
And then the source dbg-trace as was done above.
. /usr/local/share/kshdb/dbg-trace.sh -x mykshdb.cmds