From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com
Subject: [PATCH, 1/2] Factor out skip_attr
Date: Tue, 01 Jan 2019 00:00:00 -0000 [thread overview]
Message-ID: <20190307131127.GA6319@delia> (raw)
Hi,
This patch factors out new function skip_attr.
OK for trunk?
Thanks,
- Tom
Factor out skip_attr
2019-02-05 Tom de Vries <tdevries@suse.de>
* dwz.c (skip_attr): Factor out of ...
(get_AT, skip_attrs): ... here.
---
dwz.c | 216 +++++++++++++++++++++++++-----------------------------------------
1 file changed, 82 insertions(+), 134 deletions(-)
diff --git a/dwz.c b/dwz.c
index 476807a..e4e5d5c 100644
--- a/dwz.c
+++ b/dwz.c
@@ -1227,6 +1227,82 @@ off_htab_lookup (dw_cu_ref cu, unsigned int die_offset)
return (dw_die_ref) htab_find_with_hash (off_htab, &die, die_offset);
}
+/* Return pointer after the attribute ATTR of a die in CU which starts at
+ PTR. */
+static inline unsigned char *
+skip_attr (dw_cu_ref cu, struct abbrev_attr *attr, unsigned char *ptr)
+{
+ uint32_t form = attr->form;
+ size_t len = 0;
+
+ while (form == DW_FORM_indirect)
+ form = read_uleb128 (ptr);
+ switch (form)
+ {
+ case DW_FORM_ref_addr:
+ ptr += cu->cu_version == 2 ? ptr_size : 4;
+ break;
+ case DW_FORM_addr:
+ ptr += ptr_size;
+ break;
+ case DW_FORM_flag_present:
+ break;
+ case DW_FORM_ref1:
+ case DW_FORM_flag:
+ case DW_FORM_data1:
+ ++ptr;
+ break;
+ case DW_FORM_ref2:
+ case DW_FORM_data2:
+ ptr += 2;
+ break;
+ case DW_FORM_ref4:
+ case DW_FORM_data4:
+ case DW_FORM_sec_offset:
+ case DW_FORM_strp:
+ ptr += 4;
+ break;
+ case DW_FORM_ref8:
+ case DW_FORM_data8:
+ case DW_FORM_ref_sig8:
+ ptr += 8;
+ break;
+ case DW_FORM_sdata:
+ case DW_FORM_ref_udata:
+ case DW_FORM_udata:
+ read_uleb128 (ptr);
+ break;
+ case DW_FORM_string:
+ ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1;
+ break;
+ case DW_FORM_indirect:
+ abort ();
+ case DW_FORM_block1:
+ len = *ptr++;
+ break;
+ case DW_FORM_block2:
+ len = read_16 (ptr);
+ form = DW_FORM_block1;
+ break;
+ case DW_FORM_block4:
+ len = read_32 (ptr);
+ form = DW_FORM_block1;
+ break;
+ case DW_FORM_block:
+ case DW_FORM_exprloc:
+ len = read_uleb128 (ptr);
+ form = DW_FORM_block1;
+ break;
+ default:
+ abort ();
+ }
+
+ if (form == DW_FORM_block1)
+ ptr += len;
+
+ return ptr;
+}
+
/* Return a pointer at which DIE's attribute AT is encoded, and fill in
its form into *FORMP. Return NULL if the attribute is not present. */
static unsigned char *
@@ -1246,78 +1322,17 @@ get_AT (dw_die_ref die, enum dwarf_attribute at, enum dwarf_form *formp)
read_uleb128 (ptr);
for (i = 0; i < t->nattr; ++i)
{
- uint32_t form = t->attr[i].form;
- size_t len = 0;
-
- while (form == DW_FORM_indirect)
- form = read_uleb128 (ptr);
if (t->attr[i].attr == at)
{
+ uint32_t form = t->attr[i].form;
+ while (form == DW_FORM_indirect)
+ form = read_uleb128 (ptr);
+
*formp = form;
return ptr;
}
- switch (form)
- {
- case DW_FORM_ref_addr:
- ptr += cu->cu_version == 2 ? ptr_size : 4;
- break;
- case DW_FORM_addr:
- ptr += ptr_size;
- break;
- case DW_FORM_flag_present:
- break;
- case DW_FORM_ref1:
- case DW_FORM_flag:
- case DW_FORM_data1:
- ++ptr;
- break;
- case DW_FORM_ref2:
- case DW_FORM_data2:
- ptr += 2;
- break;
- case DW_FORM_ref4:
- case DW_FORM_data4:
- case DW_FORM_sec_offset:
- case DW_FORM_strp:
- ptr += 4;
- break;
- case DW_FORM_ref8:
- case DW_FORM_data8:
- case DW_FORM_ref_sig8:
- ptr += 8;
- break;
- case DW_FORM_sdata:
- case DW_FORM_ref_udata:
- case DW_FORM_udata:
- read_uleb128 (ptr);
- break;
- case DW_FORM_string:
- ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1;
- break;
- case DW_FORM_indirect:
- abort ();
- case DW_FORM_block1:
- len = *ptr++;
- break;
- case DW_FORM_block2:
- len = read_16 (ptr);
- form = DW_FORM_block1;
- break;
- case DW_FORM_block4:
- len = read_32 (ptr);
- form = DW_FORM_block1;
- break;
- case DW_FORM_block:
- case DW_FORM_exprloc:
- len = read_uleb128 (ptr);
- form = DW_FORM_block1;
- break;
- default:
- abort ();
- }
- if (form == DW_FORM_block1)
- ptr += len;
+ ptr = skip_attr (cu, &t->attr[i], ptr);
}
return NULL;
}
@@ -2692,75 +2707,8 @@ skip_attrs (dw_cu_ref cu, struct abbrev_tag *t, unsigned char *ptr)
{
unsigned int i;
for (i = 0; i < t->nattr; ++i)
- {
- uint32_t form = t->attr[i].form;
- size_t len = 0;
+ ptr = skip_attr (cu, &t->attr[i], ptr);
- while (form == DW_FORM_indirect)
- form = read_uleb128 (ptr);
- switch (form)
- {
- case DW_FORM_ref_addr:
- ptr += cu->cu_version == 2 ? ptr_size : 4;
- break;
- case DW_FORM_addr:
- ptr += ptr_size;
- break;
- case DW_FORM_flag_present:
- break;
- case DW_FORM_ref1:
- case DW_FORM_flag:
- case DW_FORM_data1:
- ++ptr;
- break;
- case DW_FORM_ref2:
- case DW_FORM_data2:
- ptr += 2;
- break;
- case DW_FORM_ref4:
- case DW_FORM_data4:
- case DW_FORM_sec_offset:
- case DW_FORM_strp:
- ptr += 4;
- break;
- case DW_FORM_ref8:
- case DW_FORM_data8:
- case DW_FORM_ref_sig8:
- ptr += 8;
- break;
- case DW_FORM_sdata:
- case DW_FORM_ref_udata:
- case DW_FORM_udata:
- read_uleb128 (ptr);
- break;
- case DW_FORM_string:
- ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1;
- break;
- case DW_FORM_indirect:
- abort ();
- case DW_FORM_block1:
- len = *ptr++;
- break;
- case DW_FORM_block2:
- len = read_16 (ptr);
- form = DW_FORM_block1;
- break;
- case DW_FORM_block4:
- len = read_32 (ptr);
- form = DW_FORM_block1;
- break;
- case DW_FORM_block:
- case DW_FORM_exprloc:
- len = read_uleb128 (ptr);
- form = DW_FORM_block1;
- break;
- default:
- abort ();
- }
-
- if (form == DW_FORM_block1)
- ptr += len;
- }
return ptr;
}
reply other threads:[~2019-03-07 13:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20190307131127.GA6319@delia \
--to=tdevries@suse.de \
--cc=dwz@sourceware.org \
--cc=jakub@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).