Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Paul Hilfinger <Hilfinger@adacore.com>
Subject: [patch] Fix forgotten check_typedef()s
Date: Sun, 11 Jul 2010 16:23:00 -0000	[thread overview]
Message-ID: <20100711162307.GA31312@host0.dyn.jankratochvil.net> (raw)

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


             reply	other threads:[~2010-07-11 16:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-11 16:23 Jan Kratochvil [this message]
2010-07-12 17:00 ` Tom Tromey
2010-07-12 17:08   ` Jan Kratochvil

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=20100711162307.GA31312@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=Hilfinger@adacore.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