Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jim Blandy <jimb@codesourcery.com>
To: Vladimir Prus <vladimir@codesourcery.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: Support constants for DW_AT_data_member_location
Date: Thu, 29 Nov 2007 19:39:00 -0000	[thread overview]
Message-ID: <m3d4tskfk2.fsf@codesourcery.com> (raw)
In-Reply-To: <200711291254.14423.vladimir@codesourcery.com> (Vladimir Prus's message of "Thu, 29 Nov 2007 12:54:13 +0300")


Vladimir Prus <vladimir at codesourcery.com> writes:
> DWARF standard allows DW_AT_data_member_location value
> to be a plain constant, but GDB does not. Is the following OK?

A constant can have other FORMs, too; how about this?

gdb/ChangeLog:
2007-11-29  Jim Blandy  <jimb@codesourcery.com>

	* dwarf2read.c (dwarf2_attr_is_constant): New function.
	(dwarf2_add_field): Use it to recognize DW_AT_data_member_location
	attributes with constant values; use
	dwarf2_get_attr_constant_value to get said values.

diff -r c4f654de59cf gdb/dwarf2read.c
--- a/gdb/dwarf2read.c	Thu Nov 29 11:28:59 2007 -0800
+++ b/gdb/dwarf2read.c	Thu Nov 29 11:33:57 2007 -0800
@@ -1012,6 +1012,8 @@ static void store_in_ref_table (unsigned
 
 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
 					       struct dwarf2_cu *);
+
+static int dwarf2_attr_is_constant (struct attribute *);
 
 static int dwarf2_get_attr_constant_value (struct attribute *, int);
 
@@ -3380,8 +3382,11 @@ dwarf2_add_field (struct field_info *fip
       attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
       if (attr)
 	{
-	  FIELD_BITPOS (*fp) =
-	    decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
+          if (dwarf2_attr_is_constant (attr))
+            FIELD_BITPOS (*fp) = dwarf2_get_attr_constant_value (attr, 0);
+          else
+            FIELD_BITPOS (*fp) =
+              decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
 	}
       else
 	FIELD_BITPOS (*fp) = 0;
@@ -9008,6 +9013,26 @@ dwarf2_get_ref_die_offset (struct attrib
   return result;
 }
 
+/* Return non-zero if ATTR's value falls in the 'constant' class, or
+   zero otherwise.  When this function returns true, you can apply
+   dwarf2_get_attr_constant_value to it.  */
+static int
+dwarf2_attr_is_constant (struct attribute *attr)
+{
+  switch (attr->form)
+    {
+    case DW_FORM_sdata:
+    case DW_FORM_udata:
+    case DW_FORM_data1:
+    case DW_FORM_data2:
+    case DW_FORM_data4:
+    case DW_FORM_data8:
+      return 1;
+    default:
+      return 0;
+    }
+}
+
 /* Return the constant value held by the given attribute.  Return -1
    if the value held by the attribute is not constant.  */
 


  reply	other threads:[~2007-11-29 19:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29  9:54 Vladimir Prus
2007-11-29 19:39 ` Jim Blandy [this message]
2007-11-29 20:18   ` Vladimir Prus
2007-12-01  1:48     ` Jim Blandy
2007-12-13 17:57       ` Vladimir Prus
2007-12-13 19:29         ` Jim Blandy
2007-12-17 19:30           ` Jim Blandy

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=m3d4tskfk2.fsf@codesourcery.com \
    --to=jimb@codesourcery.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=vladimir@codesourcery.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