This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
print/x on references
- From: Paul Hilfinger <Hilfinger at adacore dot com>
- To: gdb at sourceware dot org
- Date: Thu, 18 Oct 2007 05:37:36 -0400 (EDT)
- Subject: print/x on references
- Reply-to: Hilfinger at adacore dot com
Currently, there is a slight discrepancy in the behavior of formatted print
commands. Stop the program below in f. At that point, we see the
following behavior:
(gdb) p x
$4 = (Glorp &) @0x8049850: {x = 1, y = 2}
(gdb) p/x x
$5 = 0x8049850
Is there any particular reason these two cases shouldn't have the same
behavior? It seems that printcmd.c:print_formatted is conflating the
cases of C++ pointers and C++ references, and I don't see the justification
for doing so. True, it's easy enough to kludge around:
(gdb) p/x *&x
But it is slightly annoying to have to do this. Admittedly, I'm speaking
more from the Ada camp, where the equivalent kludge is more verbose (and
from the user's point of view, less motivated).
Still, would anyone object if this behavior were to change?
P. Hilfinger
------------------------------------------------------------
#include <iostream>
using namespace std;
struct Glorp {
int x, y;
};
Glorp z = { 1, 2 };
void f (Glorp& x) {
cout << x.x << ", " << x.y << endl;
}
main () {
f(z);
}