14.2.1 How to Start the Debugger

Starting the debugger is almost exactly like running gawk normally, except you have to pass an additional option, --debug, or the corresponding short option, -D. The file(s) containing the program and any supporting code are given on the command line as arguments to one or more -f options. (gawk is not designed to debug command-line programs, only programs contained in files.) In our case, we invoke the debugger like this:

$ gawk -D -f getopt.awk -f join.awk -f uniq.awk -- -1 inputfile

where both getopt.awk and uniq.awk are in $AWKPATH. (Experienced users of GDB or similar debuggers should note that this syntax is slightly different from what you are used to. With the gawk debugger, you give the arguments for running the program in the command line to the debugger rather than as part of the run command at the debugger prompt.) The -- ends gawk’s command line options. It’s not strictly necessary here, but it is needed if an option to the awk program conflicts with a gawk option. The -1 is an option to uniq.awk.

Instead of immediately running the program on inputfile, as gawk would ordinarily do, the debugger merely loads all the program source files, compiles them internally, and then gives us a prompt:

gawk>

from which we can issue commands to the debugger. At this point, no code has been executed.