libdwarf
Using dwarf_child()

Example accessing a DIE child.

If the DIE has children (for example inner scopes in a function or members of a struct) this retrieves the DIE which appears first. The child itself may have its own sibling chain.

*/
void example5(Dwarf_Die in_die)
{
Dwarf_Die return_kid = 0;
Dwarf_Error error = 0;
int res = 0;
res = dwarf_child(in_die,&return_kid, &error);
if (res == DW_DLV_OK) {
/* Use return_kid here. */
dwarf_dealloc_die(return_kid);
/* The original form of dealloc still works
dwarf_dealloc(dbg, return_kid, DW_DLA_DIE);
*/
/* return_kid is no longer usable for anything, we
ensure we do not use it accidentally with: */
return_kid = 0;
}
}
struct Dwarf_Die_s * Dwarf_Die
Definition: libdwarf.h:608
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
void dwarf_dealloc_die(Dwarf_Die dw_die)
Deallocate (free) a DIE.
int dwarf_child(Dwarf_Die dw_die, Dwarf_Die *dw_return_childdie, Dwarf_Error *dw_error)
Return the child DIE, if any. The child may be the first of a list of sibling DIEs.