Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <tromey@redhat.com>
Cc: <gdb-patches@sourceware.org>
Subject: [RFA-v3] dwarf2read.c: Avoid complaint for char array of unspecified size
Date: Fri, 28 May 2010 10:17:00 -0000	[thread overview]
Message-ID: <000f01cafe4e$17eccea0$47c66be0$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <m3ljb5f6qt.fsf@fleche.redhat.com>

> Pierre> +  if (die->num_attrs == 0)
> 
> A DW_TAG_subrange_type might have attributes that we ignore.  So, I
> think there is no need for a check that is this specific; just
> determine
> the type according to the above algorithm, and remove the existing
> complaint code.
> 
> Tom

  OK, I tried to follow that route,
the tricky part was that we don't really know which objfile type
is the same size as an address, but the patch is a bit lengthy...
  At the same time, I discovered that DW_AT_count was not supported,
(maybe no compiler uses that, but it can't hurt to add
support for this).


Pierre

2010-05-28  Pierre Muller  <muller@ics.u-strasbg.fr>

	* dwarf2read.c (read_subrange_type): Handle missing base type
	according to Dwarf-2 specifications.
	Also handle DW_AT_count attribute.

Index: src/gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.388
diff -u -p -r1.388 dwarf2read.c
--- src/gdb/dwarf2read.c	21 May 2010 20:45:19 -0000	1.388
+++ src/gdb/dwarf2read.c	28 May 2010 08:39:58 -0000
@@ -6129,16 +6131,8 @@ read_subrange_type (struct die_info *die
   LONGEST high = -1;
   char *name;
   LONGEST negative_mask;
-  
+
   base_type = die_type (die, cu);
-  if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
-    {
-      complaint (&symfile_complaints,
-                _("DW_AT_type missing from DW_TAG_subrange_type"));
-      base_type
-	= init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
-		     0, NULL, cu->objfile);
-    }
 
   if (cu->language == language_fortran)
     { 
@@ -6156,10 +6150,10 @@ read_subrange_type (struct die_info *die
   attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
   if (attr)
     {       
-      if (attr->form == DW_FORM_block1)
+      if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
         {
           /* GCC encodes arrays with unspecified or dynamic length
-             with a DW_FORM_block1 attribute.
+             with a DW_FORM_block1 attribute or a reference attribute.
              FIXME: GDB does not yet know how to handle dynamic
              arrays properly, treat them as arrays with unspecified
              length for now.
@@ -6174,6 +6168,48 @@ read_subrange_type (struct die_info *die
       else
         high = dwarf2_get_attr_constant_value (attr, 1);
     }
+  else
+    {
+      attr = dwarf2_attr (die, DW_AT_count, cu);
+      if (attr)
+	{
+	  int count = dwarf2_get_attr_constant_value (attr, 1);
+	  high = low + count - 1;
+	}
+    }
+
+  /* Dwarf-2 specifications explicitly allows to create subrange types
+     without specifying a base type.
+     In that case, the base type must be set to the type of
+     the lower bound, upper bound or count, in that order, if any of these
+     three attributes references an object that has a type.
+     If no base type is found, the Dwarf-2 specifications say that
+     a signed integer type of size equal to the size of an address should
+     be used.
+     For the following C code: `extern char gdb_int [];'
+     GCC produces an empty range DIE.
+     FIXME: muller/2010-05-28: Possible references to object for low bound,
+     high bound or count are not yet handled by this code.
+  */
+  if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
+    {
+      struct objfile *objfile = cu->objfile;
+      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      int addr_size = gdbarch_addr_bit (gdbarch) /8;
+      struct type *int_type = objfile_type (objfile)->builtin_long_long;
+
+      /* Test "long long int", "long int", and "int" objfile types,
+	 and select the last one having a size above or equal to the
+	 architecture address size.  */
+      if (int_type && TYPE_LENGTH (int_type) >= addr_size)
+	base_type = int_type;
+      int_type = objfile_type (objfile)->builtin_long;
+      if (int_type && TYPE_LENGTH (int_type) >= addr_size)
+	base_type = int_type;
+      int_type = objfile_type (objfile)->builtin_int;
+      if (int_type && TYPE_LENGTH (int_type) >= addr_size)
+	base_type = int_type;
+    }
 
   negative_mask = 
     (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);


  reply	other threads:[~2010-05-28 10:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <38685.0063725889$1274473713@news.gmane.org>
2010-05-21 22:13 ` [RFA] " Tom Tromey
2010-05-21 23:55   ` Pierre Muller
2010-05-24 15:35     ` Tom Tromey
2010-05-26 15:21       ` [RFA-v2] " Pierre Muller
     [not found]       ` <34200.8848595016$1274864816@news.gmane.org>
2010-05-27 20:09         ` Tom Tromey
2010-05-28 10:17           ` Pierre Muller [this message]
2010-06-01 19:07             ` [RFA-v3] " Tom Tromey
2010-06-02  6:25               ` Pierre Muller
2010-06-02 19:35                 ` Tom Tromey

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='000f01cafe4e$17eccea0$47c66be0$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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