public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* why does ptype require malloc on the inferior?
@ 2016-02-25 21:57 David Taylor
  0 siblings, 0 replies; only message in thread
From: David Taylor @ 2016-02-25 21:57 UTC (permalink / raw)
  To: gdb

In response to a problem report from one of our users, I've been playing
with ptype and discovered that sometimes it wants to malloc memory in
the inferior.

At first I thought that it might be related to some changes I've made
locally to ptype (to allow you to specify a location).  But, upon
investigation, I've determined that it occurs in a stock GDB.

It occurs in both

    GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1

and

    GNU gdb (GDB) 7.10

(pristine, no local changes, configured for x86_64-unknown-linux-gnu).

[I have not tried it with 7.11 nor with 'top of master'.]

Here's a sample program (greatly simplified from the original):

----------------- start program -----------------------
struct small
{
  void *addr;
  unsigned long long size;
};

struct contain
{
  struct small twice[2];
};

struct big
{
  char array[1000];
} big;

#define bucket (((struct contain *)big.array)->twice)

int
main (void)
{
  if (bucket[1].addr == 0)
    return (0);

  return (1);
}
-----------------  end program  -----------------------

I put it into a file, gdb-ptype.c, and compiled it with:

    gcc -g3 gdb-ptype.c -o gdb-ptype

I started up gdb on the program, and issued the commands:

    break main
    run
    break malloc
    ptype bucket

GDB responded to the ptype command with:

    Breakpoint 2, malloc (n=1000) at dl-minimal.c:93
    93	dl-minimal.c: No such file or directory.
    The program being debugged stopped while in a function called from GDB.
    Evaluation of the expression containing the function
    (malloc) will be abandoned.
    When the function is done executing, GDB will silently stop.

To which my thinking is 'WTF?!?!'.

[The ultimate target system has a *lot* of memory, but no function called
'malloc'.  Which is how it was initially discovered that ptype wants to call
malloc in the inferior...]

To me, this is a bug as I believe that ptype should not be calling
malloc (or any other function for that matter) in the inferior nor, in
general, be mucking about with the inferior.

Do others agree that it is a bug?  Should I open a bug in bugzilla?

Thanks.

David
--
David Taylor
dtaylor at emc dot com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-02-25 21:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-25 21:57 why does ptype require malloc on the inferior? David Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).