[RFA] dwarf2 reader: Clarify DW_FORM_flag/DW_FORM_flag_present

Pierre Muller pierre.muller@ics-cnrs.unistra.fr
Fri May 28 10:11:00 GMT 2010


   Dwarf-2 specs say that 
if an attribute ATTR is of form DW_FORM_flag,
then it is present of DW_UNSND (&ATTR) is non zero
and absent otherwise.
  This patch modifies dwarf2_attr and dwarf2_no_follow
to return NULL if an attribute is of form
DW_FORM_flag but with value zero.
  Dwarf-4 specifications say that for DW_FORM_flag_present
the value of DW_UNSND is irrelevant, but that is not handled correctly
in dwarf2_flag_true_p.
  I added a error if the form of the attribute is
not DW_FORM_flag nor DW_FORM_flag_present.

  Testsuite showed no change.


Pierre Muller
Pascal language support maintainer for GDB


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

	* dwarf2read.c (dwarf2_attr): Return NULL if form
	is DW_FORM_FLAG but flag value is zero.
	(dwarf2_attr_no_follow): Likewise.
	(dwarf2_flag_true_p): Check that form is either
	DW_FORM_flag or DW_FORM_flag_present, and correct
	handling of latter case.
	Call error for other forms.


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 09:27:20 -0000
@@ -7674,7 +7674,13 @@ dwarf2_attr (struct die_info *die, unsig
   for (i = 0; i < die->num_attrs; ++i)
     {
       if (die->attrs[i].name == name)
-	return &die->attrs[i];
+	{
+	  if (die->attrs[i].form == DW_FORM_flag
+	      && DW_UNSND (&die->attrs[i]) == 0)
+	    return NULL;
+	  else
+	    return &die->attrs[i];
+	}
       if (die->attrs[i].name == DW_AT_specification
 	  || die->attrs[i].name == DW_AT_abstract_origin)
 	spec = &die->attrs[i];
@@ -7703,7 +7709,13 @@ dwarf2_attr_no_follow (struct die_info *
 
   for (i = 0; i < die->num_attrs; ++i)
     if (die->attrs[i].name == name)
-      return &die->attrs[i];
+      {
+	if (die->attrs[i].form == DW_FORM_flag
+	    && DW_UNSND (&die->attrs[i]) == 0)
+	  return NULL;
+	else
+	  return &die->attrs[i];
+      }
 
   return NULL;
 }
@@ -7717,7 +7729,13 @@ dwarf2_flag_true_p (struct die_info *die
 {
   struct attribute *attr = dwarf2_attr (die, name, cu);
 
-  return (attr && DW_UNSND (attr));
+  if (!attr)
+    return 0;
+  if ((attr->form == DW_FORM_flag && DW_UNSND (attr))
+      || attr->form == DW_FORM_flag_present)
+    return 1;
+  error (_("dwarf2_flag_true_p called for wrong DIE form %s"),
+	 dwarf_form_name (attr->form));
 }
 
 static int



More information about the Gdb-patches mailing list