GDB: an introduction gdb (GNU DeBugger) is invaluable for debugging large C/C++ programs. gdb adds the debugging power of an interpreted language to C/C++. There is also a graphical version, ddd (which appears not to work on CCIS Solaris machines as of Sept., 2004?). For Java, there is also a somewhat less mature cousin, jdb. Another alternative for Java is to use GNU gcj to compile the programs and GNU gdb (version 5.1 or greater) to debug the program. A tutorial for gdb/gcj is at: http://www.gnu.org/software/gcc/java/gdb.html To use gdb, you should first re-compile your source code using the `-g' flag. It is also helpful to also use `-O0' (optimize at level zero), since otherwise an optimization may delete or move a line of source code. Note that a program compiled with `-O0' runs 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) works Most gdb commands can be abbreviated. Try the abbreviations: e.g.: n = next, s = step, c = continue, p = print, ... The most important commands in gdb are (roughly in order of importance): RUN AND EXAMINE BUG: help, run, where, list, up, down, print, ptype SET BREAKPOINT AND STEP THROUGH: help breakpoints, break, next, step, finish, continue ===================================================================== EXAMPLES OF USAGE: 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) ^C (control-C) (Type this if in an infinite loop, and GDB will stop the process at some line number.) quit ADVANCED COMMANDS: 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