开发者

How do you debug c/c++ source code in linux using emacs?

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, F开发者_如何学运维8: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


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


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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