From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Nick Roberts Newsgroups: gmane.emacs.help Subject: Tip of the day: Using Valgrind in the GUD buffer Date: Fri, 26 Dec 2003 16:34:20 +0000 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <16364.25356.429453.230750@nick.uklinux.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1072457461 20356 80.91.224.253 (26 Dec 2003 16:51:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 26 Dec 2003 16:51:01 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 26 17:50:56 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AZvAu-0001pR-00 for ; Fri, 26 Dec 2003 17:50:56 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AZw7y-0008TP-8o for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Dec 2003 12:51:58 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AZw5f-0007uF-7U for help-gnu-emacs@gnu.org; Fri, 26 Dec 2003 12:49:35 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AZw55-0007hS-SL for help-gnu-emacs@gnu.org; Fri, 26 Dec 2003 12:49:31 -0500 Original-Received: from [194.247.50.193] (helo=nick.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AZw54-0007gc-Os for help-gnu-emacs@gnu.org; Fri, 26 Dec 2003 12:48:59 -0500 Original-Received: by nick.uklinux.net (Postfix, from userid 501) id 5239875FDE; Fri, 26 Dec 2003 16:34:20 +0000 (GMT) Original-To: help-gnu-emacs@gnu.org X-Mailer: VM 6.97 under Emacs 21.2.1 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:15596 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15596 Emacs users may know that the output of valgrind can be parsed by the compilation buffer if the executable it is operating on does not require input. 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. 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