Bashdb tutorial: Debugging with the BASH debugger

[Top] [Contents] [Index] [ ? ]

Debugging with the BASH debugger

This file describes the BASH debugger, the BASH symbolic debugger.

This is the 3.1-0.06 Edition, 23 July 2006, for BASH.

Copyright (C) 2002, 2003, 2004, 2006 Rocky Bernstein


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Summary of the BASH Debugger

The purpose of a debugger such as the BASH debugger going on "inside" a bash script while it executes.

the BASH debugger these) to help you catch bugs in the act:

Although you can use the BASH debugger to debug scripts written in BASH, it can also be used just as a front-end for learning more about programming in BASH. As an additional aid, the debugger can be used within the context of an existing script with its functions and variables that have already been initialized; fragments of the existing can be experimented with by entering them inside the debugger.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 A Sample BASH Debugger Session

You can use this manual at your leisure to read all about the BASH debugger. However, a handful of commands are enough to get started using the debugger. This chapter illustrates those commands.

Below we will debug a script that contains a function to compute the factorial of a number: fact(0) is 1 and fact(n) is n*fact(n-1).

 
$ bashdb -L .  /tmp/fact.sh
Bourne-Again Shell Debugger, release bash-3.1-0.06
Copyright 2002, 2003, 2004, 2006 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.

(/tmp/fact.sh:9):
  9:	echo fact 0 is: `fact 0`
bashdb<0> -
  1:    #!/usr/local/bin/bash
  2:    fact() {
  3:    ((n==0)) && echo 1 && return
  4:    ((nm1=n-1))
  5:    ((result=n*`fact $nm1`))
  6:    return $result
  7:    }
  8:    
  9:==> echo fact 0 is: `fact 0`
bashdb<1> l
 10:   echo fact 3 is: $(fact 3)

The command invocation uses the option "-L ." Here we assume that the bashdb script and the debugger files are in the same location. If you are running from the source code, this will be the case. However if bashdb has been installed this probably won't be true and here you probably don't need to use "-L ." Instead you would type simply bashdb /tmp/fact.sh.

