diff options
author | Pedro Alves <palves@redhat.com> | 2011-02-02 17:41:54 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2011-02-02 17:41:54 +0000 |
commit | 580688f393b43a7456e3bf2857da9c5401e8954f (patch) | |
tree | 0a3e410d5f8c8057b923342ff003021d3e290495 | |
parent | 3d2c1d41d4b6cdaa6052ddfd99b0745cc70c9cbb (diff) | |
download | gdb-580688f393b43a7456e3bf2857da9c5401e8954f.zip gdb-580688f393b43a7456e3bf2857da9c5401e8954f.tar.gz gdb-580688f393b43a7456e3bf2857da9c5401e8954f.tar.bz2 |
gdb/
* c-valprint.c (c_value_print): When doing virtual base pointer
adjustment, create a new value with adjusted contents rather than
changing the contents of the value being printed (and getting it
wrong).
gdb/testsuite/
* gdb.cp/virtbase.cc (VirtualBase, VirtualMiddleA, VirtualMiddleB)
(Virtual): New structs.
(virtual_o, virtual_middle_b): New globals.
* gdb.cp/virtbase.exp: New tests.
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/c-valprint.c | 3 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/virtbase.cc | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/virtbase.exp | 15 |
5 files changed, 61 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index aa694be..b57bbdf 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2011-02-02 Pedro Alves <pedro@codesourcery.com> + * c-valprint.c (c_value_print): When doing virtual base pointer + adjustment, create a new value with adjusted contents rather than + changing the contents of the value being printed (and getting it + wrong). + +2011-02-02 Pedro Alves <pedro@codesourcery.com> + * xml-support.c (xml_find_attribute): New. (xinclude_start_include): Use it. * xml-support.h (xml_find_attribute): Declare. diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 3bd4db2..287dc0b 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -706,8 +706,7 @@ c_value_print (struct value *val, struct ui_file *stream, type = lookup_reference_type (real_type); } /* JYG: Need to adjust pointer value. */ - /* NOTE: cagney/2005-01-02: THIS IS BOGUS. */ - value_contents_writeable (val)[0] -= top; + val = value_from_pointer (type, value_as_address (val) - top); /* Note: When we look up RTTI entries, we don't get any information on const or volatile attributes. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3afe2e5..0b6095c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2011-02-02 Pedro Alves <pedro@codesourcery.com> + + * gdb.cp/virtbase.cc (VirtualBase, VirtualMiddleA, VirtualMiddleB) + (Virtual): New structs. + (virtual_o, virtual_middle_b): New globals. + * gdb.cp/virtbase.exp: New tests. + 2011-01-31 Paul Pluzhnikov <ppluzhnikov@google.com> * gdb.base/jit.exp: New file. diff --git a/gdb/testsuite/gdb.cp/virtbase.cc b/gdb/testsuite/gdb.cp/virtbase.cc index 1e6874f..e23dbda 100644 --- a/gdb/testsuite/gdb.cp/virtbase.cc +++ b/gdb/testsuite/gdb.cp/virtbase.cc @@ -88,6 +88,37 @@ public: RTTI_data() : data(1) {} }; +/* These classes are for testing pointer adjustment when printing a + pointer into a virtual base, with print object on. */ +struct VirtualBase { + int x; + + virtual ~VirtualBase() {} +}; + +struct VirtualMiddleA : public virtual VirtualBase { + /* Make sure the vbase offset of Virtual::VirtualBaseB is larger + than what fits in one byte. */ + int y[300]; + + virtual ~VirtualMiddleA() {} +}; + +struct VirtualMiddleB : public virtual VirtualBase { + int y; + + virtual ~VirtualMiddleB() {} +}; + +struct Virtual : public virtual VirtualMiddleA, public virtual VirtualMiddleB { + int z; + + virtual ~Virtual() {} +}; + +Virtual virtual_o; +VirtualMiddleB *virtual_middle_b = &virtual_o; + int main() { ph::Derived tst; tst.get_y(); diff --git a/gdb/testsuite/gdb.cp/virtbase.exp b/gdb/testsuite/gdb.cp/virtbase.exp index 460c968..4bfec44 100644 --- a/gdb/testsuite/gdb.cp/virtbase.exp +++ b/gdb/testsuite/gdb.cp/virtbase.exp @@ -65,3 +65,18 @@ gdb_test "print/x b->mA" " = 0xaaaaaaaa" # https://bugzilla.redhat.com/show_bug.cgi?id=606660 # `set print object on' is expected. gdb_test "print rtti_data" " = .*, data = 1\}" + +# Printing a pointer into a virtual base of a larger object used to do +# pointer adjusment directly into the value being printed, in-place +# (and did it wrong, too). Print the pointer, and then access the +# value history to check the pointer value is not changed. If it had +# been changed, then we'd not be able to find the real type anymore. +gdb_test "print virtual_middle_b" \ + " = \\(Virtual \\*\\) $hex" \ + "print pointer to virtual base at non-zero offset of larger object" +gdb_test "print $" \ + " = \\(Virtual \\*\\) $hex" \ + "print same pointer from history value" +gdb_test "print *$$" \ + " = \\(Virtual\\) {<VirtualMiddleA> = {<VirtualBase> = {_vptr.VirtualBase = $hex, x = 0}, _vptr.VirtualMiddleA = $hex, y = \\{0 <repeats 300 times>\\}}, <VirtualMiddleB> = {_vptr.VirtualMiddleB = $hex, y = 0}, _vptr.Virtual = $hex, z = 0}" \ + "print whole pointed-to object, starting from the virtual base pointer" |