Which is your favorite macro/trick in gdb? Have you written any good macros for improving language integration? What's your best way of making the debugging experience inside gdb less painful?
(~/.gdb/ptrace)
break ptrace
commands 1
return
continue
end
also check out http://reverse.put.as/2008/11/19/gdbinit-version-70/
One of my favorite tricks is a macro to make it easier to debug Python (CPython to be fair) applications:
define pyp if PyObject_Repr ($arg0) print PyString_AsString(PyObject_Repr($arg0)) end end
extending Johan's answer: for CPython use the "gdbinit" file supplied in its source distribution. it has that and lots more.
Emacs has great support for GDB. To get into gdb-mode, type "M-x gdb".
I like to split the window in two, with my source code in one window, and gdb in the other. Emacs will mark your place in the source code as you step through. In the source code window, you can type "C-x spacebar" to set a breakpoint.
There's a nice introductory tutorial online at http://tedlab.mit.edu/~dr/gdbintro.html
I use gdbtui
all the time. It provides a curses-interface so you can actually see the code you're debugging. When you use the command list
, it will show the code in the upper part of the terminal, and you can scroll up and down. It also shows breakpoints and the current line, and follows you when you step through the program.
Start it with gdbtui
or gdb -tui
. You can also switch between TUI and normal gdb by pressing Ctrl+X, Ctrl+A.
But be careful with stdout
and stderr
. If the debugged program prints something while you are in TUI mode, it will mess up the interface. Either redirect the output when you start the program, or press Ctrl+L to redraw the interface if it is already messed up.