This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: PR10687 Printing c++ class with static array (of same type) can produce infinite output
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: cmoller at redhat dot com (Chris Moller)
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 14 Jun 2010 18:11:50 +0200 (CEST)
- Subject: Re: PR10687 Printing c++ class with static array (of same type) can produce infinite output
Chris Moller wrote:
> + 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 *));
> + }
This is broken on platforms where sizeof (CORE_ADDR) != sizeof (struct type *).
As the objects stored into the dont_print_stat_array_obstack are in fact of
type "struct type *", the size computations also need to use this type's size.
I'm seeing this problem on a spu-elf GDB built as 32-bit PowerPC executable.
Fixed by the patch below.
Tested on spu-elf, committed to mainline.
Bye,
Ulrich
ChangeLog:
* cp-valprint.c (cp_print_static_field): Members of
dont_print_stat_array_obstack are of type "struct type *".
(_initialize_cp_valprint): Likewise.
Index: gdb/cp-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-valprint.c,v
retrieving revision 1.69
diff -u -p -r1.69 cp-valprint.c
--- gdb/cp-valprint.c 11 Jun 2010 15:36:04 -0000 1.69
+++ gdb/cp-valprint.c 14 Jun 2010 16:03:53 -0000
@@ -615,7 +615,7 @@ cp_print_static_field (struct 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);
+ / sizeof (struct type *);
while (--i >= 0)
{
@@ -764,7 +764,7 @@ Show printing of object's derived type b
show_objectprint,
&setprintlist, &showprintlist);
- obstack_begin (&dont_print_stat_array_obstack, 32 * sizeof (CORE_ADDR));
+ obstack_begin (&dont_print_stat_array_obstack, 32 * sizeof (struct type *));
obstack_begin (&dont_print_statmem_obstack, 32 * sizeof (CORE_ADDR));
obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *));
}
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com