diff options
author | Tom Tromey <tromey@redhat.com> | 2012-09-27 16:04:23 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2012-09-27 16:04:23 +0000 |
commit | 7977e5d2a6287c48bbfe41fdc5fc795b58e98dfe (patch) | |
tree | a3010f595c4802223eaaf34634ba36b76a153e77 | |
parent | 807160da3c24f9a8adfb0c2b04352ab56ebc1d61 (diff) | |
download | gdb-7977e5d2a6287c48bbfe41fdc5fc795b58e98dfe.zip gdb-7977e5d2a6287c48bbfe41fdc5fc795b58e98dfe.tar.gz gdb-7977e5d2a6287c48bbfe41fdc5fc795b58e98dfe.tar.bz2 |
Fix https://bugzilla.redhat.com/show_bug.cgi?id=849357
* cp-valprint.c (cp_print_value_fields): Use get_vptr_fieldno.
gdb/testsuite
* gdb.cp/derivation.exp: Add regression test.
* gdb.cp/derivation.cc (class V_base, class V_inter, class
V_derived): New.
(vderived): New global.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/cp-valprint.c | 7 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/derivation.cc | 29 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/derivation.exp | 8 |
5 files changed, 54 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8faa029..fe69ce6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2012-09-27 Tom Tromey <tromey@redhat.com> + + Fix https://bugzilla.redhat.com/show_bug.cgi?id=849357 + * cp-valprint.c (cp_print_value_fields): Use get_vptr_fieldno. + 2012-09-27 Joel Brobecker <brobecker@adacore.com> * sol-thread.c (sol_thread_fetch_registers) diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index c066aa5..e6a99ec 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -210,7 +210,9 @@ cp_print_value_fields (struct type *type, struct type *real_type, { int statmem_obstack_initial_size = 0; int stat_array_obstack_initial_size = 0; - + struct type *vptr_basetype = NULL; + int vptr_fieldno; + if (dont_print_statmem == 0) { statmem_obstack_initial_size = @@ -225,6 +227,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, } } + vptr_fieldno = get_vptr_fieldno (type, &vptr_basetype); for (i = n_baseclasses; i < len; i++) { /* If requested, skip printing of static fields. */ @@ -358,7 +361,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, v, stream, recurse + 1, options); } - else if (i == TYPE_VPTR_FIELDNO (type)) + else if (i == vptr_fieldno && type == vptr_basetype) { int i_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; struct type *i_type = TYPE_FIELD_TYPE (type, i); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6707751..a68f69d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2012-09-27 Tom Tromey <tromey@redhat.com> + + * gdb.cp/derivation.exp: Add regression test. + * gdb.cp/derivation.cc (class V_base, class V_inter, class + V_derived): New. + (vderived): New global. + 2012-09-26 Tom Tromey <tromey@redhat.com> * gdb.dwarf2/dw2-common-block.S: New file. diff --git a/gdb/testsuite/gdb.cp/derivation.cc b/gdb/testsuite/gdb.cp/derivation.cc index 942fcd2..fcd57ce 100644 --- a/gdb/testsuite/gdb.cp/derivation.cc +++ b/gdb/testsuite/gdb.cp/derivation.cc @@ -118,8 +118,37 @@ public: }; +class V_base +{ +public: + virtual void m(); + int base; +}; + +void +V_base::m() +{ +} + +class V_inter : public virtual V_base +{ +public: + virtual void f(); + int inter; +}; + +void +V_inter::f() +{ +} +class V_derived : public V_inter +{ +public: + double x; +}; +V_derived vderived; int A::afoo() { return 1; diff --git a/gdb/testsuite/gdb.cp/derivation.exp b/gdb/testsuite/gdb.cp/derivation.exp index b752b52..a4210d9 100644 --- a/gdb/testsuite/gdb.cp/derivation.exp +++ b/gdb/testsuite/gdb.cp/derivation.exp @@ -176,3 +176,11 @@ gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" { gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.bfoo()" gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.cfoo()" + +# This is a regression test for a bug that caused a crash when trying +# to print the vtbl pointer. We don't care about the output so much +# here (it is tested elsewhere), just that gdb doesn't crash. We test +# "ptype" first because, before the gdb fix, that was the only code +# path calling get_vptr_fieldno. +gdb_test "ptype vderived" "type = .*" +gdb_test "print vderived" " = {.* inter = 0.*x = 0}" |