tags:

views:

175

answers:

5

Hello all,

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

A: 

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

Kinopiko
+1  A: 

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).

pajton
FWIW I prefer GDB's command line interface to the GUI based setups. I suspect this is true for anyone who spends a substantial amount of time in a command line.
stsquad
I prefer gdb -tui when gdb is being used independently of an IDE, and I prefer the Clang Static Analyzer to Valgrind.
Yktula
Ekhm guys, when you downvote, there is this little reminder to post a comment why do you find the answer bad. So, why?
pajton
he is talking about using the GUD interface with gdb in emacs. This is a frontend fully integrated with the editor that shows where you are in the current source file etc. It is not the normal gdb interface. So your answer looks ignorant.
Justin Smith
@Justin I specifically answered the first two questions: "So my question is how do you guys debug the source code ?What programs do you use ?"
pajton
@Justin Did I answer them *wrong* in your opinion?
pajton
You answered the question, but the second half makes it sound like you don't understand the question. He is already using a well integrated frontend to gdb.
Justin Smith
+3  A: 

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

Bastien Léonard
It's `M-x gdb`.
dave
@dave: thanks, I've edited my answer.
Bastien Léonard
+2  A: 

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

momeara
+1  A: 

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.
dave