This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Fix forgotten check_typedef()s
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Paul Hilfinger <Hilfinger at adacore dot com>
- Date: Sun, 11 Jul 2010 18:23:07 +0200
- Subject: [patch] Fix forgotten check_typedef()s
Hi,
patch
[COMMIT] 64-bit range types in GDB
http://sourceware.org/ml/gdb-patches/2009-12/msg00181.html
violates the comment
/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
so you only have to call check_typedef once. Since allocate_value
calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
#define TYPE_LENGTH(thistype) (thistype)->length
by not calling check_typedef or CHECK_TYPEDEF before using TYPE_LENGTH in
read_subrange_type. On gdb.pascal/hello.pas it has no effect but apparently
the calculation is not right:
(gdb) p base_type->length
$7 = 0
(gdb) p base_type->main_type->flag_unsigned
$8 = 0
(gdb) p/x negative_mask
$5 = 0x8000000000000000
(gdb) p check_typedef (base_type)
$9 = (struct type *) 0x1ed9190
(gdb) p $9->length
$12 = 1
(gdb) p $9->main_type->flag_unsigned
$13 = 1
(gdb) p/x low
$14 = 0x0
(gdb) p/x high
$15 = 0xff
I did not try to find a reproducer.
With the archer-jankratochvil-vla patchset there is a regression as LENGTH is
check_typedef'ed there.
pascal_printstr is the same class of bug, unrelated to the 64-bit range types
patch above. (archer-jankratochvil-vla has a problem as create_array_type
does not do CHECK_TYPEDEF (element_type) when it is not immediately required.)
[ In a longterm IMO check_typedef should return a different GDB C type than
what is its argument so that check_typedef is enforced during gdb compilation.
]
No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu.
OK to check-in?
Thanks,
Jan
gdb/
2010-07-11 Jan Kratochvil <jan.kratochvil@redhat.com>
* dwarf2read.c (read_subrange_type): Call read_subrange_type.
* p-lang.c (pascal_printstr): Likewise.
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6332,6 +6332,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
LONGEST negative_mask;
base_type = die_type (die, cu);
+ /* Preserve BASE_TYPE's original type, just set its LENGTH. */
+ check_typedef (base_type);
/* The die_type call above may have already set the type for this DIE. */
range_type = get_die_type (die, cu);
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -222,7 +222,11 @@ pascal_printstr (struct ui_file *stream, struct type *type,
unsigned int things_printed = 0;
int in_quotes = 0;
int need_comma = 0;
- int width = TYPE_LENGTH (type);
+ int width;
+
+ /* Preserve TYPE's original type, just set its LENGTH. */
+ check_typedef (type);
+ width = TYPE_LENGTH (type);
/* If the string was not truncated due to `set print elements', and
the last byte of it is a null, we don't print that, in traditional C