* [PATCH, 1/2] Factor out skip_attr
@ 2019-01-01 0:00 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2019-01-01 0:00 UTC (permalink / raw)
To: dwz, jakub
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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-03-07 13:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01 0:00 [PATCH, 1/2] Factor out skip_attr 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).