Position information consists of a filename and line number, e.g. (/tmp/fact.sh:9) and is given parenthesis. This position format is similar to that used by the Perl debugger and is also in the same format used by my GNU make debugger ( http://bashdb.sourceforge.net/remake. and Extended python debugger http://remake.sourceforge.net/pydb. GNU Emacs and DDD can parse this and in fact the same regular expression is used on the 3 debuggers.

The first debugger command we gave -, we listed a window of lines before where we were executing. Because the window, 10 lines, is larger than the number of lines to the top of the file we printed only 9 lines here. The next command list starting from the current line and again wants to print 10 lines but because there are only one remaining line, that is what is printed.

 
bashdb<2> step
(/tmp/fact.sh:9):
fact 0
9:	echo fact 0 is: `fact 0`
bashdb<(3)> RET
2:	fact() {
bashdb<(4)> RET
3:	((n==0)) && echo 1 && return
bashdb<(5)> print $n

Ooops... The variable n isn't initialized.

The first step command steps the script one instruction. It may seem odd that the line printed is exactly the same one as before. What has happened though is that we've "stepped" into the subshell needed to run `fact 0`; we haven't however started running anything inside that subshell yet though.

To indicate that which piece of the multi-part line echo fact 0 is: `fact 0` we show that part all by itself fact 0. If nothing is shown then it means we are running the beginning statement or in this case the outermost statement.

To indicate that we are now nested in a subshell, notice that the command number, starting with 3, or the third command entered, now appears in parenthesis. Each subshell nesting adds a set of parenthesis.

The first step command steps the script one instruction; it didn't advance the line number, 9, at all. That is because we were stopping before the command substitution or backtick is to take place. The second command we entered was just hitting the return key; bashdb remembers that you entered step previously, so it runs the step rather than next, the other alternative when you hit RET. Step one more instruction and we are just before running the first statement of the function.

Next, we print the value of the variable n. Notice we need to add a preceding dollar simple to get the substitution or value of n. As we will see later, if the pe command were used this would not be necessary.

We now modify the file to add an assignment to local variable n and restart.

 
bashdb<6> restart
Restarting with: /usr/local/bin/bashdb -L . fact.sh
(/tmp/fact.sh:10):
10:	echo fact 0 is: `fact 0`
bashdb<0> list 1
  1:    #!/usr/local/bin/bash
  2:    fact() {
  3:    local -i n=${1:0}
  4:    ((n==0)) && echo 1 && return
  5:    ((nm1=n-1))
  6:    ((result=n*`fact $nm1`))
  7:    return $result
  8:    }
  9:    
 10:==> echo fact 0 is: `fact 0`
bashdb<1> s 3
(/tmp/fact.sh:3):
3:	local -i n=${1:0}
bashdb<(2)> step
(/tmp/fact.sh:4):
4:	((n==0)) && echo 1 && return
bashdb<(3)> print $n
print $n
0

This time we use the list debugger command to list the lines in the file. From before we know it takes three steps commands before we get into the fact() function, so we add a count onto the step command. Notice we abbreviate step with s; we could have done likewise and abbreviated list with l.

 
bashdb<(4)> RET
(/tmp/fact.sh:4):
4:	((n==0)) && echo 1 && return
echo 1
bashdb<(5)> RET
(/tmp/fact.sh:4): 
4:	((n==0)) && echo 1 && return
return

Again we just use RET to repeat the last step commands. And again the fact that we are staying on the same line 4 means that the next condition in the line is about to be executed. Notice that we see the command (echo 1 or return) listed when we stay on the same line which has multiple stopping points in it. Given the information above, we know that the value echo'ed on return will be 1.

 
bashdb<(6)> RET
fact 0 is: 1
(/tmp/fact.sh:12): 
12:	echo fact 3 is: $(fact 3)
bashdb<(7)> break 5
Breakpoint 1 set in file fact.sh, line 5.
bashdb<(8)> continue

We saw that we could step with a count into the function fact(). However above took another approach: we set a stopping point or "breakpoint" at line 5 to get us a little ways into the fact() subroutine. Just before line 5 is to executed, we will get back into the debugger. The continue command just resumes execution until the next stopping point which has been set up in some way.

 
(/tmp/fact.sh:5):
5:      ((nm1=n-1))
Breakpoint 1 hit(1 times).
bashdb<(8)> x n-1
2
bashdb<(9)> s
(/tmp/fact.sh:5):
6:     ((result=n*`fact $nm1`))
bashdb<(10)> c
fact.sh: line 6: ((: result=n*: syntax error: operand expected (error token is "*")
bashdb<(7)> R
Restarting with: bash --debugger fact.sh 
11:	echo fact 0 is: `fact 0`
bashdb<0> l fact
 2:    fact () 
 3:    { 
 4:       local -i n=${1:0};
 5:       (( "n==0" )) && echo 1 && return;
 6:       (( nm1=n-1 ));
 7:       ((fact_nm1=`fact $nm1`))
 8:       (( "result=n*fact_nm1" ));
 9:       echo $result
10:    }

In addition to listing by line numbers, we can also list giving a function name. Below, instead of setting a breakpoint at line 5 and running "continue" as we did above, we try something slightly shorter and slightly different. We give the line number on the "continue" statement. This is a little different in that a one-time break is made on line 5. Once that statement is reached the breakpoint is removed.

 
bashdb<1> continue 5
One-time breakpoint 1 set in file fact.sh, line 5.
fact 0 is: 1
(/tmp/fact.sh:5):
5:	((nm1=n-1))
bashdb<(2)> s
6:	((fact_nm1=`fact $nm1`))
bashdb<(3)> s
2:	fact() {
bashdb<(4)> T
->0 in file `fact.sh' at line 2
##1 fact("3") called from file `fact.sh' at line 12
##2 source("fact.sh") called from file `/usr/local/bin/bashdb' at line 154
##3 main("fact.sh") called from file `/usr/local/bin/bashdb' at line 0
bashdb<(5)> c
fact 3 is: 6
Debugged program terminated normally. Use q to quit or R to restart.

When we stop at line 5 above, we have already run fact(0) and output the correct results. The output from the program "fact 0 is: 1" is intermixed with the debugger output. The T command above requests call stack output and this confirms that we are not in the fact(0) call but in the fact(3) call. There are 4 lines listed in the stack trace even though there is just one call from the main program. The top line of the trace doesn't really represent a call, it's just where we currently are in the program. That last line is an artifact of invoking bash from the bashdb script rather than running bash --debugger.

The last message in the output above `Debugged program exited normally.' is from the BASH debugger; it indicates script has finished executing. We can end our bashdb session with the bashdb quit command.

Above we did our debugging session on the command line. If you are a GNU Emacs user, you can do your debugging inside that. Also there is a(nother) GUI interface called DDD that supports the BASH debugger.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Interactive Line Tracing Session

One of the things I've always found annoying about set -x tracing is that there is no position information given in the trace output, in particular the line number and the file name. Although function nesting information is shown, other important Information such as BASH shell and subshell nesting count is not. From a programming standpoint, these are just as important because they affect the namespace, or the scope over which variables are seen.

Although I this is best fixed inside BASH, the debugger provides a means for showing position information when tracing a script. Here's a simple session.

 
/usr/local/bin/bashdb /tmp/fact.sh
Bourne-Again Shell Debugger, release bash-3.1-0.06
Copyright 2002, 2003, 2004, 2006 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.

(/tmp/fact.sh:11):
11:	echo fact 0 is: `fact 0`
bashdb<0> set linetrace on
bashdb<1> cont
(/tmp/fact.sh:11):
level 1, subshell 1, depth 0:	echo fact 0 is: `fact 0`
fact 0
(/tmp/fact.sh:2):
level 1, subshell 1, depth 1:	fact() {
(/tmp/fact.sh:3):
level 1, subshell 1, depth 1:	    local -i n=${1:0}
(/tmp/fact.sh:4):
level 1, subshell 1, depth 1:	    ((n==0)) && echo 1 && return
(/tmp/fact.sh:4):
level 1, subshell 1, depth 1:	    ((n==0)) && echo 1 && return
echo 1
(/tmp/fact.sh:4):
level 1, subshell 1, depth 1:	    ((n==0)) && echo 1 && return
return
fact 0 is: 1
(/tmp/fact.sh:13):
level 1, subshell 0, depth 0:	echo fact 3 is: $(fact 3)
(/tmp/fact.sh:13):
level 1, subshell 1, depth 0:	echo fact 3 is: $(fact 3)
fact 3
(/tmp/fact.sh:2):
level 1, subshell 1, depth 1:	fact() {
(/tmp/fact.sh:3):
level 1, subshell 1, depth 1:	    local -i n=${1:0}
(/tmp/fact.sh:4):
level 1, subshell 1, depth 1:	    ((n==0)) && echo 1 && return
(/tmp/fact.sh:5):
level 1, subshell 1, depth 1:	    ((nm1=n-1))
(/tmp/fact.sh:6):
level 1, subshell 1, depth 1:	    ((fact_nm1=`fact $nm1`))
(/tmp/fact.sh:6):
level 1, subshell 2, depth 1:	    ((fact_nm1=`fact $nm1`))
fact $nm1
(/tmp/fact.sh:2):
level 1, subshell 2, depth 2:	fact() {
...
level 1, subshell 4, depth 4:	fact() {
(/tmp/fact.sh:3):
level 1, subshell 4, depth 4:	    local -i n=${1:}
(/tmp/fact.sh:4):
level 1, subshell 4, depth 4:	    ((n==0)) && echo 1 && return
(/tmp/fact.sh:4):
level 1, subshell 4, depth 4:	    ((n==0)) && echo 1 && return
echo 1
(/tmp/fact.sh:4):
level 1, subshell 4, depth 4:	    ((n==0)) && echo 1 && return
return
(/tmp/fact.sh:7):
level 1, subshell 3, depth 3:	    ((result=n*fact_nm1))
(/tmp/fact.sh:8):
level 1, subshell 3, depth 3:	    echo $result
(/tmp/fact.sh:7):
level 1, subshell 2, depth 2:	    ((result=n*fact_nm1))
(/tmp/fact.sh:8):
level 1, subshell 2, depth 2:	    echo $result
(/tmp/fact.sh:7):
level 1, subshell 1, depth 1:	    ((result=n*fact_nm1))
(/tmp/fact.sh:8):
level 1, subshell 1, depth 1:	    echo $result
fact 3 is: 6
(/usr/local/bin/bashdb:260):
level 1, subshell 0, depth -1:	
Debugged program terminated normally. Use q to quit or R to restart.
bashdb<2> 

An explanation of the output. The level is how many invocations of BASH are in effect before the statement shown is executed. The subshell is how many subshells you are nested in. Subshells are used by command substitution--`..' and $(...)--as well as arithmetic expressions ((...)). The depth is the function depth or how many calls you are nested in. A "source" command also increases this depth.

Notice also that in contrast to set -x tracing, the line shown is exactly as you entered it in the source. So if you indented statements in a meaningful way, it will help you understand the statement nesting level. But as before, if a line contains multiple statements, you are not executing the first statement in the line and set showcommand is not turned off (by default it is on), that statement is shown in addition below the multi-statement line. Such an example can be seen right at the beginning where fact 0 is shown.

If what you want to do is trace the entire script as was done above (and not stop in the debugger when the script is over), you can get the same effect by using the -X or --trace option on the bashdb command:

 
/usr/local/bin/bashdb -X /tmp/fact.sh
Bourne-Again Shell Debugger, release bash-3.1-0.06
Copyright 2002, 2003, 2004, 2006 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.

(/usr/local/bin/bashdb:272):
level 1, subshell 0, depth -1:	  . $_source_file
(/tmp/fact.sh:11):
level 1, subshell 0, depth 0:	echo fact 0 is: `fact 0`
(/tmp/fact.sh:11):
level 1, subshell 1, depth 0:	echo fact 0 is: `fact 0`
fact 0
(/tmp/fact.sh:2):
level 1, subshell 1, depth 1:	fact() {
(/tmp/fact.sh:3):
level 1, subshell 1, depth 1:	    local -i n=${1:0}
...
level 1, subshell 2, depth 2:	    echo $result
(/tmp/fact.sh:7):
level 1, subshell 1, depth 1:	    ((result=n*fact_nm1))
(/tmp/fact.sh:8):
level 1, subshell 1, depth 1:	    echo $result
fact 3 is: 6
(/usr/local/bin/bashdb:285):
level 1, subshell 0, depth -1:	

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Free software

the BASH debugger General Public License (GPL). The GPL gives you the freedom to copy or adapt a licensed program--but every person getting a copy also gets with it the freedom to modify that copy (which means that they must get access to the source code), and the freedom to distribute further copies. Typical software companies use copyrights to limit your freedoms; the Free Software Foundation uses the GPL to preserve these freedoms.

Fundamentally, the General Public License is a license which says that you have these freedoms and that you cannot take these freedoms away from anyone else.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Free Software Needs Free Documentation

The biggest deficiency in the free software community today is not in the software--it is the lack of good free documentation that we can include with the free software. Many of our most important programs do not come with free reference manuals and free introductory texts. Documentation is an essential part of any software package; when an important free software package does not come with a free manual and a free tutorial, that is a major gap. We have many such gaps today.

Consider Perl, for instance. The tutorial manuals that people normally use are non-free. How did this come about? Because the authors of those manuals published them with restrictive terms--no copying, no modification, source files not available--which exclude them from the free software world.

That wasn't the first time this sort of thing happened, and it was far from the last. Many times we have heard a GNU user eagerly describe a manual that he is writing, his intended contribution to the community, only to learn that he had ruined everything by signing a publication contract to make it non-free.

Free documentation, like free software, is a matter of freedom, not price. The problem with the non-free manual is not that publishers charge a price for printed copies--that in itself is fine. (The Free Software Foundation sells printed copies of manuals, too.) The problem is the restrictions on the use of the manual. Free manuals are available in source code form, and give you permission to copy and modify. Non-free manuals do not allow this.

The criteria of freedom for a free manual are roughly the same as for free software. Redistribution (including the normal kinds of commercial redistribution) must be permitted, so that the manual can accompany every copy of the program, both on-line and on paper.

Permission for modification of the technical content is crucial too. When people modify the software, adding or changing features, if they are conscientious they will change the manual too--so they can provide accurate and clear documentation for the modified program. A manual that leaves you no choice but to write a new manual to document a changed version of the program is not really available to our community.

Some kinds of limits on the way modification is handled are acceptable. For example, requirements to preserve the original author's copyright notice, the distribution terms, or the list of authors, are ok. It is also no problem to require modified versions to include notice that they were modified. Even entire sections that may not be deleted or changed are acceptable, as long as they deal with nontechnical topics (like this one). These kinds of restrictions are acceptable because they don't obstruct the community's normal use of the manual.

However, it must be possible to modify all the technical content of the manual, and then distribute the result in all the usual media, through all the usual channels. Otherwise, the restrictions obstruct the use of the manual, it is not free, and we need another manual to replace it.

Please spread the word about this issue. Our community continues to lose manuals to proprietary publishing. If we spread the word that free software needs free reference manuals and free tutorials, perhaps the next person who wants to contribute by writing documentation will realize, before it is too late, that only free manuals contribute to the free software community.

If you are writing documentation, please insist on publishing it under the GNU Free Documentation License or another free documentation license. Remember that this decision requires your approval--you don't have to let the publisher decide. Some commercial publishers will use a free license if you insist, but they will not propose the option; it is up to you to raise the issue and say firmly that this is what you want. If the publisher you are dealing with refuses, please try other publishers. If you're not sure whether a proposed license is free, write to [email protected].

You can encourage commercial publishers to sell more free, copylefted manuals and tutorials by buying them, and particularly by buying copies from the publishers that paid for their writing or for major improvements. Meanwhile, try to avoid buying non-free documentation at all. Check the distribution terms of a manual before you buy it, and insist that whoever seeks your business must respect your freedom. Check the history of the book, and try to reward the publishers that have paid or pay the authors to work on it.

The Free Software Foundation maintains a list of free documentation published by other publishers, at http://www.fsf.org/doc/other-free-books.html.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Getting in and out

This chapter discusses how to start the BASH debugger, and how to get out of it. The essentials are:

There are also two front-ends available as well. One can also enter the debugger inside emacs via the command M-x bashdb after loading Emacs' Grand Unified Debugger, gud. See Using the BASH debugger from GNU Emacs. And there is support in a DDD for bash.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 Starting the BASH debugger

Note: it is important to use a debugger-enabled bash. You will get an error message if the debugger is run under a version of BASH that does not have debugging support.

As mentioned above, one can enter the BASH debugger DDD. However you don't have to use either of these. And these still need a way on their own to get things started.

There are in fact two other ways to start the BASH debugger. The first way is to pass the `--debugger' option to bash with the name of your script the scripts arguments following that, or with a command string (-c).

 
bash --debugger script script-arguments...
bash --debugger -c command-string...

This calls a debugger initialization script. It works much like a BASH login profile which may set variables and define functions. But this shell profile is customized for debugging and as such arranges for itself to get called before each statement is executed. Although there are some problems at present in I/O redirection that the method described next doesn't have, it is expected that over time more features will be enabled in bash when the `--debugger' option is in effect. By default, both debugging in Emacs via GUD (Using the BASH debugger under Emacs) and debugging via DDD work via this method.

The form `bash --debugger -c ...' can be used to get into the debugger without having to give a script name to debug. Sometimes you may want to do this just to see how the debugger works: try some debugger commands or maybe get online help. If you run ddd --bash without giving a script name, it in fact uses this form.

In order for the `--debugger' option to work however, you must have the debugger scripts installed in a place where the BASH debugger find them. For this reason, in developing the BASH debugger, I use a second method more often; it doesn't require the bash debugger to be installed. This method uses another script called bashdb which after taking its own options takes the name of the script to debugged and the arguments to pass to that script. Using this method, one would start the debugger like this:

 
bash path-to-bashdb/bashdb bashdb-options script script-arguments...

As with the first method, bash should be a debugger-enabled bash. If bashdb has the path to bash in it at the top (e.g. via #!), and bashdb can be found in your program-search path, then this might be equivalent to the above:

 
bashdb bashdb-options script script-arguments...

There are two or three disadvantages however of running a debugger this way. First $0 will have the value bashdb rather than the script you are trying to run. For some scripts this may change the behavior of the debugged script. Second a traceback will contain additional lines showing the "source"-ing of the debugged script from bashdb. And third, although this way works better than the first method, over time this way may come into disuse.

An option that you'll probably need to use if bashdb isn't installed but run out of the source code directory is `-L' which specifies the directory that contains the debugger script files.

You can further control how bashdb starts up by using command-line options. bashdb itself can remind you of the options available.

Type

 
bashdb -h

to display all available options and briefly describe their use.

When the bash debugger is invoked either by the bashdb front-end script or bash --debugging, the first argument that does not have an associated option flag for bashdb or bash (as the case may be) is used as the name a the script file to be debugged, and any following options get passed the debugged script.

Options for the bashdb front-end are shown in the following list.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.1 Command-line options for bashdb script

You can run the BASH debugger mode or quiet mode. If getopts support is available the script also allows long-form command options.

-h | --help

This option causes the BASH debugger to print some basic help and exit.

-V

This option causes the BASH debugger no-warranty blurb, and exit.

-c | --command cmd

Run the string instead of running a script

-B | --basename

This option causes the BASH debugger no-warranty blurb, and exit.

-n | --nx | --no-init

Do not execute commands found in any initialization files. Normally, BASH executes the commands in these files after all the command options and arguments have been processed. See section Command files.

-q | --quiet

"Quiet". Do not print the introductory and copyright messages. These messages are also suppressed in batch mode.

-t | --terminal | --tty tty

"Terminal output". Set the file or terminal that you want debugger command output to go to. Note that the debugger output is independent of the debugged script output.

-L | --library directory

Set directory where debugger files reside to directory. The default location is ../lib/bashdb relative to the place that the bashdb script is located. For example if bashdb is located in /usr/local/bin/bashdb, the default library location will be /usr/local/lib/bashdb which may or may not exist. If it doesn't you'll get an error when you run bashdb. Only if the default location is incorrect, should you need to use the -L option.

-T | --tempdir directory

Set directory to use for writing temporary files.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Quitting the BASH debugger

An interrupt (often C-c) does not exit from the BASH debugger, but rather terminates the action of any the BASH debugger progress and returns to the BASH debugger command level. Inside a debugger command interpreter, use quit command (see section Quitting the BASH debugger).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3 Calling the BASH debugger from inside your program

Running a program from the debugger adds a bit of overhead and slows down your program quite a bit, and addressing this better would mean some serious changes to BASH internals. If you have a configure script generated by autoconf, and you want to stop in the middle of the script, it can take quite a while.

Furthermore, by necessity, debuggers change the operation of the program they are debugging. And this can lead to unexpected and unwanted differences. It has happened so often that the term "Heisenbugs" (see http://en.wikipedia.org/wiki/Heisenbug) was coined to describe the situation where the addition of the use of a debugger (among other possibilities) changes behavior of the program so that the bug doesn't manifest itself anymore.

Another way to get into the debugger which adds no overhead or slowdown until you reach the point at which you want to start debugging. However here you must change the script and make an explicit call to the debugger. Because the debugger isn't involved before the first call, there is no overhead and the script will run at the same speed as if there were no debugger.

There are two parts to calling the debugger from inside the script, "sourcing" in the debugger code and then making the call calling the debugger to issue a "step" command. The name of file in source command is bashdb-trace and it is located in the directory where the other bash debugger files live. For example on GNU/Linux if it is in directory /usr/local/share/bashdb, you would first add to a BASH script the line:

 
    source /usr/local/share/bashdb/bashdb-trace

Although I said that running under the debugger adds overhead which slows down you program, the above command in of itself will not cause any slowdown. If possible, it's best to put this somewhere in the main-line code rather than in a function or in a subshell. If it is put in a function of subshell and you step outside of that, some of the global variables set up in bashdb-trace may be lost. One the other hand if you know your debugging will be confined to just the scope of the source command there is no problem.

The second thing that needs to be done is put add statements to start stepping code, and this line looks like this:

 
     _Dbg_set_trace ; : ; :

(For reasons that are a mystery to me, the stepping seems to kick in only two statements after the call.)

Putting these two components together, here's an example:

 
  # Lots of stuff here. ...
  x=2
  source <path-to-program>/_Dbg_bash_trace
  echo There can be lots of other statements between the above
  echo and below line.
  _Dbg_set_trace ; : ; :
  y=3

You will be stopped before y=3 in the debugger.

You can also supply options to _Dbg_bash_trace just as you would to the debugger itself. All of the options listed in Command-line options for bashdb script can be used with the exception of -c (run a command) and of course you don't supply the name of a BASH script.

For example to suppress the banner you could use _Dbg_bash_trace -q in the above example.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Script Setup inside the BASH Debugger


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 Starting your script

restart [options to debugged script]
run
R

Use the restart command to restart your script under the BASH debugger. Without any arguments, the script name and parameters from the last invocation are used. The BASH debugger tries to maintain the settings, watchpoints, breakpoints, actions and so on. Internally it uses line numbers and filenames to record he position of interesting places in your porgram; so if your program changes some or all of these numbers may be off. Environment variable BASHDB_RESTART_FILE is and a temporary file are used to signal a restart, so you shouldn't uset BASHDB_RESTART_FILE (or any environment variable starting with BASHDB_.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Command files

A command file for the BASH debugger commands. Comments (lines starting with #) may also be included. An empty line in a command file does nothing; it does not mean to repeat the last command, as it would from the terminal.

When you start the BASH debugger, it automatically executes commands from its init files, normally called `.bashdbinit'(1). During startup, the BASH debugger

  1. Reads the init file (if any) in your home directory(2).
  2. Processes command line options and operands.
  3. Reads the init file (if any) in the current working directory.
  4. Reads command files specified by the `-x' option.

The init file in your home directory can set options (such as `set complaints') that affect subsequent processing of command line options and operands. Init files are not executed if you use the `-x' option (see section bashdb script options).

On some configurations of the BASH debugger, the init file is known by a different name (these are typically environments where a specialized form of the BASH debugger different name for the specialized version's init file). These are the environments with special init file names:

You can also request the execution of a command file with the source command:

source filename

Execute the command file filename.

The lines in a command file are executed sequentially. They are not printed as they are executed. If there is an error, execution proceeds to the next command in the file.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 Your script's arguments

The arguments to your script can be specified by the arguments of the restart command. They are passed to a shell, which expands wildcard characters and performs redirection of I/O, and thence to your script.

restart with no arguments uses the same arguments used by the previous restart, or those set by the set args command..

set args

Specify the arguments to be used the next time your program is run. If set args has no arguments, restart executes your program with no arguments. Once you have run your program with arguments, using set args before the next restart is the only way to run it again without arguments.

show args

Show the arguments to give your program when it is started.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Your script's input and output

By default, the script you run under the BASH debugger does input and output to the same terminal that BASH uses. Before running the script to be debugged, the debugger records the tty that was in effect. All of its output is then written to that. However you can change this when using the `bashdb' script using the `-t' option.

info terminal

Displays information recorded by the BASH debugger program is using.

Another way to specify where your script should do input and output is with the tty command. This command accepts a file name as argument, and causes this file to be the default for future restart commands. It also resets the controlling terminal for the child process, for future restart commands. For example,

 
tty /dev/ttyb

directs that processes started with subsequent restart commands default to do input and output on the terminal `/dev/ttyb' and have that as their controlling terminal.

An explicit redirection in restart overrides the tty command's effect on the input/output device, but not its effect on the controlling terminal.

When you use the tty command or redirect input in the restart command, only the input for your script is affected. The input for the BASH debugger


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5 Script/Debugger Interaction

The BASH debugger and your program live in the same variable space so to speak. BASH does not have a notion of module scoping or lexical hiding (yet) and this then imposes some additional care and awareness.

Most of the variables and functions used inside the BASH debugger _Dbg_, so please don't use variables or functions with these names in your program.

Note: there are some other variables that begin with just an underscore (_); over time these will be phased out. But until then, avoid those or consult what is used by the debugger. Run `bashdb --debugger -c 'declare -p'' to list all the variables in use including those used by the debugger.

A number of the BASH debugger use; these start with BASHDB_. For example: BASHDB_INPUT, BASHDB_LEVEL and, BASHDB_QUIT_ON_QUIT (see section Debug), BASHDB_RESTART_FILE (see section Starting), to name a few. Finally, there are some BASH environment dynamic variables and these start with BASH_. For example BASH_SUBSHELL (see section Debug), BASH_COMMAND (see section Command Display), BASH_LINENO, and BASH_SOURCE to name a few.

In order to do its work The BASH debugger sets up a DEBUG trap. Consequently a script shouldn't reset this or the debugger will lose control. The BASH debugger also sets up an EXIT handler so that it can gain control after the script finishes. Another signal intercepted is the an interrupt or INT signal. For more information about signal handling, see section Signals


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. BASH Debugger Command Reference

You can abbreviate the long name of the BASH debugger few letters of the command name, if that abbreviation is unambiguous; and you can repeat the next o rstep commands by typing just RET. Some commands which require a parameter, such as print remember the argument that was given to them.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Command syntax

A BASH debugger command is a single line of input. There is no limit on how long it can be. It starts with a command name, which is followed by arguments whose meaning depends on the command name. For example, the command step accepts an argument which is the number of times to step, as in `step 5'. You can also use the step command with no arguments. Some commands do not allow any arguments.

A blank line as input to the BASH debugger repeat the previous next or step command.

Any text from a # to the end of the line is a comment; it does nothing. This is useful mainly in command files (see section Command files).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Getting help (`help')

Once inside the BASH debugger, you can always ask it for information on its commands, using the command help.

help
h

You can use help (abbreviated h) with no arguments to display a short list of named classes of commands:

 
bashdb<0> help
bashdb commands:
List/search source lines:                 Control script execution:
-------------------------                 -------------------------
 l [start|.] [cnt] List cnt lines         T [n]        Stack trace
                   from line start        s [n]        Single step [n times]
 l sub       List source code fn          n [n]        Next, steps over subs
 - or .      List previous/current line   <CR>/<Enter> Repeat last n or s 
 w [line]    List around line             c [linespec] Continue [to linespec]
 f filename  View source in file          L            List all breakpoints
 /pat/       Search forward for pat       b linespec   Set breakpoint
 ?pat?       Search backward for pat      del [n].. or D Delete a/all breaks
                                                         by entry number
Debugger controls:                        skip         skip execution of cmd
-------------------------                 cl linespec  Delete breakpoints by
 H [num]         Show last num commands                line spec
 q [exp] or ^D   Quit returning exp       R [args]     Attempt a restart
 info [cmd]      Get info on cmd.         u [n]        Go up stack by n or 1.
 !n or hi n      Run debugger history n   do [n]       Go down stack by n or 1.
 h or ? [cmd]    Get help on command      W [var]      Add watchpoint. If no
 info [cmd]      Get info on cmd                       no expr, delete all
 show [cmd]      Show settings            We [expr]    Add Watchpoint arith 
                                                       expr
 so file         read in dbg commands     t            Toggle trace
                                          en/di n      enable/disable brkpt,
 set x y         set a debugger variable               watchpoint, or display
 e bash-cmd      evaluate a bash command  tb linespec  Add one-time break
 disp expr       add a display expr       a linespec cmd eval "cmd" at linespec
 M               Show module versions     A            delete all actions
 x expr          evaluate expression      ret          jump out of fn or source
                 (via declare, let, eval) finish       execute until return
 deb             debug into another       cond n exp   set breakpoint condition
                 shell script
 !! cmd [args]   execute shell command "cmd" with "args"
 file filename   Set script filename to read for current source.

Data Examination: also see e, t, x
-------------------------                 
 p variable      Print variable 
 V [[!]pat]      List variable(s) matching or not (!) matching pattern pat
 S [[!]pat]      List subroutine names [not] matching pattern pat

Readline command line editing (emacs/vi mode) is available.
For more help, type h <cmd> or consult online-documentation.
help command

With a command name as help argument, the BASH debugger displays short information on how to use that command.

 
bashdb<0> help list
l linespec      List window lines starting at linespec.
l min incr      List incr lines starting at 'min' linespec.
l               List next window of lines.
l .             Same as above.
                Long command name: list.

In addition to help, you can use the debugger command info to inquire about the state of your script, or the state of the BASH debugger point to all the sub-commands. See section Command Index.

info

This command (abbreviated i) is for describing the state of your program. For example, you can list the arguments given to your script with info args, or list the breakpoints you have set with info breakpoints. You can get a complete list of the info sub-commands with help info.

 
bashdb<0> help info
List of info subcommands:

info args -- Argument variables (e.g. $1, $2, ...) of the current stack frame.
info breakpoints -- Status of user-settable breakpoints
info display -- Show all display expressions
info files -- Source files in the program
info functions -- All function names
info line -- list current line number and and file name
info program -- Execution status of the program.
info signals -- What debugger does when program gets various signals
info source -- Information about the current source file
info stack -- Backtrace of the stack
info terminal -- Print terminal device
info variables -- All global and static variable names
info warranty -- Various kinds of warranty you do not have
bashdb<1> info source
Current script file is parm.sh
Contains 34 lines.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Quitting the BASH debugger (`quit')

quit [expression]
quit [expression [subshell-levels]]
q

To exit the BASH debugger, use the quit command (abbreviated q), or type an end-of-file character (usually C-d). If you do not supply expression, the BASH debugger normally or with exit code 0. Otherwise it will terminate using the result of expression as the exit code.

A simple quit tries to terminate all nested subshells that may be in effect. If you are nested a subshell, this is normally indicated in a debugger prompt by the number of parentheses that the history number is inside -- no parenthesis means there is no subshell in effect. The dynamic variable BASH_SUBSHELL also contains the number of subshells in effect.

If you want only to terminate some number of subshells but not all of them, you can give a count of the number of subshells to leave after the return-code expression. To leave just one level of subshell return does almost the same thing. (See see section Returning) There is a subtle difference between the two though: return will leave you at the beginning of the next statement while quit may leave you at the place the subshell was invoked which may be in the middle of another command such as an assingment statement or condition test.

If the environment variable BASHDB_QUIT_ON_QUIT is set, when the program terminates, the debugger will also terminate too. This may be useful if you are debugging a script which calls another script and you want this inner script just to return to the outer script.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Stopping and Resuming Execution

One important use of a debugger is to stop your program before it terminates so that, if your script might run into trouble, you can investigate and find out why. However should your script accidently continue to termination, the BASH debugger debugger without your explicit instruction. That way, you can restart the program using the same command arguments.

Inside the BASH debugger, your script may stop for any of several reasons, such as a signal, a breakpoint, or reaching a new line after a debugger command such as step. You may then examine and change variables, set new breakpoints or remove old ones, and then continue execution.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)

A breakpoint makes your script stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your script stops.

You can set breakpoints with the break command and its variants (see section Setting breakpoints), to specify the place where your script should stop by line number. or function name in the debugged script.

A watchpoint is a special breakpoint that stops your script when the value of an expression changes. There is a different command to set watchpoints (see section Setting watchpoints).

But aside from that, you can manage a watchpoint like any other breakpoint: you delete enable, and disable both breakpoints and watchpoints using the same commands.

You can arrange to have values from your program displayed automatically whenever BASH stops at a breakpoint. See section Automatic display.

The BASH debugger assigns a number to each breakpoint and watchpoint when you create it; these numbers are successive integers starting with one. In many of the commands for controlling various features of breakpoints you use the breakpoint number to say which breakpoint you want to change. Each breakpoint may be enabled or disabled; if disabled, it has no effect on your script until you enable it again.

Watchpoint numbers however are distinguished from breakpoint numbers by virtue of their being suffixed with the either an upper- or lower-case `W'. For example, to enable breakpoint entry 0 along with watchpoint entry 1 you would write `enable 1 2w', the "2w" refers to the watchpoint; "2W" would work just as well.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1.1 Setting breakpoints (`break' `tbreak')

Breakpoints are set with the break command (abbreviated b).

break function

Set a breakpoint at entry to function function.

break linenum

Set a breakpoint at line linenum in the current source file. The current source file is the last file whose source text was printed. The breakpoint will stop your script just before it executes any of the code on that line.

break filename:linenum

Set a breakpoint at line linenum in source file filename; filename has to be one of the files previously read in and has to be specified exactly as the name used when read in. For a list of read-in files, use the `info files' command.

break � if cond

Set a breakpoint with condition cond; evaluate the expression cond each time the breakpoint is reached, and stop only if the value is nonzero--that is, if cond evaluates as true. The expression is evaluated via the let builtin funtion. `�' stands for one of the possible arguments described above (or no argument) specifying where to break. The word "if" is often optional and is necessary only `�' is omitted. See section Break conditions, for more information on breakpoint conditions.

Examples:

 
bashdb<0> break fn1
Breakpoint 1 set in file parm.sh, line 3.
bashdb<1> break 28
Breakpoint 2 set in file parm.sh, line 28.
bashdb<2> break parm.sh:29
Breakpoint 3 set in file parm.sh, line 29.
bashdb<3> break 28 if x==5
Breakpoint 4 set in file parm.sh, line 28.
tbreak args

Set a breakpoint enabled only for one stop. args are the same as for the break command, and the breakpoint is set in the same way, but the breakpoint is automatically deleted after the first time your program stops there. See section Disabling breakpoints.

info breakpoints [n]
info break [n]
info watchpoints [n]

Print a table of all breakpoints, watchpoints set and not deleted, with the following columns for each breakpoint:

Breakpoint Numbers (`Num')
Enabled or Disabled (`Enb')

Enabled breakpoints are marked with `1'. `0' marks breakpoints that are disabled (not enabled).

Count

The number of times that breakpoint or watchpoint has been hit.

Condition

The arithmetic expression

File and Line (`file:line')

The filename and line number inside that file where of breakpoint in the script. The file and line are separated with a colon.

If a breakpoint is conditional, info break shows the condition on the line following the affected breakpoint; breakpoint commands, if any, are listed after that.

info break displays a count of the number of times the breakpoint has been hit.

info break with a breakpoint number n as argument lists only that breakpoint.

Examples:

 
bashdb<4> info break
Breakpoints at following places:
Num Type       Disp Enb What
1   breakpoint keep y   parm.sh:3
2   breakpoint keep y   parm.sh:28
3   breakpoint keep y   parm.sh:29
4   breakpoint keep y   parm.sh:28
No watch expressions have been set.
bashdb<5> info break 4
Num Type       Disp Enb What
4   breakpoint keep y   parm.sh:28
No watch expressions have been set.

the BASH debugger your script. There is nothing silly or meaningless about this. When the breakpoints are conditional, this is even useful (see section Break conditions).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1.2 Setting watchpoints (`watch', `watche')

You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. As with the print (see section Examining Data), the idiosyncracies of a BASH or any POSIX shell derivative suggest using two commands. The watch command is just for a single variables; the watche command uses the builtin "let" command to evaluate an expression. If the variable you are tracking can take a string value, issuing something like `watch foo' will not have the desired effect--any string assignment to foo will have a value 0 when it is assigned via "let."

watch var

Set a watchpoint for a variable. the BASH debugger value of var changes. In this command do not add a leading dollar symbol to var.

watche expr

Set a watchpoint for an expression via the builtin "let" command. the BASH debugger and its value changes. Not that this may not work for tracking arbitrary string value changes. For that use watch described earlier.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1.3 Breakpoint command lists (`commands')

commands [bnum]
� command-list �
end

Specify a list of commands for breakpoint number bnum. The commands themselves appear on the following lines. Type a line containing just end to terminate the commands.

To remove all commands from a breakpoint, type commands and follow it immediately with end; that is, give no commands.

With no bnum argument, commands refers to the last breakpoint, watchpoint, or catchpoint set (not to the breakpoint most recently encountered).

Pressing RET as a means of repeating the last debugger command is disabled within a command-list.

You can use breakpoint commands to start your program up again. Simply use the continue command, or step, or any other command that resumes execution.

Any other commands in the command list, after a command that resumes execution, are ignored. This is because any time you resume execution (even with a simple next or step), you may encounter another breakpoint--which could have its own command list, leading to ambiguities about which list to execute.

If the first command you specify in a command list is silent, the usual message about stopping at a breakpoint is not printed. This may be desirable for breakpoints that are to print a specific message and then continue. If none of the remaining commands print anything, you see no sign that the breakpoint was reached. silent is meaningful only at the beginning of a breakpoint command list.

The commands echo, output, and printf allow you to print precisely controlled output, and are often useful in silent breakpoints.

For example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.

 
break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end

One application for breakpoint commands is to compensate for one bug so you can test for another. Put a breakpoint just after the erroneous line of code, give it a condition to detect the case in which something erroneous has been done, and give it commands to assign correct values to any variables that need them. End with the continue command so that your program does not stop, and start with the silent command so that no output is produced. Here is an example:

 
break 403
commands
silent
set x = y + 4
cont
end

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1.4 Deleting breakpoints (`clear', `delete')

It may desirable to eliminate a breakpoint or watchpoint once it has done its job and you no longer want your script to stop there. This is called deleting the breakpoint. A breakpoint that has been deleted no longer exists; it is forgotten.

With the clear command you can delete breakpoints according to where they are in your script. With the delete command you can delete individual breakpoints, or watchpoints by specifying their breakpoint numbers. Note: as described below under the "clear" command, "d" is an alias for "clear", not "delete".

It is not necessary to delete a breakpoint to proceed past it. the BASH debugger automatically ignores breakpoints on the first instruction to be executed when you continue execution.

clear

Delete any breakpoints at the next instruction to be executed in the selected stack frame (see section Selecting a frame). When the innermost frame is selected, this is a good way to delete a breakpoint where your script just stopped.

It may seem odd that we have an alias "d" for "clear." It so happens that Perl's debugger use "d" for its delete command and the delete concept in Perl's debugger corresponds to "clear" in GDB. (Perl doesn't have a notion of breakpoint entry numbers). So in order to be compatible with both debugger interfaces, "d" is used as an alias for "clear." Clear?

clear function
clear filename:function

Delete any breakpoints set at entry to the function function.

clear linenum
d linenum

Delete any breakpoints set at or within the code of the specified line.

delete [breakpoints]

Delete the breakpoints, watchpoints specified as arguments.

If no argument is specified, delete all breakpoints (the BASH debugger confirmation, unless you have set confirm off). You can abbreviate this command as de.

Note that for compatibility with Perl's debugger, d means something else: clear.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1.5 Disabling breakpoints (`disable', `enable')

Rather than deleting a breakpoint or watchpoint, you might prefer to disable it. This makes the breakpoint inoperative as if it had been deleted, but remembers the information on the breakpoint so that you can enable it again later.

You disable and enable breakpoints, watchpoints, and catchpoints with the enable and disable commands, optionally specifying one or more breakpoint numbers as arguments. Use info break or info watch to print a list of breakpoints, watchpoints, and catchpoints if you do not know which numbers to use.

A breakpoint, watchpoint, or catchpoint can have any of four different states of enablement:

You can use the following commands to enable or disable breakpoints, watchpoints, and catchpoints:

disable [breakpoints]

Disable the specified breakpoints--or all breakpoints, if none are listed. A disabled breakpoint has no effect but is not forgotten. All options such as ignore-counts, conditions and commands are remembered in case the breakpoint is enabled again later. You may abbreviate disable as dis.

enable [breakpoints]

Enable the specified breakpoints (or all defined breakpoints). They become effective once again in stopping your program.

Except for a breakpoint set with tbreak (see section Setting breakpoints), breakpoints that you set are initially enabled; subsequently, they become disabled or enabled only when you use one of the commands above. (The command until can set and delete a breakpoint of its own, but it does not change the state of your other breakpoints; see Resuming Execution.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1.6 Break conditions (`condition')

The simplest sort of breakpoint breaks every time your script reaches a specified place. You can also specify a condition for a breakpoint. A condition is just a BASH expression.

Break conditions can be specified when a breakpoint is set, by using `if' in the arguments to the break command. See section Setting breakpoints. A breakpoint with a condition evaluates the expression each time your script reaches it, and your script stops only if the condition is true.

There is also a notion of a "one-time" breakpoint which gets deleted as soon as it is hit, so that that breakpoint is executed once only.

Conditions are also accepted for watchpoints; you may not need them, since a watchpoint is inspecting the value of an expression anyhow--but it might be simpler, say, to just set a watchpoint on a variable name, and specify a condition that tests whether the new value is an interesting one.

Break conditions can be specified when a breakpoint is set, by using `if' in the arguments to the break command. See section Setting breakpoints. They can also be changed at any time with the condition command.

condition bnum expression

Specify expression as the break condition for breakpoint bnum. After you set a condition, breakpoint bnum stops your program only if the value of expression is true (nonzero).

condition bnum

Remove the condition from breakpoint number bnum. It becomes an ordinary unconditional breakpoint.

BASH does not actually evaluate expression at the time the condition command (or a command that sets a breakpoint with a condition, like break if �) is given, however.

Examples;

 
condition 1 x>5   # Stop on breakpoint 0 only if x>5 is true.
condition 1       # Change that! Unconditinally stop on breakpoint 1.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2 Resuming Execution (`step', `next', `finish', `skip', `continue', `debug', `return')

Continuing means resuming program execution until your script completes normally. In contrast, stepping means executing just one more "step" of your script, where "step" may mean either one line of source code. Either when continuing or when stepping, your script may stop even sooner, due to a breakpoint or a signal.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.1 Step (`step')

step

Continue running your script until control reaches a different source line, then stop it and return control to the BASH debugger. This command is abbreviated s.

The step command only stops at the first instruction of a source line. This prevents the multiple stops that could otherwise occur in switch statements, for loops, etc. step continues to stop if a function that has debugging information is called within the line. In other words, step steps inside any functions called within the line.

step [count]

Continue running as in step, but do so count times. If a breakpoint is reached, or a signal not related to stepping occurs before count steps, stepping stops right away.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.2 Next (`next')

next [count]

Continue to the next source line in the current (innermost) stack frame. This is similar to step, but function calls that appear within the line of code are executed without stopping. Execution stops when control reaches a different line of code at the original stack level that was executing when you gave the next command. This command is abbreviated n.

An argument count is a repeat count, as for step.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.3 Finish (`finish')

finish

Continue running until just after function returns. Currently, the line shown on a return is the function header, unless the return builtin function is executed in which case it is the line number of the return function.

Contrast this with the return command (see section Returning from a function) and the quit (see section Quitting the BASH debugger).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.4 Skip (`skip')

skip [count]

Skip execution of the next source line. This may be useful if you have an action that "fixes" existing code in the script. The debug command internally uses the skip command to skip over existing non-debugged invocation that was presumably just run.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.5 Continue (`continue')

continue [linespec]
c [line-number]

Resume program execution, at the address where your script last stopped; any breakpoints set at that address are bypassed. The optional argument linespec allows you to specify a linespec (a line number, function, or filename linenumber combination) to set. A one-time breakpoint is deleted when that breakpoint is reached. Should the program stop before that breakpoint is reached, for example, perhaps another breakpoint or watchpoint is reached first, in a listing of the breakpoints you will see this entry with the condition 9999 which indicates a one-time breakpoint.

To resume execution at a different place, you can use return (see section Returning from a function) to go back to the calling function or sourced script. If you are nested inside a subshell, quit with a value for the number of subshells to exit also functions like a return.

A typical technique for using stepping is to set a breakpoint (see section Breakpoints; watchpoints) at the beginning of the function or the section of your script where a problem is believed to lie, run your script until it stops at that breakpoint, and then step through the suspect area, examining the variables that are interesting, until you see the problem happen.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.6 Debug (`debug')

debug [script-name]

Debug into script-name. If no name is given the current source line is used. In either case the options are prepended to cause the debugger to run.

The nesting level of the debugger is saved inside environment variable BASHDB_LEVEL. The debugger prompt indicates the level of nesting by enclosing the history in that many nestings of <> symbols.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.2.7 Returning from a function, sourced file, or subshell (`return')

return
return

You can cancel execution of a function call or a subshell with the return command.

The return command does not resume execution; it leaves the program stopped in the state that would exist if the function had just returned. See also the quit command (Quitting the BASH debugger). In some situations return is similar to quit: in particular when the script is not currenlty inside in a function and the number of subshells in effect is 0, or when a subshell count of 1 is given on the quit command.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.3 Signals

A signal is an asynchronous event that can happen in a program. The operating system defines the possible kinds of signals, and gives each kind a name and a number. For example, in Unix SIGINT is the signal a program gets when you type an interrupt character (often C-c); SIGALRM occurs when the alarm clock timer goes off (which happens only if your program has requested an alarm).

Some signal handlers are installed and changed for the BASH debugger's normal use: SIGDEBUG and SIGEXIT. SIGDEBUG is used by the debugger to potentially stop your program before execution of each statement occurs, and SIGEXIT is used to catch your program just before it is set to leave so you have the option of restarting the program with the same options (and not leave the debugger) or let the program quit.

Signal handlers that the debugged script might have installed are saved and called before the corresponding debugger handler. Thus, the debugged program should work roughly in the same fashion as when it is not debugged. However there are some call-stack variables which inevitably will differ. To try to hedge this a little so the behaviour is the same, the BASH debugger will modify arguments to the traps if it finds one of the call-stack that change as a result of the debugger being in place. In particluar $LINENO will get replaced with ${BASH_LINENO[0]}; also ${BASH_LINENO[0]} and ${BASH_SOURCE[0]} get replaced with ${BASH_LINENO[1]} and ${BASH_SOURCE[1]} respectively.

The debugger also installs an interrupt handler SIGINT so that errant programs can be interrupted and you can find out where the program was when you interrupted it.

Some signals, including SIGALRM, are a normal part of the functioning of your program. Others, such as SIGSEGV, indicate errors; these signals are fatal (they kill your program immediately) if the program has not specified in advance some other way to handle the signal. SIGINT does not indicate an error in your program, but it is normally fatal so it can carry out the purpose of the interrupt: to kill the program.

BASH has the ability to detect any occurrence of a signal in your program. You can tell BASH in advance what to do for each kind of signal.

Normally, BASH is set up to let the non-erroneous signals like SIGALRM be silently passed to your program (so as not to interfere with their role in the program's functioning) but to stop your program immediately whenever an error signal happens. You can change these settings with the handle command.

info signals
info handle

Print a table of all the kinds of signals and how BASH has been told to handle each one. You can use this to see the signal numbers of all the defined types of signals.

info handle is an alias for info signals.

handle signal keywords�

Change the way BASH handles signal signal. signal can be the number of a signal or its name (with or without the `SIG' at the beginning); a list of signal numbers of the form `low-high'; or the word `all', meaning all the known signals. The keywords say what change to make.

The keywords allowed by the handle command can be abbreviated. Their full names are:

stop

BASH should stop your program when this signal happens. This implies the print keyword as well.

nostop

BASH should not stop your program when this signal happens. It may still print a message telling you that the signal has come in.

print

BASH should print a message when this signal happens.

noprint

BASH should not mention the occurrence of the signal at all.

stack

BASH should print a stack trace when this signal happens.

nostack

BASH should not print a stack trace when this signal occurs.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 Status and Debugger Settings (`info', `show')

In addition to help, you can use the BASH commands info and show to inquire about the state of your program, or the state of BASH itself. Each command supports many topics of inquiry; here we introduce each of them in the appropriate context. The listings under info and under show in the Index point to all the sub-commands. See section Command Index.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.1 Showing information about the program being debugged (`info')

This info command (abbreviated i) is for describing the state of your program. For example, you can list the current $1, $2 parameters with info args, or list the breakpoints you have set with info breakpoints or info watchpoints. You can get a complete list of the info sub-commands with help info.

info args

Argument variables (e.g. $1, $2, ...) of the current stack frame.

info breakpoints

Status of user-settable breakpoints

info display

Show all display expressions

info files

Source files in the program

info functions

All function names

info line

list current line number and and file name

info program

Execution status of the program.

info signals

What debugger does when program gets various signals

info source

Information about the current source file

info stack

Backtrace of the stack

info terminal

Print terminal device

info variables

All global and static variable names


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.2 Show information about the debugger (`show')

In contrast to info, show is for describing the state of BASH itself. You can change most of the things you can show, by using the related command set;

The distinction between info and show however is a bit fuzzy and is kept here to try to follow the GDB interface. For example, to list the arguments given to your script use show args; info args does something different.

Here are three miscellaneous show subcommands, all of which are exceptional in lacking corresponding set commands:

show version

Show what version of BASH is running. You should include this information in BASH bug-reports. If multiple versions of BASH are in use at your site, you may need to determine which version of BASH you are running; as BASH evolves, new commands are introduced, and old ones may wither away. Also, many system vendors ship variant versions of BASH, and there are variant versions of BASH in GNU/Linux distributions as well. The version number is the same as the one announced when you start BASH.

show copying

Display information about permission for copying BASH.

show linetrace

Show if line tracing is enabled. See also Show position information as statements are executed (`set linetrace').

show logging

Show summary information of logging variables which can be set via set logging. See also Logging output (`set logging', `set logging file'...).

show logging file

Show the current logging file.

show logging overwrite

Show whether logging overwrites or appends to the log file.

show warranty

Display the GNU "NO WARRANTY" statement, or a warranty, if your version of the BASH debugger


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6 Examining the Stack (`where', `frame', `up', `down')

When your script has stopped, one thing you'll probably want to know is where it stopped and some idea of how it got there.

Each time your script performs a function call (either as part of a command substitution or not), or `source's a file, information about this action is saved. The call stack then is this a history of the calls that got you to the point that you are currently stopped at.

One of the stack frames is selected by the BASH debugger the BASH debugger particular, whenever you ask the BASH debugger a line number or location the value is found in the selected frame. There are special the BASH debugger are interested in. See section Selecting a frame.

When your program stops, BASH automatically selects the currently executing frame and describes it briefly, similar to the frame command.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.1 Stack frames

The call stack is divided up into contiguous pieces called stack frames, or frames for short; each frame is the data associated with one call to one function. The frame contains the line number of the caller of the function, the source-file name that the line refers to a function name (which could be the built-in name "source")..

When your script is started, the stack has only one frame, that of the function main. This is called the initial frame or the outermost frame. Each time a function is called, a new frame is made. Each time a function returns, the frame for that function invocation is eliminated. If a function is recursive, there can be many frames for the same function. The frame for the function in which execution is actually occurring is called the innermost frame. This is the most recently created of all the stack frames that still exist.

the BASH debugger assigns numbers to all existing stack frames, starting with zero for the innermost frame, one for the frame that called it, and so on upward. These numbers do not really exist in your script; they are assigned by the BASH debugger to give you a way of designating stack frames in the BASH debugger commands.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.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 sare 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 3.1-0.06
Copyright 2002, 2003, 2004, 2006 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.3 Selecting a frame (`up', `down', `frame')

Commands for listing source code in your script work on whichever stack frame is selected at the moment. Here are the commands for selecting a stack frame; all of them finish by printing a brief description of the stack frame just selected.

up n

Move n frames up the stack. For positive numbers n, this advances toward the outermost frame, to higher frame numbers, to frames that have existed longer. n defaults to one.

down n

Move n frames down the stack. For positive numbers n, this advances toward the innermost frame, to lower frame numbers, to frames that were created more recently. n defaults to one. You may abbreviate down as do.

All of these commands end by printing two lines of output describing the frame. The first line shows the frame number, the function name, the arguments, and the source file and line number of execution in that frame. The second line shows the text of that source line.

For example:

 
bashdb<8> up
19:	sourced_fn
bashdb<8> T
##0 in file `./bashtest-sourced' at line 8
->1 sourced_fn() called from file `bashtest-sourced' at line 19
##2 source() called from file `bashdb-test1' at line 23
##3 fn2() called from file `bashdb-test1' at line 33
##4 fn1() called from file `bashdb-test1' at line 42
##5 main() called from file `bashdb-test1' at line 0

After such a printout, the list command with no arguments prints ten lines centered on the point of execution in the frame. See section Printing source lines.

frame args

The frame command allows you to move from one stack frame to another, and to print the stack frame you select. args is the the stack frame number. Without an argument, frame prints the current stack frame.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.7 Examining Source Files (`list')

the BASH debugger can print parts of your script's source. When your script stops, the BASH debugger spontaneously prints the line where it stopped. Likewise, when you select a stack frame (see section Selecting a frame), the BASH debugger prints the line where execution in that frame has stopped. You can print other portions of source files by explicit command.

If you use the BASH debugger through its GNU Emacs interface, you may prefer to use Emacs facilities to view source; see Using the BASH debugger under GNU Emacs.

To print lines from a source file, use the list command (abbreviated l). By default, ten lines are printed. There are several ways to specify what part of the file you want to print.

Here are the forms of the list command most commonly used:

list linenum
l linenum

Print lines centered around line number linenum in the current source file.

list function
l function

Print the text of function.

list
l

Print more lines. If the last lines printed were printed with a list command, this prints lines following the last lines printed; however, if the last line printed was a solitary line printed as part of displaying a stack frame (see section Examining the Stack), this prints lines centered around that line.

list -
l -

Print lines just before the lines last printed.

By default, the BASH debugger prints ten source lines with any of these forms of the list command. You can change this using set listsize:

set listsize count

Make the list command display count source lines (unless the list argument explicitly specifies some other number).

show listsize

Display the number of lines that list prints.

Repeating a list command with RET discards the argument, so it is equivalent to typing just list. This is more useful than listing the same lines again. An exception is made for an argument of `-'; that argument is preserved in repetition so that each repetition moves up in the source file.

In general, the list command expects you to supply a linespecs. Linespecs specify source lines; there are several ways of writing them, but the effect is always to specify some source line.

Here is a complete description of the possible arguments for list:

list linespec

Print lines centered around the line specified by linespec.

list first increment

Print increment lines starting from first

list first

Print lines starting with first.

list -

Print lines just before the lines last printed.

list .

Print lines after where the script is stopped.

list

As described in the preceding table.

Here are the ways of specifying a single source line--all the kinds of linespec.

number

Specifies line number of the current source file. When a list command has two linespecs, this refers to the same source file as the first linespec.

filename:number

Specifies line number in the source file filename.

function

Specifies the line that function function is listed on.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.8 Searching source files (`search', `reverse', `/.../', `?..?')

There are two commands for searching through the current source file for a BASH extended pattern-matching expression.

forward bash-pattern
search bash-pattern

The command `forward bash-pattern' checks each line, starting with the one following the current line, for a match for bash-pattern which is an extended bash pattern-matching expression. It lists the line that is found. You can use the synonym `search bash-pattern' or abbreviate the command name as fo or /pat/.

reverse bash-pattern

The command `reverse bash-pattern' checks each line, starting with the one before the last line listed and going backward, for a match for bash-pattern. It lists the line that is found. You can abbreviate this command as rev or ?bash-pattern?.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9 Examining Data (`print', `examine', `info variables')

One way to examine string data in your script is with the print command (abbreviated p). However a more versatile print command is x; it can print variable and function definitions and can do arithmetic computations. Finally, the most general method would be via eval echo.

print expr

Use print to display strings as you would from echo. And as such, variable names to be substituted have to be preceded with a dollar sign. As with echo, filename expansion, e.g. tilde expansion, is performed on unquoted strings. So for example if you want to print a *, you would write `print "*"', not `print *'. If you want to have the special characters dollars sign appear, use a backslash.

 
bashdb<0> print the value of x is $x
the value of x is 22
bashdb<1> p The home directory for root is ~root
The home directory for root is /root
bashdb<2> p '*** You may have won $$$ ***'
*** You may have won $$$ ***
bashdb<3> # Note the use of the single quotes.
bashdb<3> # Compare what happens with double quotes or no quotes
print
p

If you omit expr, the BASH debugger displays the last expression again.

x variable1 [variable2...]
x expr

This is a smarter, more versatile "print" command, and although sometimes it might not be what you want, and you may want to resort to either print or eval echo....

As with print, if you omit expr, the BASH debugger displays the last expression again.

The x command first checks if expr is variable or a list of variables delimited by spaces. If it is, the definition(s) and value(s) of each printed via BASH's declare -p command. This will show the variable's attributes such as if it is read only or if it is an integer. If the variable is an array, that is show and the array values are printed.

If instead expr is a function, the function definition is printed via BASH's declare -f command. If expr was neither a variable nor an expression, then we try to get a value via let. And if this returns an error, as a last resort we call print and give what it outputs.

Since let may be used internally and since (to my thinking) let does funny things, the results may seem odd unless you understand the sequence tried above and how let works. For "example if the variable foo has value 5, then `x foo' shows the definition of foo with value 5, and `x foo+5' prints 10 as expected. So far so good. However if foo is has the value `alpha', `x foo+5' prints 5 because let has converted the string `alpha' into the numeric value 0. So `p foo+5' will simply print "foo+5"; if you want the value of "foo" substituted inside a string, for example you expect "the value of foo is $foo" to come out "the value of foo is 5", then the right command to use is print rather than x, making sure you add the dollar onto the beginning of the variable.

 
bashdb<0> examine x y
declare -- x="22"
declare -- y="23"
bashdb<1> examine x+y
45
bashdb<2> x fn1
fn1 () 
{ 
    echo "fn1 here";
    x=5;
    fn3
}
bashdb<2> x FUNCNAME
declare -a FUNCNAME='([0]="_Dbg_cmd_x" [1]="_Dbg_cmdloop" [2]="_Dbg_debug_trap_handler" [3]="main")'
V [!][pattern]

If you want to all list variables and values or a set of variables by pattern, use this command.

 
bashdb<0> V dq*
dq_args="dq_*"
dq_cmd="V"
bashdb<1> V FUNCNAME
FUNCNAME='([0]="_Dbg_cmd_list_variables" [1]="_Dbg_cmdloop" [2]="_Dbg_debug_trap_handler" [3]="main")'

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.10 Running Arbitrary BASH and Shell commands (`eval', `shell')

The two most general commands and most "low-level" are eval and shell.

eval
e

In contrast to the commands of the last section the most general way to examine data is through eval. But you do much more with this; you can change the values of variables, since, you are just evaluating BASH code.

If you expect output, you should arrange that in the command, such as via echo or printf. For example, to print the value of foo, you would type `e echo $foo'. This is bit longer than `p $foo' or (when possible) `x foo'. However suppose you wanted to find out how the builtin test operator `[' works with the `-z' test condition. You could use eval to do this such as `e [ -z "$foo"] && echo "yes"'.

shell command string
!!

If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend the BASH debugger; you can just use the shell command or its alias !!.

Invoke a shell to execute command string.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.11 Interfacing to the OS (`cd', `pwd')

cd

Set working directory to directory for debugger and program being debugged. The change does not take effect for the program being debugged until the next time it is started.

pwd

Prints the working directory as the program sees things.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.12 Automatic display (`display', `undisplay')

If you find that you want to print the value of an expression frequently (to see how it changes), you might want to add it to the automatic display list so that the BASH debugger evaluates a statement each time your program stops. Each expression added to the list is given a number to identify it; to remove an expression from the list, you specify that number. The automatic display looks like this:

 
2 (echo $x): 38

This display shows item numbers, expressions and their current values.

display expr

Add the expression expr to the list of expressions to display each time your program stops.

undisplay dnums�
delete display dnums�

Remove item numbers dnums from the list of expressions to display.

undisplay does not repeat if you press RET after using it. (Otherwise you would just get the error `No display number �'.)

disable display dnums�

Disable the display of item numbers dnums. A disabled display item is not printed automatically, but is not forgotten. It may be enabled again later.

enable display dnums�

Enable display of item numbers dnums. It becomes effective once again in auto display of its expression, until you specify otherwise.

display

Display the current values of the expressions on the list, just as is done when your program stops.

info display

Print the list of expressions previously set up to display automatically, each one with its item number, but without showing the values. This includes disabled expressions, which are marked as such. It also includes expressions which would not be displayed right now because they refer to automatic variables not currently available.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13 Controlling bashdb (`set', `file', `prompt', `history'...)

You can alter the way BASH interacts with you in various ways given below.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.1 Annotation Level (`set annotate')

set annotate integer

The annotation level controls how much information the BASH debugger prints in its prompt; right new it just controls whether we show full filenames in output or the base part of the filename without path information. Level 0 is the normal, level 1 is for use when the BASH debugger is run as a subprocess of GNU Emacs of DDD, level 2 is the maximum annotation suitable for programs that control the BASH debugger.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.2 File basename (`set basename')

set basename [ on | 1 ]

Source filenames are shown as the basename only. This is useful in running the regression tests.

set basename [ off | 0 ]

Source filenames are shown as with their full path. This is the default.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.3 Allow Debugging the debugger (`set debugger')

set debugger [ on | 1 ]

Allow the possibility of debugging this debugger. Somewhat of an arcane thing to do. For gurus, and even he doesn't use it all that much.

set debugger [ off | 0 ]

Don't allow debugging into the debugger. This is the default.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.4 Specifying a Script-File Association (`file')

Sometimes the BASH debugger gets confused about where to find the script source file for the name reported to it by bash. To resolve relative file names that bash supplies via BASH_SOURCE, the BASH debugger uses the current working directory when the debugged script was started as well as the current working directory now (which might be different if a "cd" command was issued to change the working directory).

However somethimes this doesn't work and there is a way to override this.

file script-file

Directs the BASH debugger to use script-file whenever bash would have it refers to the filename given in BASH_SOURCE. The filename specified in BASH_SOURCE that gets overriden is shown when is this command is issued.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.5 Show position information as statements are executed (`set linetrace')

BASH has set -x tracing to show commands as they are run. However missing from this is file and line position information. So the debugger compensates here for what I think is deficiency of BASH by providing this information. The downside is that this tracing is slower than the built-in tracing of BASH.

The status of whether line tracing is enabled can be show via show linetrace.

set linetrace [ on | 1 ]

Turn on line tracing.

set linetrace [ off | 0 ]

Turn off line tracing.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.6 Logging output (`set logging', `set logging file'...)

You may want to save the output of the debugger commands to a file. There are several commands to control the debuggers's logging.

set logging

Prints set logging usage.

set logging [ on | 1 ]

Enable or Disable logging.

set logging file filename

Change the name of the current logfile. The default logfile is `bashdb.txt'.

set logging overwrite [ on | 1 ]

By default, the debugger will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead.

set logging redirect [ on | 1 ]

By default, the debugger output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file.

show logging

Show the current values of the logging settings.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.7 Prompt (`set prompt', `show prompt')

The BASH debugger indicates its readiness to read a command by printing a string called the prompt. This string is normally:

 
bashdb${_Dbg_less}${#_Dbg_history[@]}${_Dbg_greater}$_Dbg_space

When variables inside the the prompt string are evaluated, the above becomes something like `bashdb<5>' if this is the fifth command executed or perhaps `bashdb<<2>>' if you have called the debugger from inside a debugger session and this is the second command inside the debugger session or perhaps `bashdb<(6)>' if you entered a subshell after the fifth command.

You can change the prompt string with the set prompt command, although it is not normally advisable to do so without understanding the implications. If you are using the DDD GUI, it changes the changes the prompt and should not do so. In certain other circumstances (such as writing a GUI like DDD), it may be is useful to change the prompt.

Note: set prompt does not add a space for you after the prompt you set. This allows you to set a prompt which ends in a space or a prompt that does not. Furthermore due to a implementation limitation (resulting from a limitation of the bash built-in function "read"), to put a space at the end of the prompt use the `$_Dbg_space' variable.

set prompt newprompt

Directs the BASH debugger to use newprompt as its prompt string henceforth.

Warning: changing the prompt can DDD's ability to understand when the debugger is waiting for input.

show prompt

Prints a line of the form: `bashdb's prompt is: your-prompt'


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.8 Command editing (`set editing', `show editing')

the BASH debugger reads its input commands through bash which uses via the readline interface. This GNU library provides consistent behavior for programs which provide a command line interface to the user. Advantages are GNU Emacs-style or vi-style inline editing of commands, csh-like history substitution, and a storage and recall of command history across debugging sessions.

You may control the behavior of command line editing in BASH with the command set.

set editing
set editing [ on | 1 ]

Enable command line editing (enabled by default).

set editing [ off | 0 ]

Disable command line editing.

show editing

Show whether command line editing is enabled.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.9 Command Display (`set showcommand')

The debugger normally lists the line number and source line of the for the statement to be next executed. Often this line contains one expression or one statement and it is clear from this line what's going to happen. However BASH allows many expressions or statements to be put on a single source line; some lines contain several units of execution. Some examples of this behavior are listed below:

 
x=1; y=2; x=3
(( x > 5 )) && x=5
y=`echo *`

In the first line of the example above, we have three assignment statements on a single line. In the second line of the example above we have a statement which gets run only if a condition tests true. And in the third line of the example above, we have a command that gets run and then the output of that is substituted in an assignemnt statement. If you were single stepping inside the debugger, each line might get listed more than once before each of the actions that might get performed. (In the case of the conditional statement, the line gets listed only once when the condition is false.)

In order to assist understanding where you are, the enhanced version of BASH maintains a dynamic variable BASH_COMMAND that contains piece of code next to be run (or is currently being run). The debugger has arranged to save this and can display this information or not. This is controlled by set showcommand.

set showcommand [auto | on | 1 | off | 0 ]

controls whether or not to show the saved BASH_COMMAND for the command next to be executed.

When the value is auto the following heuristic is used to determine whether or not to display the saved BASH_COMMAND. If the last time you stopped you were at the same place and the command string has changed, then show the command. When the value on is used, the debugger always shows BASH_COMMAND and when off is used, the debugger nevers shows BASH_COMMAND. Note that listing the text of the source line is independent of whether or not the command is also listed.

Some examples:

 
set showcommand auto      This is the default
set showcommand on        Always show the next command to be executed
set showcommand off       Never show the next command to be executed

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.10 Command history (`H', `history', `!')

The BASH debugger can keep track of the commands you type during your debugging sessions, so that you can be certain of precisely what happened. If the prompt has not been changed (see Prompt), the history number that will be in use next is by default listed in the debugger prompt. Invalid commands and history commands are not saved on the history stack.

H [start-number [end-number]]
H [-count]
![-]n:p

You can list what is in the history stack with H. Debugger commands in ths history stack are listed from most recent to least recent. If no start-number is given we start with the most recently executed command and end with the first entry in the history stack. If start-number is given, that history number is listed first. If end-number is given, that history number is listed last. If a single negative number is given list that many history commands.

An alternate form is !n:p or !-n:p where n is an integer. If a minus sign is used, n is taken as the count to go back from the end rather than as a absolute history number. In contrast H, this form only prints a single history item.

Some examples:

 
H      List entire history
H -2   List the last two history items
!-2:p  List a single history item starting at the same place as above
H 5    List history from history number 5 to the begining (number 0)
H 5 0  Same as above
H 5 3  List history from history number 5 down to history number 3
!5:p   List a single history item 5
history [[-]n]
![-]n

Use this command to reexecute a given history number. If no number is given, the last debugger command in the history is executed.

An alternate form is !n or !-n where n is an integer.

If a minus sign is used in in either form, n is taken as the count to go back from the end rather than as a absolute history number.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.13.11 Command Completion (`complete')

The complete args command lists all the possible completions for the beginning of a command. We can also show completions for set, show and info subcommands. Use args to specify the beginning of the command you want completed. For example:

 
complete d

results in:

 
d
debug
delete
disable
display
deleteall
down

And

 
complete set a

results in:

 
set args
set annotate

This is intended for use by front-ends such as GNU Emacs and DDD.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5. Using the BASH debugger from a front-end user interface

There are some front-ends that can use the BASH debugger as a back-end debugger.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 Using the BASH debugger from GNU Emacs

A special interface allows you to use GNU Emacs to view (and edit) the source files for the program you are debugging with the BASH debugger. However you must be using GNU Emacs version 21 or greater. (M-x show-emacs-version inside GNU Emacs will tell you what version you are running.)

To use this interface, use the command M-x bashdb in GNU Emacs. Give the executable file you want to debug as an argument. Make sure to use the version that comes with this package as this is newer than that supplied with GNU Emacs.

The bashdb command starts the BASH debugger as a subprocess of Emacs, with input and output through a newly created Emacs buffer.

Using the BASH debugger under Emacs is just like using the BASH debugger normally except for two things:

This applies both to the BASH debugger commands and their output, and to the input and output done by the program you are debugging.

This is useful because it means that you can copy the text of previous commands and input them again; you can even use parts of the output in this way.

All the facilities of GNU Emacs' Shell mode are available for interacting with your script. In particular, you can send signals the usual way--for example, C-c C-c for an interrupt, C-c C-z for a stop.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1.1 Commands from the GUD buffer

Each time the BASH debugger displays a stack frame, Emacs automatically finds the source file for that frame and puts an arrow (`=>') at the left margin of the current line. Emacs uses a separate buffer for source display, and splits the screen to show both your the BASH debugger session and the source.

Explicit the BASH debugger list or search commands still produce output as usual, but you probably have no reason to use them from GNU Emacs.

Warning: If the directory where your script resides is not your current directory, it can be easy to confuse Emacs about the location of the source files, in which case the auxiliary display buffer does not appear to show your source. the BASH debugger can find programs by searching your environment's PATH variable, so the the BASH debugger input and output session proceeds normally; but Emacs does not get enough information back from the BASH debugger to locate the source files in this situation. To avoid this problem, either start the BASH debugger mode from the directory where your script resides, or specify an absolute file name when prompted for the M-x gdb argument.

A similar confusion can result if you use the the BASH debugger file command to switch to debugging a program in some other location, from an existing the BASH debugger buffer in Emacs.

By default, M-x bashdb calls the bash --debugger. If you need to call the BASH debugger by a different name (for example, if you keep several configurations around, with different names) you can set the Emacs variable gud-bashdb-command-name; for example,

 
(setq gud-bashdb-command-name "bash --debugger")

(preceded by M-: or ESC :, or typed in the *scratch* buffer, or in your `.emacs' file) makes Emacs call the program named "bash-debugger" instead.

In the the BASH debugger I/O buffer, you can use the Emacs commands listed below in addition to the standard Shell mode commands. The I/O buffer name name is usually *gud-script-name*, where script-name is the name of the script you are debugging.

Many of the commands listed below are also bound to a second key sequence which also can be used in the also be used in the source script. These are listed in Commands from the source script.

C-h m

Describe the features of Emacs' the BASH debugger Mode.

C-c C-f

Execute until exit from the selected stack frame. The Same as the BASH debugger finish command. The GNU Emacs command name is gud-finish and C-x C-a f C-f is an alternate binding which also can be used in the source script. See section Finish (`finish').

C-c C-l

Resynchronize the current position with the source window. The GNU Emacs command name is gud-refresh and C-x C-a C-l is an alternate binding which also can be used in the source script.

C-c C-n

Execute to next source line in this function, skipping all function calls. Same as the BASH debugger next command. The GNU Emacs command name is gud-next and C-x C-a n is an alternate binding which also can be used in the source script. See section Next (`next').

With a numeric argument, run that many times. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

C-c C-r

Continue execution of your script Same as the BASH debugger continue command. The GNU Emacs command name is gud-cont and C-x C-a C-r is an alternate binding which also can be used in the source script. See Continue (`continue').

C-c C-s

Step one source line. Same as the BASH debugger step command. The GNU Emacs command name is gud-step and C-x C-a C-s is an alternate binding which can be used in the source script. See section Step (`step').

With a numeric argument, run that many times. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

C-c >

Go down a stack frame. Same as the BASH debugger down. With a numeric argument, go down that many stack frames. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

The GNU Emacs command name is gud-down and C-x C-a > is an alternate binding which can be used in the source script.

C-c <

Go up a stack frame. With a numeric argument, go up that many stack frames. Same the BASH debugger up command. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

The GNU Emacs command name is gud-up and C-x C-a < is an alternate binding which can be used in the source script.

C-c a

Shows argument variables (e.g. $1, $2) of the current stack frame. Same as the BASH debugger info args command. The GNU Emacs command name is gud-args and C-x C-a a is an alternate binding which also can be used in the source script.

C-c R

Restart or run the script. Same as the BASH debugger run command. The GNU Emacs command name is gud-finish and C-x C-a R is an alternate binding which also can be used in the source script.

C-c T

Show stack trace. Same as the BASH debugger where command. The GNU Emacs command name is gud-where and C-x C-a T is an alternate binding which can be used in the source script. See section Backtraces (`where').

In any source file, the Emacs command C-x SPC (gud-break) tells the BASH debugger to set a breakpoint on the source line point is on.

If you accidentally delete the source-display buffer, an easy way to get it back is to type the command frame in the the BASH debugger buffer, to request a frame display; when you run under Emacs, this recreates the source buffer if necessary to show you the context of the current frame.

The source files displayed in Emacs are in ordinary Emacs buffers which are visiting the source files in the usual way. You can edit the files with these buffers if you wish; but keep in mind that the BASH debugger communicates with Emacs in terms of line numbers. If you add or delete lines from the text, the line numbers that the BASH debugger knows cease to correspond properly with the code.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1.2 Commands from the source script

C-x SPC

tells the BASH debugger to set a breakpoint on the source line point is on. (gud-break)

C-x C-a t

gud-linetrace

C-x C-a C-f

Restart or run the script. Same as the BASH debugger run command. The GNU Emacs command name is gud-finish. In the corresponding I/O buffer, C-c R is an alternate binding.

C-x C-a T

Show stack trace. Same as the BASH debugger where command. In the corresponding I/O buffer, C-c T is an alternate binding. See section Backtraces (`where').

C-x C-a <

Go up a stack frame. With a numeric argument, go up that many stack frames. Same the BASH debugger up command. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

The GNU Emacs command name is gud-up. In the corresponding I/O buffer, C-c < is an alternate binding.

C-x C-a >

Go down a stack frame. Same as the BASH debugger down. With a numeric argument, go down that many stack frames. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

The GNU Emacs command name is gud-down. In the corresponding I/O buffer, C-c > is an alternate binding.

C-x C-a C-t

gud-tbreak

C-x C-a C-s

Step one source line. Same as the BASH debugger step command. See section Step (`step').

With a numeric argument, run that many times. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

The GNU Emacs command name is gud-step. In the corresponding I/O buffer, C-c C-s is an alternate binding.

C-x C-a C-e

gud-statement

C-x C-a R

Restart or run the script. Same as the BASH debugger run command. The GNU Emacs command name is gud-run. In the corresponding I/O buffer, C-c R is an alternate binding.

C-x C-a C-d

Delete breakpoint. gud-remove

C-x C-a C-p

gud-print

C-x C-a C-n

Execute to next source line in this function, skipping all function calls. Same as the BASH debugger next command. With a numeric argument, run that many times. See (Emacs)Arguments section `Numeric Arguments' in The GNU Emacs Manual.

The GNU Emacs command name is gud-next. In the corresponding I/O buffer, C-c C-n is an alternate binding.

C-x C-a f C-f

gud-finish

C-x C-a C-r

Continue execution of your script Same as the BASH debugger continue command. The GNU Emacs command name is gud-cont. In the corresponding I/O buffer, C-c C-r is an alternate binding. See Continue (`continue').

C-x C-a C-b

gud-break

C-x C-a a

gud-args Shows argument variables (e.g. $1, $2) of the current stack frame. Same as the BASH debugger info args command. The GNU Emacs command name is gud-args. In the corresponding I/O buffer, C-c a is an alternate binding which also can be used in the source script.

C-x C-a C-l

Move to current position in this source window. The GNU Emacs command name is gud-refresh. In the corresponding I/O buffer, C-c C-l is an alternate binding.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1.3 the BASH debugger from a GNU Emacs Shell

It is also possible in GNU emacs to use a regular ("comint") shell and set a mode to watch for the BASH debugger prompts. To do this, in Emacs issue the command (from M-x) turn-on-bashdbtrack. There is some overhead involved in scanning output, so if you are not debugging bash programs you probably want to turn this off which can be done via the M-x turn-off-bashdbtrack command.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2 Using the BASH debugger from DDD

the BASH debugger support is rather new in DDD. As a programming language, the BASH debugger is not feature rich: there are no record structures or hash tables (yet), no pointers, package variable scoping or methods. So much of the data display and visualization features of DDD are disabled.

As with any scripting or interpreted language (e.g. Perl), one can't step by a single machine-language instruction. So the ddd Stepi/Nexti commands are disabled.

Some BASH settings are essential for DDD to work correctly. These settings with their correct values are:

 
set annotate 1
set prompt set prompt bashdb$_Dbg_less$_Dbg_greater$_Dbg_space

DDD sets these values automatically when invoking BASH; if these values are changed, there may be some malfunctions.

Pay special attention when the prompt has extra angle brackets (a nested shell) or has any parenthesis (is in a subshell). Quitting may merely exit out of one of these nested (sub)shells rather than leave the program.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Reporting Bugs

Your bug reports play an essential role in making the BASH debugger reliable.

Reporting a bug may help you by bringing a solution to your problem, or it may not. But in any case the principal function of a bug report is to help the entire community by making the next version of the BASH debugger work better. Bug reports are your contribution to the maintenance of the BASH debugger.

In order for a bug report to serve its purpose, you must include the information that enables us to fix the bug.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Have you found a bug?

If you are not sure whether you have found a bug, here are some guidelines:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 How to report bugs

Bug reports can sent via the sourceforge bug tracking mechansim at http://sourceforge.net/tracker/?group_id=61395&atid=497159. Of course patches are very much welcome too. Those can also be sent via the same mechanism.

The fundamental principle of reporting bugs usefully is this: report all the facts. If you are not sure whether to state a fact or leave it out, state it!

Often people omit facts because they think they know what causes the problem and assume that some details do not matter. Thus, you might assume that the name of the variable you use in an example does not matter. Well, probably it does not, but one cannot be sure. Perhaps the bug is a stray memory reference which happens to fetch from the location where that name is stored in memory; perhaps, if the name were different, the contents of that location would fool the debugger into doing the right thing despite the bug. Play it safe and give a specific, complete example. That is the easiest thing for you to do, and the most helpful.

Keep in mind that the purpose of a bug report is to enable us to fix the bug. It may be that the bug has been reported previously, but neither you nor we can know that unless your bug report is complete and self-contained.

Sometimes people give a few sketchy facts and ask, "Does this ring a bell?" Those bug reports are useless, and we urge everyone to refuse to respond to them except to chide the sender to report bugs properly.

To enable us to fix the bug, you should include all these things:

Here are some things that are not necessary:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. 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 indrectly 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)

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

A. GNU GENERAL PUBLIC LICENSE

Version 2, June 1991

 
Copyright � 1989, 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Preamble

The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.

Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and modification follow.

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".

    Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.

  2. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

    You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

  3. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
    1. You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
    2. You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
    3. If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)

    These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

    Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.

    In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

  4. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
    1. Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
    2. Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
    3. Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)

    The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.

    If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.

  5. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
  6. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
  7. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
  8. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.

    If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.

    It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.

    This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.

  9. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
  10. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

    Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.

  11. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

    NO WARRANTY

  12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.

 
one line to give the program's name and a brief idea of what it does.
Copyright (C) year  name of author

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this when it starts in an interactive mode:

 
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:

 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.

signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice

This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

B. GNU Free Documentation License

Version 1.1, March 2000

 
Copyright (C) 2000  Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

  1. PREAMBLE

    The purpose of this License is to make a manual, textbook, or other written document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

    This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

    We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.


  2. APPLICABILITY AND DEFINITIONS

    This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you."

    A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

    A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (For example, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

    The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License.

    The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License.

    A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, whose contents can be viewed and edited directly and straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent. A copy that is not "Transparent" is called "Opaque."

    Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML designed for human modification. Opaque formats include PostScript, PDF, proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML produced by some word processors for output purposes only.

    The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.

  3. VERBATIM COPYING

    You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

    You may also lend copies, under the same conditions stated above, and you may publicly display copies.

  4. COPYING IN QUANTITY

    If you publish printed copies of the Document numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

    If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

    If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

    It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

  5. MODIFICATIONS

    You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

    A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.
    B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has less than five).
    C. State on the Title page the name of the publisher of the Modified Version, as the publisher.
    D. Preserve all the copyright notices of the Document.
    E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
    F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.
    G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.
    H. Include an unaltered copy of this License.
    I. Preserve the section entitled "History", and its title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
    J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
    K. In any section entitled "Acknowledgements" or "Dedications", preserve the section's title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.
    L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.
    M. Delete any section entitled "Endorsements." Such a section may not be included in the Modified Version.
    N. Do not retitle any existing section as "Endorsements" or to conflict in title with any Invariant Section.

    If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.

    You may add a section entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties-for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

    You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

    The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.

  6. COMBINING DOCUMENTS

    You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice.

    The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

    In the combination, you must combine any sections entitled "History" in the various original documents, forming one section entitled "History"; likewise combine any sections entitled "Acknowledgements", and any sections entitled "Dedications." You must delete all sections entitled "Endorsements."

  7. COLLECTIONS OF DOCUMENTS

    You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

    You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

  8. AGGREGATION WITH INDEPENDENT WORKS

    A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, does not as a whole count as a Modified Version of the Document, provided no compilation copyright is claimed for the compilation. Such a compilation is called an "aggregate", and this License does not apply to the other self-contained works thus compiled with the Document, on account of their being thus compiled, if they are not themselves derivative works of the Document.

    If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one quarter of the entire aggregate, the Document's Cover Texts may be placed on covers that surround only the Document within the aggregate. Otherwise they must appear on covers around the whole aggregate.

  9. TRANSLATION

    Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail.

  10. TERMINATION

    You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

  11. FUTURE REVISIONS OF THIS LICENSE

    The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

    Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

ADDENDUM: How to use this License for your documents

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

 
Copyright (C)  year  your name.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1
or any later version published by the Free Software Foundation;
with the Invariant Sections being list their titles, with the
Front-Cover Texts being list, and with the Back-Cover Texts being list.
A copy of the license is included in the section entitled "GNU
Free Documentation License."

If you have no Invariant Sections, write "with no Invariant Sections" instead of saying which ones are invariant. If you have no Front-Cover Texts, write "no Front-Cover Texts" instead of "Front-Cover Texts being list"; likewise for Back-Cover Texts.

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Function Index


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Command Index

Jump to:   !   #  
B   C   D   E   F   H   I   L   N   P   Q   R   S   T   U   V   W   X  
Index Entry Section

!
!! (shell) 4.10 Running Arbitrary BASH and Shell commands (`eval', `shell')
![-]n (history) 4.13.10 Command history (`H', `history', `!')

#
# (a comment) 4.1 Command syntax

B
b (break) 4.4.1.1 Setting breakpoints (`break' `tbreak')
backtrace 4.6.2 Backtraces (`where')
break 4.4.1.1 Setting breakpoints (`break' `tbreak')
bt (backtrace) 4.6.2 Backtraces (`where')

C
c (continue) 4.4.2.5 Continue (`continue')
cd directory 4.11 Interfacing to the OS (`cd', `pwd')
clear 4.4.1.4 Deleting breakpoints (`clear', `delete')
commands 4.4.1.3 Breakpoint command lists (`commands')
condition 4.4.1.6 Break conditions (`condition')
continue 4.4.2.5 Continue (`continue')

D
d (clear) 4.4.1.4 Deleting breakpoints (`clear', `delete')
de (delete) 4.4.1.4 Deleting breakpoints (`clear', `delete')
debug 4.4.2.6 Debug (`debug')
delete 4.4.1.4 Deleting breakpoints (`clear', `delete')
delete display 4.12 Automatic display (`display', `undisplay')
dis (disable) 4.4.1.5 Disabling breakpoints (`disable', `enable')
disable 4.4.1.5 Disabling breakpoints (`disable', `enable')
disable breakpoints 4.4.1.5 Disabling breakpoints (`disable', `enable')
disable display 4.12 Automatic display (`display', `undisplay')
display 4.12 Automatic display (`display', `undisplay')
do (down) 4.6.3 Selecting a frame (`up', `down', `frame')
down 4.6.3 Selecting a frame (`up', `down', `frame')

E
e (eval) 4.10 Running Arbitrary BASH and Shell commands (`eval', `shell')
enable 4.4.1.5 Disabling breakpoints (`disable', `enable')
enable breakpoints 4.4.1.5 Disabling breakpoints (`disable', `enable')
enable display 4.12 Automatic display (`display', `undisplay')
end 4.4.1.3 Breakpoint command lists (`commands')
eval 4.10 Running Arbitrary BASH and Shell commands (`eval', `shell')
examine 4.9 Examining Data (`print', `examine', `info variables')

F
file 4.13.4 Specifying a Script-File Association (`file')
finish 4.4.2.3 Finish (`finish')
forward 4.8 Searching source files (`search', `reverse', `/.../', `?..?')
frame 4.6.3 Selecting a frame (`up', `down', `frame')

H
h (help) 4.2 Getting help (`help')
H [start-number [end-number]] 4.13.10 Command history (`H', `history', `!')
handle 4.4.3 Signals
history [-][n] 4.13.10 Command history (`H', `history', `!')

I
i (info) 4.2 Getting help (`help')
info 4.2 Getting help (`help')
info args 4.5.1 Showing information about the program being debugged (`info')
info breakpoints 4.4.1.1 Setting breakpoints (`break' `tbreak')
info breakpoints 4.5.1 Showing information about the program being debugged (`info')
info display 4.5.1 Showing information about the program being debugged (`info')
info display 4.12 Automatic display (`display', `undisplay')
info files 4.5.1 Showing information about the program being debugged (`info')
info functions 4.5.1 Showing information about the program being debugged (`info')
info line 4.5.1 Showing information about the program being debugged (`info')
info program 4.5.1 Showing information about the program being debugged (`info')
info signals 4.4.3 Signals
info signals 4.5.1 Showing information about the program being debugged (`info')
info source 4.5.1 Showing information about the program being debugged (`info')
info stack 4.5.1 Showing information about the program being debugged (`info')
info terminal 3.4 Your script's input and output
info terminal 4.5.1 Showing information about the program being debugged (`info')
info variables 4.5.1 Showing information about the program being debugged (`info')
info variables 4.9 Examining Data (`print', `examine', `info variables')

L
l (list) 4.7 Examining Source Files (`list')
list 4.7 Examining Source Files (`list')

N
n (next) 4.4.2.2 Next (`next')
next 4.4.2.2 Next (`next')

P
p (print) 4.9 Examining Data (`print', `examine', `info variables')
print 4.9 Examining Data (`print', `examine', `info variables')
print 4.9 Examining Data (`print', `examine', `info variables')
pwd 4.11 Interfacing to the OS (`cd', `pwd')

Q
q (quit) 4.3 Quitting the BASH debugger (`quit')
quit [expression [subshell-levels]] 4.3 Quitting the BASH debugger (`quit')

R
R (restart) 3.1 Starting your script
restart 3.1 Starting your script
RET (repeat last command) 4.1 Command syntax
return 4.4.2.7 Returning from a function, sourced file, or subshell (`return')
reverse-search 4.8 Searching source files (`search', `reverse', `/.../', `?..?')
run (restart) 3.1 Starting your script

S
s (step) 4.4.2.1 Step (`step')
search 4.8 Searching source files (`search', `reverse', `/.../', `?..?')
set annotate 4.13.1 Annotation Level (`set annotate')
set args 3.3 Your script's arguments
set basename 4.13.2 File basename (`set basename')
set debugger 4.13.3 Allow Debugging the debugger (`set debugger')
set editing 4.13.8 Command editing (`set editing', `show editing')
set linetrace 4.13.5 Show position information as statements are executed (`set linetrace')
set listsize 4.7 Examining Source Files (`list')
set logging 4.13.6 Logging output (`set logging', `set logging file'...)
set prompt 4.13.7 Prompt (`set prompt', `show prompt')
set showcommand 4.13.9 Command Display (`set showcommand')
shell 4.10 Running Arbitrary BASH and Shell commands (`eval', `shell')
show args 3.3 Your script's arguments
show copying 4.5.2 Show information about the debugger (`show')
show editing 4.13.8 Command editing (`set editing', `show editing')
show listsize 4.7 Examining Source Files (`list')
show prompt 4.13.7 Prompt (`set prompt', `show prompt')
show version 4.5.2 Show information about the debugger (`show')
show warranty 4.5.2 Show information about the debugger (`show')
silent 4.4.1.3 Breakpoint command lists (`commands')
skip 4.4.2.4 Skip (`skip')
source 3.2 Command files
step 4.4.2.1 Step (`step')

T
tbreak 4.4.1.1 Setting breakpoints (`break' `tbreak')
tty 3.4 Your script's input and output

U
undisplay 4.12 Automatic display (`display', `undisplay')
up 4.6.3 Selecting a frame (`up', `down', `frame')

V
V (info variables) 4.9 Examining Data (`print', `examine', `info variables')

W
watch 4.4.1.2 Setting watchpoints (`watch', `watche')
where 4.6.2 Backtraces (`where')

X
x (examine) 4.9 Examining Data (`print', `examine', `info variables')

Jump to:   !   #  
B   C   D   E   F   H   I   L   N   P   Q   R   S   T   U   V   W   X  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Variable Index


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

General Index

Jump to:   $   -   .  
A   B   C   D   E   F   G   H   I   L   N   O   P   R   S   T   V   W  
Index Entry Section

$
$_ and info breakpoints 4.4.1.1 Setting breakpoints (`break' `tbreak')

-
--basename 2.1.1 Command-line options for bashdb script
--command 2.1.1 Command-line options for bashdb script
--help 2.1.1 Command-line options for bashdb script
--library 2.1.1 Command-line options for bashdb script
--no-init 2.1.1 Command-line options for bashdb script
--nx 2.1.1 Command-line options for bashdb script
--quiet 2.1.1 Command-line options for bashdb script
--tempdir 2.1.1 Command-line options for bashdb script
--terminal 2.1.1 Command-line options for bashdb script
--tty 2.1.1 Command-line options for bashdb script
-B 2.1.1 Command-line options for bashdb script
-c 2.1.1 Command-line options for bashdb script
-h 2.1.1 Command-line options for bashdb script
-L 2.1.1 Command-line options for bashdb script
-n 2.1.1 Command-line options for bashdb script
-q 2.1.1 Command-line options for bashdb script
-T 2.1.1 Command-line options for bashdb script
-t 2.1.1 Command-line options for bashdb script
-V 2.1.1 Command-line options for bashdb script

.
`.bashdbinit' 3.2 Command files

A
arguments (to your script) 3.3 Your script's arguments
automatic display 4.12 Automatic display (`display', `undisplay')

B
backtraces 4.6.2 Backtraces (`where')
BASH debugger bugs, reporting 6.2 How to report bugs
`bashdb.ini' 3.2 Command files
breakpoint conditions 4.4.1.6 Break conditions (`condition')
breakpoint numbers 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)
breakpoint on variable modification 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)
breakpoints 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)
bug criteria 6.1 Have you found a bug?
bug reports 6.2 How to report bugs
bugs 6. Reporting Bugs

C
call stack 4.6 Examining the Stack (`where', `frame', `up', `down')
change working directory 4.11 Interfacing to the OS (`cd', `pwd')
clearing breakpoints, watchpoints 4.4.1.4 Deleting breakpoints (`clear', `delete')
command files 3.2 Command files
command line editing 4.13.8 Command editing (`set editing', `show editing')
comment 4.1 Command syntax
conditional breakpoints 4.4.1.6 Break conditions (`condition')
continuing 4.4.2 Resuming Execution (`step', `next', `finish', `skip', `continue', `debug', `return')
controlling terminal 3.4 Your script's input and output
crash of debugger 6.1 Have you found a bug?
current stack frame 4.6.3 Selecting a frame (`up', `down', `frame')

D
DDD 5.2 Using the BASH debugger from DDD
debugger crash 6.1 Have you found a bug?
delete breakpoints 4.4.1.4 Deleting breakpoints (`clear', `delete')
deleting breakpoints, watchpoints 4.4.1.4 Deleting breakpoints (`clear', `delete')
display of expressions 4.12 Automatic display (`display', `undisplay')

E
editing 4.13.8 Command editing (`set editing', `show editing')
Emacs 5.1 Using the BASH debugger from GNU Emacs
error on valid input 6.1 Have you found a bug?
examining data 4.9 Examining Data (`print', `examine', `info variables')

F
fatal signal 6.1 Have you found a bug?
fatal signals 4.4.3 Signals
frame number 4.6.1 Stack frames
frame, definition 4.6.1 Stack frames

G
GNU Emacs 5.1 Using the BASH debugger from GNU Emacs

H
handling signals 4.4.3 Signals

I
I/O 3.4 Your script's input and output
init file 3.2 Command files
init file name 3.2 Command files
initial frame 4.6.1 Stack frames
innermost frame 4.6.1 Stack frames
interrupt 2.2 Quitting the BASH debugger
invalid input 6.1 Have you found a bug?

L
latest breakpoint 4.4.1.1 Setting breakpoints (`break' `tbreak')
linespec 4.7 Examining Source Files (`list')

N
numbers for breakpoints 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)
numbers for watchpoints 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)

O
one-time breakpoints 4.4.1.6 Break conditions (`condition')
online documentation 4.2 Getting help (`help')
outermost frame 4.6.1 Stack frames

P
print working directory 4.11 Interfacing to the OS (`cd', `pwd')
printing data 4.9 Examining Data (`print', `examine', `info variables')
prompt 4.13.7 Prompt (`set prompt', `show prompt')

R
readline 4.13.8 Command editing (`set editing', `show editing')
redirection 3.4 Your script's input and output
repeating next/step commands 4.1 Command syntax
reporting bugs 6. Reporting Bugs
resuming execution 4.4.2 Resuming Execution (`step', `next', `finish', `skip', `continue', `debug', `return')
returning from a function, sourced file or subshell 4.4.2.7 Returning from a function, sourced file, or subshell (`return')
running 3.1 Starting your script

S
searching 4.8 Searching source files (`search', `reverse', `/.../', `?..?')
selected frame 4.6 Examining the Stack (`where', `frame', `up', `down')
setting watchpoints 4.4.1.2 Setting watchpoints (`watch', `watche')
shell escape 4.10 Running Arbitrary BASH and Shell commands (`eval', `shell')
signals 4.4.3 Signals
stack frame 4.6.1 Stack frames
stack traces 4.6.2 Backtraces (`where')
starting 3.1 Starting your script
stepping 4.4.2 Resuming Execution (`step', `next', `finish', `skip', `continue', `debug', `return')

T
terminal 3.4 Your script's input and output
tracebacks 4.6.2 Backtraces (`where')

V
version number 4.5.2 Show information about the debugger (`show')

W
watchpoints 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)
watchpoints numbers 4.4.1 Breakpoints, watchpoints (`break', `tbreak', `watch', `watche'...)

Jump to:   $   -   .  
A   B   C   D   E   F   G   H   I   L   N   O   P   R   S   T   V   W  

[Top] [Contents] [Index] [ ? ]

Footnotes

(1)

The DJGPP port of the BASH debugger limitations of file names imposed by DOS filesystems.

(2)

On DOS/Windows systems, the home directory is the one pointed to by the HOME environment variable.


[Top] [Contents] [Index] [ ? ]

Table of Contents


[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated by R. Bernstein on July, 23 2006 using texi2html 1.76.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ < ] Back previous section in reading order 1.2.2
[ > ] Forward next section in reading order 1.2.4
[ << ] FastBack beginning of this chapter or previous chapter 1
[ Up ] Up up section 1.2
[ >> ] FastForward next chapter 2
[Top] Top cover (top) of document  
[Contents] Contents table of contents  
[Index] Index index  
[ ? ] About about (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated by R. Bernstein on July, 23 2006 using texi2html 1.76.