Chapter 14. Debugging awk Programs
It would be nice if computer programs worked perfectly the first time
they were run, but in real life, this rarely happens for programs of any
complexity. Thus, most programming languages have facilities available
for “debugging” programs, and now awk
is
no exception.
The gawk
debugger is purposely
modeled after the GNU Debugger
(GDB) command-line debugger. If you are familiar with GDB, learning how to use gawk
for debugging your program is easy.
Introduction to the gawk Debugger
This section introduces debugging in general and begins
the discussion of debugging in gawk
.
Debugging in General
(If you have used debuggers in other languages, you may want to skip ahead to awk Debugging.)
Of course, a debugging program cannot remove bugs for you, because it has no way of knowing what you or your users consider a “bug” versus a “feature.” (Sometimes, we humans have a hard time with this ourselves.) In that case, what can you expect from such a tool? The answer to that depends on the language being debugged, but in general, you can expect at least the following:
The ability to watch a program execute its instructions one by one, giving you, the programmer, the opportunity to think about what is happening on a time scale of seconds, minutes, or hours, rather than the nanosecond time scale at which the code usually runs.
The opportunity to not only passively observe the operation of your program, but to control it and try different paths of execution, without having ...
Get Effective awk Programming, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.