This is the mail archive of the gdb@sourceware.org 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: print/x on references


On 10/18/07, Douglas Evans <dje@google.com> wrote:
> To find the address of the pointer to the object I was thinking "p
> &(&x)".  It works, at least in the simple example I used to experiment
> with.
>
> Am I misunderstanding your point?  [quite likely - apologies]

Heh ... or used too simplistic an example.  Here it is fwiw.

class c
{
  int i;
};

void
foo (c& cref)
{
}

int
main ()
{
  c cobj;
  foo (cobj);
}

dje@ruffy:~/src$ gdb a.out
GNU gdb 6.7.50-20071017-cvs
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b foo
Breakpoint 1 at 0x8048357: file ref-printing.cc, line 9.
(gdb) r
Starting program: /home/dje/src/a.out

Breakpoint 1, foo (cref=@0xffffd864) at ref-printing.cc:9
9       }
(gdb) info frame
Stack level 0, frame at 0xffffd840:
 eip = 0x8048357 in foo(c&) (ref-printing.cc:9); saved eip 0x8048381
 called by frame at 0xffffd870
 source language c++.
 Arglist at 0xffffd838, args: cref=@0xffffd864
 Locals at 0xffffd838, Previous frame's sp is 0xffffd840
 Saved registers:
  ebp at 0xffffd838, eip at 0xffffd83c
(gdb) p cref
$1 = (c &) @0xffffd864: {i = 1334422496}
(gdb) p &cref
$2 = (c *) 0xffffd864
(gdb) p &(&cref)
$3 = (c **) 0xffffd840
(gdb) x/4x $ebp
0xffffd838:     0xffffd868      0x08048381      0xffffd864      0x416ed604
(gdb)


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