PR 10867
authorChris Moller <cmoller@cygnus>
Tue, 20 Apr 2010 20:22:12 +0000 (20:22 +0000)
committerChris Moller <cmoller@cygnus>
Tue, 20 Apr 2010 20:22:12 +0000 (20:22 +0000)
* 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.
* gdb.cp/Makefile.in  (EXECUTABLES): Added pr10687
* gdb.cp/pr10687.cc: New file.
* gdb.cp/pr10687.exp: New file

gdb/ChangeLog
gdb/cp-valprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/Makefile.in
gdb/testsuite/gdb.cp/pr10687.cc [new file with mode: 0644]
gdb/testsuite/gdb.cp/pr10687.exp [new file with mode: 0644]

index 8ac2399bec4cf52f40bd4f8f5bfe62525d88ef56..f87175f3054e72a0d7270820151b8a04fa77abd2 100644 (file)
@@ -1,3 +1,12 @@
+2010-04-20  Chris Moller  <cmoller@redhat.com>
+       
+       PR 10867
+
+       * 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-20  Mark Kettenis  <kettenis@gnu.org>
 
        * i386-linux-tdep.c (i386_linux_regset_sections): Size of the
index 34a19324e8b7edc9f607d14f2faf68cedbe9eed1..d3d94d9cd8294873b23cedae4ef87f27b10e1acf 100644 (file)
@@ -71,6 +71,7 @@ show_static_field_print (struct ui_file *file, int from_tty,
 
 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 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 {
   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 @@ cp_print_value_fields (struct type *type, struct type *real_type,
   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 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 
       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 @@ cp_print_static_field (struct type *type,
                       const struct value_print_options *options)
 {
   struct value_print_options opts;
+  
   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
     {
       CORE_ADDR *first_dont_print;
@@ -542,6 +564,32 @@ cp_print_static_field (struct type *type,
       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 +720,7 @@ Show printing of object's derived type based on vtable info."), NULL,
                           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 a9400af334d8f5849abee53283f0e82060580aff..d1aa33befb87c3c34377ed69bd92bff40f688619 100644 (file)
@@ -1,3 +1,12 @@
+2010-04-20  Chris Moller  <cmoller@redhat.com>
+
+       PR 10867
+       
+       * gdb.cp/Makefile.in  (EXECUTABLES): Added pr10687
+       * gdb.cp/pr10687.cc: New file.
+       * gdb.cp/pr10687.exp: New file.
+
+
 2010-04-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Sergio Durigan Junior  <sergiodj@redhat.com>
 
index d78258ea756473abea60e045192a5433d5bb3e71..721094da5c750c8cc88e1946569e2c3e92dbf0fc 100644 (file)
@@ -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
+       pr1072 pr10687
 
 all info install-info dvi install uninstall installcheck check:
        @echo "Nothing to be done for $@..."
diff --git a/gdb/testsuite/gdb.cp/pr10687.cc b/gdb/testsuite/gdb.cp/pr10687.cc
new file mode 100644 (file)
index 0000000..bc25dcc
--- /dev/null
@@ -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
+}
diff --git a/gdb/testsuite/gdb.cp/pr10687.exp b/gdb/testsuite/gdb.cp/pr10687.exp
new file mode 100644 (file)
index 0000000..d99a17f
--- /dev/null
@@ -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.*"
+