From 55f57e83b2441e93cff7806eaaf3b9c2f5f04e50 Mon Sep 17 00:00:00 2001 From: cmoller Date: Wed, 21 Apr 2010 17:33:51 +0000 Subject: [PATCH] PR 9167 * cp-valprint.c (cp_print_value_fields): Replaced obstack_base() method of popping recursion-detection stack with a method based on obstack_object_size(). * gdb.cp/Makefile.in (EXECUTABLES): Added pr9167. * gdb.cp/pr9167.cc: New file. * gdb.cp/pr9167.exp: New file. --- gdb/ChangeLog | 9 ++++++++- gdb/cp-valprint.c | 23 ++++++++++++++++------- gdb/testsuite/ChangeLog | 8 ++++++++ gdb/testsuite/gdb.cp/Makefile.in | 2 +- gdb/testsuite/gdb.cp/pr9167.cc | 36 ++++++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.cp/pr9167.exp | 31 +++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 gdb/testsuite/gdb.cp/pr9167.cc create mode 100644 gdb/testsuite/gdb.cp/pr9167.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f5a245352d..0ea0d8aec3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2010-04-21 Chris Moller + + PR 9167 + * cp-valprint.c (cp_print_value_fields): Replaced obstack_base() + method of popping recursion-detection stack with a method based on + obstack_object_size(). + 2010-04-21 Pierre Muller PR pascal/11492. @@ -3184,7 +3191,7 @@ addr_bit. Adjust LOAD_ADDR sign for cross-arch inferiors. 2010-02-17 Tristan Gingold - Petr Hluzín + Petr Hluzín * avr-tdep.c (avr_scan_prologue): Convert an if statement to a gdb_assert. Fix info->size for SIG prologue. diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index d3d94d9cd8..c865ba41ad 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -186,14 +186,13 @@ cp_print_value_fields (struct type *type, struct type *real_type, fprintf_filtered (stream, ""); else { - void *statmem_obstack_top = NULL; + int obstack_initial_size = 0; void *stat_array_obstack_top = NULL; if (dont_print_statmem == 0) { - /* Set the current printed-statics stack top. */ - statmem_obstack_top - = obstack_next_free (&dont_print_statmem_obstack); + obstack_initial_size = + obstack_object_size (&dont_print_statmem_obstack); if (last_set_recurse != recurse) { @@ -321,8 +320,19 @@ cp_print_value_fields (struct type *type, struct type *real_type, if (dont_print_statmem == 0) { - if (obstack_object_size (&dont_print_statmem_obstack) > 0) - obstack_free (&dont_print_statmem_obstack, statmem_obstack_top); + int obstack_final_size = + obstack_object_size (&dont_print_statmem_obstack); + + if (obstack_final_size > obstack_initial_size) { + /* In effect, a pop of the printed-statics stack. */ + + void *free_to_ptr = + obstack_next_free (&dont_print_statmem_obstack) - + (obstack_final_size - obstack_initial_size); + + obstack_free (&dont_print_statmem_obstack, + free_to_ptr); + } if (last_set_recurse != recurse) { @@ -555,7 +565,6 @@ cp_print_static_field (struct type *type, addr = value_address (val); obstack_grow (&dont_print_statmem_obstack, (char *) &addr, sizeof (CORE_ADDR)); - CHECK_TYPEDEF (type); cp_print_value_fields (type, value_enclosing_type (val), value_contents_all (val), diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index cc07b6c594..a096256b81 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +Wed Apr 21 12:47:26 2010 Chris Moller + + PR 9167 + * gdb.cp/Makefile.in (EXECUTABLES): Added pr9167. + * gdb.cp/pr9167.cc: New file. + * gdb.cp/pr9167.exp: New file. + + 2010-04-21 Pierre Muller PR pascal/11492. diff --git a/gdb/testsuite/gdb.cp/Makefile.in b/gdb/testsuite/gdb.cp/Makefile.in index 721094da5c..5b00a61131 100644 --- a/gdb/testsuite/gdb.cp/Makefile.in +++ b/gdb/testsuite/gdb.cp/Makefile.in @@ -5,7 +5,7 @@ EXECUTABLES = ambiguous annota2 anon-union cplusfuncs cttiadd \ derivation inherit local member-ptr method misc \ overload ovldbreak ref-typ ref-typ2 templates userdef virtfunc namespace \ ref-types ref-params method2 pr9594 gdb2495 virtfunc2 pr9067 \ - pr1072 pr10687 + pr1072 pr10687 pr9167 all info install-info dvi install uninstall installcheck check: @echo "Nothing to be done for $@..." diff --git a/gdb/testsuite/gdb.cp/pr9167.cc b/gdb/testsuite/gdb.cp/pr9167.cc new file mode 100644 index 0000000000..a0c50021da --- /dev/null +++ b/gdb/testsuite/gdb.cp/pr9167.cc @@ -0,0 +1,36 @@ +#include + +template +struct ATB +{ + int data; + ATB() : data(0) {} +}; + + +template +class A : public ATB +{ +public: + static DerivedType const DEFAULT_INSTANCE; +}; + +template +const DerivedType A::DEFAULT_INSTANCE; + +class B : public A +{ + +}; + +int main() +{ + B b; + // If this if-block is removed then GDB shall + // not infinitely recurse when trying to print b. + + return 0; // marker +} + + diff --git a/gdb/testsuite/gdb.cp/pr9167.exp b/gdb/testsuite/gdb.cp/pr9167.exp new file mode 100644 index 0000000000..7d05ae908a --- /dev/null +++ b/gdb/testsuite/gdb.cp/pr9167.exp @@ -0,0 +1,31 @@ +#Copyright 2010 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set testfile pr9167 +set srcfile ${testfile}.cc +if [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] { + return -1 +} + +if ![runto_main] then { + fail "Can't run to main" + return +} + +gdb_breakpoint [gdb_get_line_number "marker"] +gdb_continue_to_breakpoint "marker" + +gdb_test "p b" "{> = {> = {data = 0}, static DEFAULT_INSTANCE = }, }" + -- 2.11.0