GDB: A Brief Introduction gdb (GNU DeBugger) is invaluable for debugging large C/C++ programs. There is also a somewhat less mature cousin, jdb, for Java. There is also a graphical version, ddd, which is currently available on EDORAS. gdb adds the debugging power of an interpreted language to C/C++. To use gdb, you should first re-compile your source code using the `-g' flag. It is sometimes helpful to also use `-O0' (optimize at level zero), since otherwise an optimization may delete or move a line of source code. However, a program compiled with `-O0' will also run more slowly. For production, recompile without `-O0'. gcc -g -O0 myfile.c g++ -g -O0 myfile.c Then type: gdb a.out These are some basic techniques available throughout gdb: completion repeat last command arrow keys (cursor keys) work Most gdb commands can be abbreviated. Try the abbreviations: e.g.: n = next, s = step, c = continue, p = print, ... This is a list of the most important commands in gdb. help help breakpoints break main run 1234 > myfile.out (Anything after `run' is as if it's on the command line of a call to `a.out') next (next line) step (step inside next function, or next line if no function) finish (finish current function, and stop for commands) list (list lines around current line number) list main print x print x+3 print *(int *)ptr print foo(3) (execute foo(3) and display the result) ptype ptr (print type of variable) break break main (Add breakpoint at beginning of routine main) For C++, note gdb 'MyClass::myfnc( to see all possible member functions for the method MyClass::myfn run (kill current process, start a new one) continue (continue until next breakpoint) quit watch, awatch, rwatch (slower, because tested at every line) attach (attach to a running process. Useful for debugging client/server or master/worker applications.) detach