Skip to content
mrtalley edited this page Dec 7, 2017 · 1 revision
  • Compile your program with -g to add debugging symbols -ggdb adds even more symbols
  • Starting gdb and emacs gud-gdb mode
    • on command line: gdb <program name>
    • In emacs: M-x gud-gdb
    • In emacs 22 or older: M-x gdb
    • M-x gdb works on later version of emacs, too, but it has changed in ways that I don't understand, while M-x gud-gdb invokes the old, pre-emacs 23 behavior.

GDB Commands

  • run
    • Runs the program
  • backtrace (bt)
    • prints the stack trace (all stack frames)
  • up
    • Move up the stack (toward main())
  • down
    • Moves down (away from main())
  • break
    • Set a breakpoint
    • takes a function name, a line number, or a file:line number, or an address
  • (s)tep
    • Step into a function call
  • (n)ext
    • step over a function call
  • print
    • print a variable
    • 'set print pretty' gives nicer output
  • list
    • list code around the current line
    • Not particularly useful in emacs, but necessary in the shell.
  • (c)ontinue
    • Continue execution
  • clear
    • delete a breakpoint
  • delete
    • delete all breakpoints
Clone this wiki locally