CSI2100 GDB Debug Cheat Sheet

To compile and load your program into the gdb debugger, please perform the following steps (-g tells clang to add debug information to your executable):
clang -g yourprogram.c
gdb ./a.out

 GDB Commands
 Start the program with no arguments:
 (gdb) run
 (gdb) r
 Start the program with arguments <args>:
 (gdb) run <args>
 (gdb) r <args>
 Exit the debugger:
 (gdb) quit
 Do a source level single step over:
 (gdb) next
 (gdb) n
 Run the program until it reaches to a breakpoint:
 (gdb) continue
 (gdb) c
 Set a breakpoint at main function:
 (gdb) break main
 Set a breakpoint in file test.c at line 12:
 (gdb) break test.c:12
 List all breakpoints:
 (gdb) info break
 Delete a breakpoint:
 (gdb) delete 1
 Set a watchpoint on a variable when it is written to:
 (gdb) watch global_var
 Set a condition on a watchpoint:
 (gdb) watch global_var if global_var == 0
 List all watchpoints:
 (gdb) info break
 Delete a watchpoint:
 (gdb) delete 1
 Display the variables "argc" and "argv" every time you stop:
 (gdb) display argc
 (gdb) display argv