The Science of Debugging
Chapter 6


6.1 Before You Start Using Gdb


Gdb is your debugger for the *nix environment . There aren't many pre-requisites for using it; simply make sure to specify the -g option (debugging) when you compile your program, or when you link multiple object files together (they must have been compiled with the -g option too, of course). Ex:

> gcc -g autowiz.c -o autowiz




CircleMUD's default setup includes this flag by default. If you want to make a potentially sleeker, smaller, build with a smaller memory footprint, you can remove this option. Personally speaking, I've only ever had this problem once, and I was doing some pretty tricky stuff. Normally compiler optimizations are pretty safe, and you shouldn't have to question them.

Note that sometimes including the optimization flags (-O# where # is 1 or 2 usually) can cause subtle inconsistencies while debugging; in rare cases, optimization can also cause crashes that cannot be duplicated without the optimization flags on! This can put you in a catch 22, if you cannot get accurate debugging results with optimization turned on, but cannot reproduce the error without it!

Use logging to locate your area of interest, and attempt to isolate or rewrite the code in a more 'normal' manner; if you're doing something tricky, you may end up confusing the optimizing compiler.



Index
6 - Debugging Using gdb 6.2 Starting Gdb