next up previous
Next: Coding Style for CS2005 Up: Creating C-Programs Previous: Compiling and Running your

Debugging

For command-line driven development, the most efficient debugging methods are black-box-testing, printing variables, and step-by-step debugging. In black-box testing, the program is tested by giving certain input and comparing the output with what is expected. Many errors can be found in this way. Printing variables helps with more subtle errors. Include simple output statements to the standard error stream (cerr << "loop counter: " << i;) at strategic positions in your code and compare the variable values with what you expect. Sometimes, it helps to just print an asterisk or a number in several places in the source code to see the control flow of the program. Conditional printouts (if (i>10) cerr << "i>10";) can also be useful. This method often helps finding errors in border cases (at the beginning or end of loops), or at rarely used code segments. Step-by-step-debugging is the most powerful tool, but also the hardest to use. On the CCC-machines, the software for step-by-step debugging is the GNU-Debugger gdb. Start gdb with your executable file as a parameter and type help for a command list. The usual way of debugging is to set a breakpoint shortly before the suspected error in the source file and then step through the file with next or step commands.
next up previous
Next: Coding Style for CS2005 Up: Creating C-Programs Previous: Compiling and Running your
Andreas Koeller
2000-06-04