Noeud:So What Have We Learned?, Noeud « Previous »:One More Time..., Noeud « Up »:An example debugging session using gdb



So What Have We Learned?

This is the end of the first section of this chapter. We have gone through a simple program with lots of bugs, and seen how to use a debugger to investigate the problem.

We can run the debugger with gdb programname, then run it with parameters using run param1 param2. Breakpoints are inserted with break main or break 34 to force the program to stop at the start of main() or at line 34 respectively.

Once the program has stopped and is under our control, we made it go one step at a time using step or next. At each step we could examine the value of local or global variables which were in scope at that point using print.

We found out what a core dump actually is, and how to examine it to see what caused the program to crash, and where, using gdb programname core. backtrace and up and down are used to move around the stack frames to see what led us to where the program crashed.

We saw how gdb has the power to alter variables while the program is running, to try out potential solutions without having to recompile the whole thing.

Now you know enough to carry out most of the day-to-day debugging most people need to do.

There are two parts to the rest of the chapter - the next one will look at GUI front ends which may make your debugging task easier, then the final one looks at more complicated debugging scenarios - debugging multithreaded code, overloaded C++ functions, making it stop only when it's just about to go wrong, that sort of thing.