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]

Re: calling glibc mallinfo() from GDB after attaching to a process?


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;
}


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