summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2017-10-03 15:18:56 +0900
committerDominique Martinet <asmadeus@codewreck.org>2017-10-03 15:18:56 +0900
commitceb2f138453334e13c58cb092c2e52e64dc6a014 (patch)
tree06fd19013c333befbd3bfaef358807b70d601165
parenta717094e06962b4694e9298cdde52af53f99321a (diff)
change attrlist to specifically pick attr
-rw-r--r--dwarf.c78
1 files changed, 32 insertions, 46 deletions
diff --git a/dwarf.c b/dwarf.c
index b116cf5..cf6506f 100644
--- a/dwarf.c
+++ b/dwarf.c
@@ -238,66 +238,52 @@ static void find_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name, i
}
static void print_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name) {
- Dwarf_Attribute *attrs;
- Dwarf_Signed attrcount = 0;
+ Dwarf_Attribute attr;
Dwarf_Error err;
Dwarf_Unsigned offset = 0;
int rc, i;
printf("Found %s\n", field_name);
- rc = dwarf_attrlist(die, &attrs, &attrcount, &err);
+ rc = dwarf_attr(die, DW_AT_data_member_location, &attr, &err);
if (rc == DW_DLV_NO_ENTRY) {
- printf("Found %s but no attribute\n", field_name);
- exit(4);
- }
- if (rc != DW_DLV_OK) {
+ printf("Found %s but no offest, assuming 0\n", field_name);
+ } else if (rc != DW_DLV_OK) {
printf("Error getting dwarf attrlist: %s\n", dwarf_errmsg(err));
exit(4);
- }
-
- for (i = 0; i < attrcount; i++) {
- Dwarf_Half aform;
- rc = dwarf_whatattr(attrs[i], &aform, &err);
+ } else {
+ Dwarf_Half form;
+ rc = dwarf_whatform(attr, &form, &err);
if (rc != DW_DLV_OK) {
- printf("Error getting attr %d: %s\n", i, dwarf_errmsg(err));
+ printf("Error getting whatform: %s\n", dwarf_errmsg(err));
exit(5);
}
- if (aform == DW_AT_data_member_location) {
- Dwarf_Half form;
- rc = dwarf_whatform(attrs[i], &form, &err);
- if (rc != DW_DLV_OK) {
- printf("Error getting whatform: %s\n", dwarf_errmsg(err));
- exit(5);
+ if (form == DW_FORM_data1 || form == DW_FORM_data2
+ || form == DW_FORM_data2 || form == DW_FORM_data4
+ || form == DW_FORM_data8 || form == DW_FORM_udata) {
+ dwarf_formudata(attr, &offset, 0);
+ } else if (form == DW_FORM_sdata) {
+ Dwarf_Signed soffset;
+ dwarf_formsdata(attr, &soffset, 0);
+ if (soffset < 0) {
+ printf("unsupported negative offset\n");
+ /* FAIL */
+ }
+ offset = (Dwarf_Unsigned) soffset;
+ } else {
+ Dwarf_Locdesc **locdescs;
+ Dwarf_Signed len;
+ if (dwarf_loclist_n(attr, &locdescs, &len, &err) == DW_DLV_ERROR) {
+ printf("unsupported member offset\n");
+ /* FAIL */
}
- if (form == DW_FORM_data1 || form == DW_FORM_data2
- || form == DW_FORM_data2 || form == DW_FORM_data4
- || form == DW_FORM_data8 || form == DW_FORM_udata) {
- dwarf_formudata(attrs[i], &offset, 0);
- } else if (form == DW_FORM_sdata) {
- Dwarf_Signed soffset;
- dwarf_formsdata(attrs[i], &soffset, 0);
- if (soffset < 0) {
- printf("unsupported negative offset\n");
- /* FAIL */
- }
- offset = (Dwarf_Unsigned) soffset;
- } else {
- Dwarf_Locdesc **locdescs;
- Dwarf_Signed len;
- if (dwarf_loclist_n(attrs[i], &locdescs, &len, &err) == DW_DLV_ERROR) {
- printf("unsupported member offset\n");
- /* FAIL */
- }
- if (len != 1
- || locdescs[0]->ld_cents != 1
- || (locdescs[0]->ld_s[0]).lr_atom != DW_OP_plus_uconst) {
- printf("unsupported location expression\n");
- /* FAIL */
- }
- offset = (locdescs[0]->ld_s[0]).lr_number;
+ if (len != 1
+ || locdescs[0]->ld_cents != 1
+ || (locdescs[0]->ld_s[0]).lr_atom != DW_OP_plus_uconst) {
+ printf("unsupported location expression\n");
+ /* FAIL */
}
- } else if (aform == DW_AT_type) {
+ offset = (locdescs[0]->ld_s[0]).lr_number;
}
}
printf("offset %u\n", offset);