diff options
author | Patrick Frants <osscontribute@gmail.com> | 2017-10-26 22:26:08 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-10-26 22:26:08 -0400 |
commit | a43f3893f6cb66dfca7f628cd159a008009ad06f (patch) | |
tree | d41cec11fd0d299d17753559770aa1e5701f6d0c /gdb/testsuite/gdb.cp/classes.cc | |
parent | 95904ac43c21694a609b4b8016b7fdfe8c2fc0fb (diff) | |
download | gdb-a43f3893f6cb66dfca7f628cd159a008009ad06f.zip gdb-a43f3893f6cb66dfca7f628cd159a008009ad06f.tar.gz gdb-a43f3893f6cb66dfca7f628cd159a008009ad06f.tar.bz2 |
Fix broken recursion detection when printing static members
Recursion detection for static members was broken. The implementation
uses a growing (and shrinking) obstack object to simulate a stack of
addresses (CORE_ADDR). Pushing addresses is implemented by calling
obstack_grow(), while popping is implemented by calling obstack_free().
The latter is problematic because obstack_free() expects a pointer to
the base of an object. When popping elements of the stack however,
obstack_free() was called with the new top, which potentially is not the
same as the base of the stack. This is unintended use and the effect is
that obstack->next_free and obstack->object_base members are assigned
the value of the new top, which equals an empty stack. Summary: popping
elements would always result in an empty stack, which breaks the
recursion detection.
The fix shrinks the stack using obstack_blank_fast() with a negative
value as described at the bottom of this page:
https://gcc.gnu.org/onlinedocs/libiberty/Extra-Fast-Growing.html "You
can use obstack_blank_fast with a “negative” size argument to make the
current object smaller. Just don’t try to shrink it beyond zero
length—there’s no telling what will happen if you do that. Earlier
versions of obstacks allowed you to use obstack_blank to shrink objects.
This will no longer work."
The reproducer is added to gdb.cp/classes.exp, which fails without this
patch.
gdb/ChangeLog:
* cp-valprint.c (cp_print_value_fields): Use obstack_blank_fast
to rewind obstack.
gdb/testsuite/ChangeLog:
* gdb.cp/classes.exp (test_static_members): Test printing
Outer::instance.
* gdb.cp/classes.c (struct Inner, struct Outer): New.
(Inner::instance, Outer::instance): New.
Diffstat (limited to 'gdb/testsuite/gdb.cp/classes.cc')
-rw-r--r-- | gdb/testsuite/gdb.cp/classes.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc index 50f0740..a650846 100644 --- a/gdb/testsuite/gdb.cp/classes.cc +++ b/gdb/testsuite/gdb.cp/classes.cc @@ -665,6 +665,19 @@ void use_methods () base1 b (3); } +struct Inner +{ + static Inner instance; +}; + +struct Outer +{ + Inner inner; + static Outer instance; +}; + +Inner Inner::instance; +Outer Outer::instance; int main() |