3
votes

I am using emacs and autotools, to write and compile c/c++ sources on linux.
I am using gdb via GUD in emacs.
I have defined for convenience: F7:compile, F10:gud-next, F11:gud-step, F5:gud-cont, F9:gud-tbreak, F8:gud-until, F4:gud-print.
I am mainly interested in debugging c/c++ source code on linux from emacs and I would like to get the most gdb can give.
Unfortunately I am using only F4 which prints the variable under cursor.

So my question is how do you guys debug the source code ?
What programs do you use ?
What key bindings (functionality) do you use mostly ?
What do you need the debugger to do for you ?
If you do weird stuff it doesn't matter. I would like to know everything to boost my speed a bit here.
Thanks in advance.
Mihai

5

5 Answers

3
votes

I use the M-x gdb... commands to select the windows I need, then I use the gdb prompt.

2
votes

I often set break points with C-x SPC on the source line once gdb is underway,

1
votes

You'll get the most out of gdb by using the command line instead of key bindings. The most useful commands that I use:

  • bt - prints a backtrace; helpful to know full context of where you are
  • s, n, cont - step, next, continue
  • run - very useful for starting over within the same session
  • watch - sets a watchpoint; useful for catching when a value changes
  • call - invoke a function
  • display - Print a value every time the program stops.
1
votes

valgrind is perfect for detecting memory errors. Most of the times you are given the exact location of where the error is.

gdb is nice too, but doesn't have great interface, so it is best to be used with some kind of gui like ddd or Eclipse for instance (yes, I am using gdb with Eclipse, it has built in support for it).

-1
votes

I only use the debugger to get a backtrace on a segmentation fault. For everything else I use printf debugging.