6 History and Acknowledgments

The suggestion for a debugger for a Bourne-like shell came from the book “Learning the Korn Shell”, by Bill Rosenblatt Copyright (C) 1993 by O’Reilly and Associates, Inc. Others such as Cigy Cyriac, Chet Ramey, Rocky Bernstein, and Gary V. Vaughan expanded and improved on that.

However Bourne-Shell debuggers rely on a signal mechanism (SIGDEBUG) to call a debugger routine. In the Korn shell as well as BASH in versions prior to 2.05, there was a fundamental flaw: the routine that you registered in the trap, got called after the statement was executed. It takes little imagination to realize that this is a bit too late to find and correct errors, especially if the offending command happens to do serious damage like remove filesystems or reboot a server. As a horrible hack, these debuggers added one to the line number that was just executed on the wishful thinking that this would then be the line of next statement to execute. Sometimes this was correct, but it was too often wrong, such as in loops and conditionals, comments, or commands that are continued on the next line.

Another failing of these debuggers was the inability to debug into functions or into sourced files, provide a stack trace, dynamically skip a statement to be run, unconditionally trace into a function or subshell, or stop when a subroutine, sourced file, or subshell completed. In truth, the crux of the problem lay in debugging support in BASH. Given that there was limited bash debugging support, it is not surprising that these debuggers could not do any of the things listed above and could debug only a single shell in a single source file: lines could be listed only from a single text, breakpoints were set into the text which was in fact a copy of the script name prepended with debugger routines.

In version 2.04 of BASH, Rocky Bernstein started hacking on BASH to add call-stack information, source file information, allow for debugging into functions and for reporting line numbers in functions as relative to the file rather than the beginning of a function whose origin line number was not accessible from BASH. He started changing the user commands in bashdb to be like other more-advanced debuggers, in particular perl5db and gdb. However he gave up on this project when realizing that stopping before a line was crucial. A patch for this was nontrivial and wildly changed semantics. Furthermore the chance of getting his other patches into BASH was was not going to happen in version 2.04.

In version 2.05, the fundamental necessary change to the semantics of SIGDEBUG trap handling (suggested at least two years earlier) was made. Also, version 2.05 changed the line-number reporting in a function to be relative to the beginning of the file rather than the beginning of a function—sometimes. Rocky then picked up where he left off and this then became this debugger. A complete rewrite of the debugger, some of which started in 2.04 was undertaken. Debugger internals were changed to support multiple file names, save and restore the calling environment (such as variables $1 and $?) and install debugger signal handlers. Work was also done on the BASH in conjunction with the debugger to save stack trace information, provide a means for stopping after a routine finished, debugging into a subshell and so on. And a number of changes were made to BASH just to improve the accuracy of the line number reporting which is crucial in a debugger.

This documentation was modified from the GNU Debugger (GDB) Reference manual.

Additions to this section are particularly welcome. If you or your friends (or enemies, to be evenhanded) have been unfairly omitted from this list, we would like to add your names!

The following have contributed directly or indirectly to bashdb:

Rocky Bernstein (initial full-featured bashdb with stack tracing and multi-file support)

Masatake YAMATO (help to merge Rocky’s hack to the official bash source tree)

Rod Smith (for creating and hosting a nicely formatted version of this manual that you are probably reading online)

Bill Rosenblatt (kshdb), Michael Loukides (kshdb), Cigy Cyriac (proto bashdb), Chet Ramey (proto bashdb), and Gary V. Vaughan (proto bashdb).

Authors of per5ldb:

Ray Lischner, Johan Vromans, and Ilya Zakharevich.

Authors of GDB:

Richard Stallman, Andrew Cagney, Jim Blandy, Jason Molenda, Stan Shebs, Fred Fish, Stu Grossman, John Gilmore, Jim Kingdon, and Randy Smith (to name just a few).

Authors of GUD:

Eric S. Raymond.