Debugging C programs with GDB - (GNU DeBugger) All programs to be debugged should be compiled with the -g switch. E.g. gcc -g ex5.c (for C++ use g++ instead of gcc) This includes a Global symbol table and allows the debugger the use variable names instead of memory addresses only. (Note that the -g option also works for javac but in this case you need to use jdb instead of gdb.) To start debugging type gdb At the (gdb) prompt you can type the following commands (and many others). Most commands can be abbreviated to the first letter The new version of gdb seems to require file a.out -- to load the program (could have any name) help -- gives a summary of commands which is a bit overwhelming list -- list 10 lines about where you are l -- ditto RETURN -- list 10 more list 20,40 -- list lines 20 up to 40 list myfun -- list first 10 lines of myfun() break main -- inserts a breakpoint at beginning of main() break 27 -- inserts a breakpoint at start of line 27 -- useful to put a break at key while loops run -- runs program up to crash or end -- input/output redirection and command line arguments are ok run