3

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 Answers 5

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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.

Comments

1

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

6 Comments

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.
I prefer gdb -tui when gdb is being used independently of an IDE, and I prefer the Clang Static Analyzer to Valgrind.
Ekhm guys, when you downvote, there is this little reminder to post a comment why do you find the answer bad. So, why?
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 I specifically answered the first two questions: "So my question is how do you guys debug the source code ? What programs do you use ?"
|
-1

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

1 Comment

Using printf to debug is terrible. Not least that you need to recompile and link possibly introducing other bugs. Inefficient, time consuming and a, source of error. Use the debugger. It's why it's there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.