libdwarf
Using dwarf_attrlist()

Example showing dwarf_attrlist()

Parameters
somediePass in any valid relevant DIE pointer.
errorAn error pointer we can use.
Returns
Return DW_DLV_OK (etc).
*/
int example1(Dwarf_Die somedie,Dwarf_Error *error)
{
Dwarf_Debug dbg = 0;
Dwarf_Signed atcount;
Dwarf_Attribute *atlist;
Dwarf_Signed i = 0;
int errv;
errv = dwarf_attrlist(somedie, &atlist,&atcount, error);
if (errv != DW_DLV_OK) {
return errv;
}
for (i = 0; i < atcount; ++i) {
Dwarf_Half attrnum = 0;
const char *attrname = 0;
/* use atlist[i], likely calling
libdwarf functions and likely
returning DW_DLV_ERROR if
what you call gets DW_DLV_ERROR */
errv = dwarf_whatattr(atlist[i],&attrnum,error);
if (errv != DW_DLV_OK) {
/* Something really bad happened. */
return errv;
}
dwarf_get_AT_name(attrnum,&attrname);
printf("Attribute[%ld], value %u name %s\n",
(long int)i,attrnum,attrname);
atlist[i] = 0;
}
dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
return DW_DLV_OK;
}
int dwarf_get_AT_name(unsigned int dw_val_in, const char **dw_s_out)
dwarf_get_AT_name
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:586
struct Dwarf_Die_s * Dwarf_Die
Definition: libdwarf.h:591
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:580
struct Dwarf_Attribute_s * Dwarf_Attribute
Definition: libdwarf.h:641
void dwarf_dealloc_attribute(Dwarf_Attribute dw_attr)
Dealloc a Dwarf_Attribute When this call returns the dw_attr is a stale pointer.
int dwarf_attrlist(Dwarf_Die dw_die, Dwarf_Attribute **dw_attrbuf, Dwarf_Signed *dw_attrcount, Dwarf_Error *dw_error)
Gets the full list of attributes.
int dwarf_whatattr(Dwarf_Attribute dw_attr, Dwarf_Half *dw_returned_attrnum, Dwarf_Error *dw_error)
Return the attribute number of the Dwarf_Attribute.
signed long long Dwarf_Signed
Definition: libdwarf.h:197
unsigned short Dwarf_Half
Definition: libdwarf.h:203
void dwarf_dealloc(Dwarf_Debug dw_dbg, void *dw_space, Dwarf_Unsigned dw_type)
The generic dealloc (free) function. It requires you know the correct DW_DLA value to pass in,...