This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Tip of the day: Using Valgrind in the GUD buffer


Here's a trick for running valgrind in the GUD buffer of Emacs so it that can
display the source of the executable at memory violations and examine values
under the control of GDB. With valgrind-2.0.0 at least, the executable could
be gdb, itself.

Note, however, that THIS REQUIRES THE CVS VERSION OF EMACS.

In the directory of the executable that you want to run under valgrind, put the
line:

set ann 1

in a file called .gdbinit (add the line at the end if it already exists). Type 
M-x gdb in the minibuffer and when prompted with (something like):

Run gdb (like this): gdb -fullname

replace it with (if your executable is ~/myprog, say):

Run gdb (like this): valgrind --gdb-attach=yes ~/myprog

At a memory violation, when valgrind asks if you want to atach to gdb, type y:

==19752== ---- Attach to GDB ? --- [Return/N/n/Y/y/C/c] ---- y

The source does not immediately appear but if you type bt, GDB prints the call
stack. This also includes calls to valgrind's code. Identify the frame number
of your code, 6 say, and type:

(gdb) frame 6

and your code should appear. Just as with the command line you can't step through
your code under valgrind but you can move up and down the stack and examine the
values of variables. When you want to return to valgrind type Ctrl-D to quit GDB
but stay in the GUD buffer.


    Nick                                         http://www.nick.uklinux.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]