Saturday, March 1, 2008

debugging with gdb

1. compile source with "-g" flag
  • gcc -g debugme.c
2. execute gdb
  • shell# gdb debugme

where "debugme" is the target executable to be debugged, which is compiled with "-g" flag.
you will then enter the "gdb>" shell

3. add breakpoints
  • gdb> b debugme.c:45
  • where 45 is the line number

4. run program with
  • gdb> run argv1 argv2 argv3 argvn

  • where argv1, argv2, argc3,... argvn are the arguments passed to debugme executable.

5. print the value of a variable
  • gdb> print var1

6. delete breakpoints
  • gdb> delete b

7. show help
  • gdb> help

8. search help
  • gdb> apropos breakpoint
  • searching help with a keyword breakpoint

  • gdb> apropos continue
  • searching help with a keyword continue