public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Rewrite write_unit_die using loop
@ 2020-01-01  0:00 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2020-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

Hi,

In write_unit_die, we currently handle attributes by testing if an attribute
is present at a hardcoded location:
...
       if (t->attr[0].attr == DW_AT_stmt_list)
...

Rewrite write_unit_die to use a loop over attributes instead, where we handle
each attribute according to its type, independent of the location.

Committed to trunk.

Thanks,
- Tom

Rewrite write_unit_die using loop

2020-02-11  Tom de Vries  <tdevries@suse.de>

	* dwz.c (write_unit_die): Rewrite into a loop over attributes.

---
 dwz.c | 97 +++++++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 53 insertions(+), 44 deletions(-)

diff --git a/dwz.c b/dwz.c
index 8562b7b..05dfe05 100644
--- a/dwz.c
+++ b/dwz.c
@@ -10780,53 +10780,62 @@ static unsigned char *
 write_unit_die (unsigned char *ptr, dw_die_ref die, dw_die_ref origin)
 {
   struct abbrev_tag *t = die->u.p2.die_new_abbrev;
+  unsigned int i;
 
-  if (t->nattr == 0)
-    return ptr;
-
-  if (t->attr[0].attr == DW_AT_stmt_list)
-    {
-      enum dwarf_form form;
-      unsigned char *p = get_AT (origin, DW_AT_stmt_list, &form);
-      assert (p && (form == DW_FORM_sec_offset
-		    || form == DW_FORM_data4));
-      if (wr_multifile)
-	write_32 (ptr, multi_line_off);
-      else if (op_multifile)
-	write_32 (ptr, 0);
-      else
-	{
-	  memcpy (ptr, p, 4);
-	  ptr += 4;
-	}
-    }
-  if (t->attr[t->nattr - 1].attr == DW_AT_comp_dir)
+  for (i = 0; i < t->nattr; ++i)
     {
-      enum dwarf_form form;
-      unsigned char *p = get_AT (origin, DW_AT_comp_dir, &form);
-      assert (p);
-      assert (form == t->attr[t->nattr - 1].form
-	      || (form == DW_FORM_strp
-		  && t->attr[t->nattr - 1].form
-		  == DW_FORM_GNU_strp_alt));
-      if (form == DW_FORM_strp)
-	{
-	  if (unlikely (wr_multifile || op_multifile || fi_multifile))
-	    {
-	      unsigned int strp = lookup_strp_offset (read_32 (p));
-	      write_32 (ptr, strp);
-	    }
-	  else
-	    {
-	      memcpy (ptr, p, 4);
-	      ptr += 4;
-	    }
-	}
-      else
+      struct abbrev_attr *attr = &t->attr[i];
+      switch (attr->attr)
 	{
-	  size_t len = strlen ((char *) p) + 1;
-	  memcpy (ptr, p, len);
-	  ptr += len;
+	case DW_AT_stmt_list:
+	  {
+	    enum dwarf_form form;
+	    unsigned char *p = get_AT (origin, DW_AT_stmt_list, &form);
+	    assert (p && (form == DW_FORM_sec_offset
+			  || form == DW_FORM_data4));
+	    if (wr_multifile)
+	      write_32 (ptr, multi_line_off);
+	    else if (op_multifile)
+	      write_32 (ptr, 0);
+	    else
+	      {
+		memcpy (ptr, p, 4);
+		ptr += 4;
+	      }
+	  }
+	  break;
+	case DW_AT_comp_dir:
+	  {
+	    enum dwarf_form form;
+	    unsigned char *p = get_AT (origin, DW_AT_comp_dir, &form);
+	    assert (p);
+	    assert (form == attr->form
+		    || (form == DW_FORM_strp
+			&& attr->form == DW_FORM_GNU_strp_alt));
+	    if (form == DW_FORM_strp)
+	      {
+		if (unlikely (wr_multifile || op_multifile || fi_multifile))
+		  {
+		    unsigned int strp = lookup_strp_offset (read_32 (p));
+		    write_32 (ptr, strp);
+		  }
+		else
+		  {
+		    memcpy (ptr, p, 4);
+		    ptr += 4;
+		  }
+	      }
+	    else
+	      {
+		size_t len = strlen ((char *) p) + 1;
+		memcpy (ptr, p, len);
+		ptr += len;
+	      }
+	  }
+	  break;
+	default:
+	  assert (false);
+	  break;
 	}
     }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-13 14:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-01  0:00 [committed] Rewrite write_unit_die using loop Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).