why does ptype require malloc on the inferior?

David Taylor <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.