summaryrefslogtreecommitdiffstats
path: root/libdw/dwarf_hasattr.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2014-12-19 00:06:26 +0100
committerMark Wielaard <[email protected]>2014-12-19 00:06:26 +0100
commitbd0434b61e0317718eb159fe7b5dc9ea870a0b79 (patch)
tree825a373c2233a59b5156b219013e32f8f241aacc /libdw/dwarf_hasattr.c
parente18bf66ce8070f96195880e83a50c9d98006b832 (diff)
parent898ed261444cdd817c2d9b3656209a291eb5e807 (diff)
Merge branch 'master' into portable
Diffstat (limited to 'libdw/dwarf_hasattr.c')
-rw-r--r--libdw/dwarf_hasattr.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/libdw/dwarf_hasattr.c b/libdw/dwarf_hasattr.c
index 7933c1c3..812c09bc 100644
--- a/libdw/dwarf_hasattr.c
+++ b/libdw/dwarf_hasattr.c
@@ -1,5 +1,5 @@
/* Check whether given DIE has specific attribute.
- Copyright (C) 2003, 2005 Red Hat, Inc.
+ Copyright (C) 2003, 2005, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <[email protected]>, 2003.
@@ -43,10 +43,43 @@ dwarf_hasattr (die, search_name)
if (die == NULL)
return 0;
- /* Search for the attribute with the given name. */
- unsigned int code;
- (void) __libdw_find_attr (die, search_name, &code, NULL);
+ /* Find the abbreviation entry. */
+ Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
+ if (unlikely (abbrevp == DWARF_END_ABBREV))
+ {
+ invalid_dwarf:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return 0;
+ }
- return code == search_name;
+ Dwarf *dbg = die->cu->dbg;
+
+ /* Search the name attribute. */
+ unsigned char *const endp
+ = ((unsigned char *) dbg->sectiondata[IDX_debug_abbrev]->d_buf
+ + dbg->sectiondata[IDX_debug_abbrev]->d_size);
+
+ const unsigned char *attrp = abbrevp->attrp;
+ while (1)
+ {
+ /* Are we still in bounds? This test needs to be refined. */
+ if (unlikely (attrp >= endp))
+ goto invalid_dwarf;
+
+ /* Get attribute name and form. */
+ unsigned int attr_name;
+ get_uleb128 (attr_name, attrp, endp);
+ unsigned int attr_form;
+ if (unlikely (attrp >= endp))
+ goto invalid_dwarf;
+ get_uleb128 (attr_form, attrp, endp);
+
+ /* We can stop if we found the attribute with value zero. */
+ if (attr_name == 0 || attr_form == 0)
+ return 0;
+
+ if (attr_name == search_name)
+ return 1;
+ }
}
INTDEF (dwarf_hasattr)