From: Chris Moller <cmoller@redhat.com>
To: gdb-patches@sourceware.org
Subject: PR10687 Printing c++ class with static array (of same type) can produce infinite output
Date: Wed, 14 Apr 2010 02:14:00 -0000 [thread overview]
Message-ID: <4BC524E8.404@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
Added yet another recursion detector (the third, so far as I noticed) to
cp-valprint.c. This one detects recursing static arrays which, although
it comes unstuck in the same place as the 9067 recursing static structs,
comes unstuck in a different way and thus needs a slightly different
mechanism to detect.
No regressions.
[-- Attachment #2: pr10687.patch --]
[-- Type: text/x-patch, Size: 7922 bytes --]
? testsuite/gdb.cp/pr10687
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.11610
diff -u -r1.11610 ChangeLog
--- ChangeLog 13 Apr 2010 21:07:15 -0000 1.11610
+++ ChangeLog 14 Apr 2010 01:42:03 -0000
@@ -1,3 +1,10 @@
+2010-04-13 Chris Moller <cmoller@redhat.com>
+
+ * cp-valprint.c (global): Adding new static array recursion
+ detection obstack.
+ (cp_print_value_fields, cp_print_static_field): Added new static
+ array recursion detection code.
+
2010-04-13 Mark Kettenis <kettenis@gnu.org>
* i386-linux-tdep.c (i386_linux_regset_sections): Remove extended
Index: cp-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-valprint.c,v
retrieving revision 1.64
diff -u -r1.64 cp-valprint.c
--- cp-valprint.c 8 Feb 2010 18:04:16 -0000 1.64
+++ cp-valprint.c 14 Apr 2010 01:42:04 -0000
@@ -71,6 +71,7 @@
static struct obstack dont_print_vb_obstack;
static struct obstack dont_print_statmem_obstack;
+static struct obstack dont_print_stat_array_obstack;
extern void _initialize_cp_valprint (void);
@@ -155,12 +156,17 @@
{
int i, len, n_baseclasses;
int fields_seen = 0;
+ static int last_set_recurse = -1;
CHECK_TYPEDEF (type);
- if (recurse == 0
- && obstack_object_size (&dont_print_statmem_obstack) > 0)
- obstack_free (&dont_print_statmem_obstack, NULL);
+ if (recurse == 0)
+ {
+ if (obstack_object_size (&dont_print_statmem_obstack) > 0)
+ obstack_free (&dont_print_statmem_obstack, NULL);
+ if (obstack_object_size (&dont_print_stat_array_obstack) > 0)
+ obstack_free (&dont_print_stat_array_obstack, NULL);
+ }
fprintf_filtered (stream, "{");
len = TYPE_NFIELDS (type);
@@ -181,12 +187,20 @@
else
{
void *statmem_obstack_top = NULL;
+ 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);
+
+ if (last_set_recurse != recurse)
+ {
+ stat_array_obstack_top
+ = obstack_next_free (&dont_print_stat_array_obstack);
+ last_set_recurse = recurse;
+ }
}
for (i = n_baseclasses; i < len; i++)
@@ -307,9 +321,16 @@
if (dont_print_statmem == 0)
{
- /* In effect, a pop of the printed-statics stack. */
if (obstack_object_size (&dont_print_statmem_obstack) > 0)
obstack_free (&dont_print_statmem_obstack, statmem_obstack_top);
+
+ if (last_set_recurse != recurse)
+ {
+ if (obstack_object_size (&dont_print_stat_array_obstack) > 0)
+ obstack_free (&dont_print_stat_array_obstack,
+ stat_array_obstack_top);
+ last_set_recurse = -1;
+ }
}
if (options->pretty)
@@ -508,6 +529,7 @@
const struct value_print_options *options)
{
struct value_print_options opts;
+
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
CORE_ADDR *first_dont_print;
@@ -531,10 +553,12 @@
}
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),
value_embedded_offset (val), addr,
@@ -542,6 +566,32 @@
return;
}
+ if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+ {
+ struct type **first_dont_print;
+ int i;
+ struct type * target_type = TYPE_TARGET_TYPE (type);
+
+ first_dont_print
+ = (struct type **) obstack_base (&dont_print_stat_array_obstack);
+ i = obstack_object_size (&dont_print_stat_array_obstack)
+ / sizeof (CORE_ADDR);
+
+ while (--i >= 0)
+ {
+ if (target_type == first_dont_print[i])
+ {
+ fputs_filtered ("<same as static member of an already"
+ " seen type>",
+ stream);
+ return;
+ }
+ }
+
+ obstack_grow (&dont_print_stat_array_obstack, (char *) &target_type,
+ sizeof (struct type *));
+ }
+
opts = *options;
opts.deref_ref = 0;
val_print (type, value_contents_all (val),
@@ -672,6 +722,7 @@
show_objectprint,
&setprintlist, &showprintlist);
+ obstack_begin (&dont_print_stat_array_obstack, 32 * sizeof (CORE_ADDR));
obstack_begin (&dont_print_statmem_obstack, 32 * sizeof (CORE_ADDR));
obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *));
}
Index: testsuite/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v
retrieving revision 1.2231
diff -u -r1.2231 ChangeLog
--- testsuite/ChangeLog 12 Apr 2010 09:49:34 -0000 1.2231
+++ testsuite/ChangeLog 14 Apr 2010 01:42:21 -0000
@@ -1,3 +1,9 @@
+2010-04-13 Chris Moller <cmoller@mredhat.com>
+
+ * gdb.cp/Makefile.in (EXECUTABLES): Added pr10687
+ * gdb.cp/pr10687.cc: New file.
+ * gdb.cp/pr10687.exp: New file.
+
2010-04-12 Phil Muldoon <pmuldoon@redhat.com>
* gdb.python/py-breakpoint.c: Make result global.
Index: testsuite/gdb.cp/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/Makefile.in,v
retrieving revision 1.9
diff -u -r1.9 Makefile.in
--- testsuite/gdb.cp/Makefile.in 8 Feb 2010 18:27:53 -0000 1.9
+++ testsuite/gdb.cp/Makefile.in 14 Apr 2010 01:42:21 -0000
@@ -5,7 +5,7 @@
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
+ pr1072 pr10687
all info install-info dvi install uninstall installcheck check:
@echo "Nothing to be done for $@..."
Index: testsuite/gdb.cp/pr10687.cc
===================================================================
RCS file: testsuite/gdb.cp/pr10687.cc
diff -N testsuite/gdb.cp/pr10687.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/pr10687.cc 14 Apr 2010 01:42:22 -0000
@@ -0,0 +1,24 @@
+class vec2
+{
+ public:
+ vec2() { _v[0] = _v[1] = 0; }
+ vec2(int x, int y) { _v[0] = x; _v[1] = y; }
+ static vec2 axis[2];
+ static vec2 axis6[6];
+ private:
+ int _v[2];
+};
+
+vec2 vec2::axis[2] = { vec2(1,0), vec2(0,1) };
+vec2 vec2::axis6[6] = {
+ vec2(1,0), vec2(0,1),
+ vec2(2,0), vec2(0,2),
+ vec2(3,0), vec2(0,3)
+};
+
+int main(int argc, char*argv[])
+{
+ vec2 a;
+
+ return 0; // marker
+}
Index: testsuite/gdb.cp/pr10687.exp
===================================================================
RCS file: testsuite/gdb.cp/pr10687.exp
diff -N testsuite/gdb.cp/pr10687.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/pr10687.exp 14 Apr 2010 01:42:22 -0000
@@ -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 <http://www.gnu.org/licenses/>.
+
+set testfile pr10687
+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 a" "{static axis = {{static axis = <same as static member of an already.*"
+
[-- Attachment #3: pr10687-gdb-sum.diff --]
[-- Type: text/x-patch, Size: 986 bytes --]
--- virgin-gdb.sum 2010-04-13 20:28:27.100326020 -0400
+++ patched-gdb.sum 2010-04-13 21:24:49.447325737 -0400
@@ -1,4 +1,4 @@
-Test Run By moller on Tue Apr 13 20:19:36 2010
+Test Run By moller on Tue Apr 13 21:16:27 2010
Native configuration is i686-pc-linux-gnu
=== gdb tests ===
@@ -12264,6 +12264,9 @@
Running ../../../src/gdb/testsuite/gdb.cp/pr-574.exp ...
PASS: gdb.cp/pr-574.exp: continue to breakpoint: end of constructors
PASS: gdb.cp/pr-574.exp: PR gdb/574
+Running ../../../src/gdb/testsuite/gdb.cp/pr10687.exp ...
+PASS: gdb.cp/pr10687.exp: continue to breakpoint: marker
+PASS: gdb.cp/pr10687.exp: p a
Running ../../../src/gdb/testsuite/gdb.cp/pr10728.exp ...
PASS: gdb.cp/pr10728.exp: continue to breakpoint: marker 1
PASS: gdb.cp/pr10728.exp: print x->y2 - x->y1
@@ -16698,7 +16701,7 @@
=== gdb Summary ===
-# of expected passes 15878
+# of expected passes 15880
# of unexpected failures 17
# of expected failures 44
# of untested testcases 4
next reply other threads:[~2010-04-14 2:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-14 2:14 Chris Moller [this message]
2010-04-20 18:27 ` Tom Tromey
2010-04-20 20:24 ` Chris Moller
2010-06-14 16:12 ` Ulrich Weigand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BC524E8.404@redhat.com \
--to=cmoller@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox