From: Michael Chastain <mec.gnu@mindspring.com>
To: eliz@gnu.org, cmarkle@sendmail.com
Cc: gdb@sources.redhat.com
Subject: Re: calling glibc mallinfo() from GDB after attaching to a process?
Date: Tue, 31 Aug 2004 15:20:00 -0000 [thread overview]
Message-ID: <4134975D.nailH9511JUUH@mindspring.com> (raw)
In-Reply-To: <41340BA3.6020801@sendmail.com>
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 <malloc.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
malloc (10);
malloc (10);
}
int my_mallinfo ()
{
struct mallinfo info = mallinfo ();
printf ("arena: %d\n", info.arena);
return 0;
}
next prev parent reply other threads:[~2004-08-31 15:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-31 2:09 Chris Markle
2004-08-31 3:58 ` Eli Zaretskii
2004-08-31 5:25 ` Chris Markle
2004-08-31 15:20 ` Michael Chastain [this message]
2004-08-31 16:07 ` Chris Markle
2004-08-31 17:14 ` Michael Chastain
2004-08-31 9:26 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4134975D.nailH9511JUUH@mindspring.com \
--to=mec.gnu@mindspring.com \
--cc=cmarkle@sendmail.com \
--cc=eliz@gnu.org \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox