From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1847 invoked by alias); 31 Aug 2004 15:20:37 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 1837 invoked from network); 31 Aug 2004 15:20:36 -0000 Received: from unknown (HELO tisch.mail.mindspring.net) (207.69.200.157) by sourceware.org with SMTP; 31 Aug 2004 15:20:36 -0000 Received: from user-119a90a.biz.mindspring.com ([66.149.36.10] helo=berman.michael-chastain.com) by tisch.mail.mindspring.net with esmtp (Exim 3.33 #1) id 1C2AR0-0004xz-00; Tue, 31 Aug 2004 11:20:34 -0400 Received: from mindspring.com (localhost [127.0.0.1]) by berman.michael-chastain.com (Postfix) with SMTP id 6B07B4B102; Tue, 31 Aug 2004 11:21:02 -0400 (EDT) Date: Tue, 31 Aug 2004 15:20:00 -0000 From: Michael Chastain To: eliz@gnu.org, cmarkle@sendmail.com Subject: Re: calling glibc mallinfo() from GDB after attaching to a process? Cc: gdb@sources.redhat.com Message-ID: <4134975D.nailH9511JUUH@mindspring.com> References: <4133DDC2.3040403@sendmail.com> <01c48f0e$Blat.v2.2.2$c9e5a100@zahav.net.il> <41340BA3.6020801@sendmail.com> In-Reply-To: <41340BA3.6020801@sendmail.com> User-Agent: nail 10.8 6/28/04 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2004-08/txt/msg00438.txt.bz2 The gdb command you want is: (gdb) print mallinfo() That is, you just say "print EXPRESSION", and EXPRESSION includes subroutine calls. gdb then does a bunch of behind-the-scenes work to make a function call into the inferior. Some people write little stub functions expressly to be called from gdb. If you are having trouble calling mallinfo() directly, try this: int my_mallinfo () { struct mallinfo info = mallinfo(); printf ("arena: %d\n", info.arena); ... return 0; } (gdb) print my_mallinfo() ... That way, you're calling a function in your program instead of a shared library, and the function returns an int rather than a struct. Both of these things make gdb work better, and avoid errors like this: (gdb) print mallinfo() Program received signal SIGSEGV, Segmentation fault. 0x4207512d in mallinfo () from /lib/i686/libc.so.6 The program being debugged was signaled while in a function called from GDB. GDB remains in the frame where the signal was received. To change this behavior use "set unwindonsignal on" Evaluation of the expression containing the function (mallinfo) will be abandoned. Sample code attached. === #include #include #include int main () { malloc (10); malloc (10); } int my_mallinfo () { struct mallinfo info = mallinfo (); printf ("arena: %d\n", info.arena); return 0; }