Debugging C and C++ code entails noticing, localising, understanding and repairing bugs.
You might think that noticing a bug is easy: you know what your code should do, and you notice that it does not do that. This easiness is deceptive. Noticing a bug involves testing. Testing is best done in a disciplined fashion, and, wherever possible, in an automated fashion [1] . For certain types of programs (e.g. compilers) it is relatively easy to construct tests (input + expected output/result) and to run these automatically — say, after each build.
You should prepare tests carefully. Make sure that if a test fails, you can see what goes wrong.
In a Unix system, a bug often manifests itself as a program crash, leaving a core dump. In the section called Core dumps, we will see what a core dump is, and how it can help you in debugging your code.
The GNU C preprocessor This comes with the gcc source in TeXinfo format, and is usually installed in `info' format.
Brian Berliner CVS II: Parallelizing Software Development Included in the CVS source distribution.
Using and Porting GNU CC The gcc and g++ manual; it comes with the gcc source in TeXinfo format, and is usually installed in `info' format.
The GNU make manual This comes with the GNU make source in TeXinfo format, and is usually installed in `info' format.
Paul Haldane Make
Dorothea Ltkehaus and Andreas Zeller DDD — the Data Display Debugger
Brian W. Kernighan and Dennis M. Ritchie The C programming language, second edition Prentice-Hall, 1988.
Ben Zorn Debugging Tools for Dynamic Storage Allocation and Memory Management
Walter F. Tichy RCS — A System for Version Control included with the RCS source distribution.
| [1] |
Unix's powerful scripting abilities come in very handy in this case. |