static void handle_die( struct dwarf_subprogram_t **subprograms, Dwarf_Debug dbg, Dwarf_Die cu_die, Dwarf_Die the_die, Dwarf_Unsigned language) { int rc; Dwarf_Error err; Dwarf_Die current_die = the_die; Dwarf_Die child_die = NULL; Dwarf_Die next_die; do { *subprograms = read_cu_entry(*subprograms, dbg, cu_die, current_die, language); /* Recursive call handle_die with child, to continue searching within child dies */ rc = dwarf_child(current_die, &child_die, &err); DWARF_ASSERT(rc, err); if (rc == DW_DLV_OK && child_die) handle_die(subprograms, dbg, cu_die, child_die, language); rc = dwarf_siblingof(dbg, current_die, &next_die, &err); DWARF_ASSERT(rc, err); dwarf_dealloc(dbg, current_die, DW_DLA_DIE); current_die = next_die; } while (rc != DW_DLV_NO_ENTRY); }
static struct dwarf_subprogram_t *read_from_cus(Dwarf_Debug dbg) { Dwarf_Unsigned cu_header_length, abbrev_offset, next_cu_header; Dwarf_Half version_stamp, address_size; Dwarf_Error err; Dwarf_Die no_die = 0, cu_die, child_die, next_die; int ret = DW_DLV_OK; int rc; struct dwarf_subprogram_t *subprograms = NULL; while (ret == DW_DLV_OK) { ret = dwarf_next_cu_header( dbg, &cu_header_length, &version_stamp, &abbrev_offset, &address_size, &next_cu_header, &err); DWARF_ASSERT(ret, err); if (ret == DW_DLV_NO_ENTRY) continue; /* TODO: If the CU can provide an address range then we can skip over * all the entire die if none of our addresses match */ /* Expect the CU to have a single sibling - a DIE */ ret = dwarf_siblingof(dbg, no_die, &cu_die, &err); if (ret == DW_DLV_ERROR) { continue; } DWARF_ASSERT(ret, err); /* Expect the CU DIE to have children */ ret = dwarf_child(cu_die, &child_die, &err); DWARF_ASSERT(ret, err); next_die = child_die; /* Now go over all children DIEs */ do { subprograms = read_cu_entry(subprograms, dbg, cu_die, child_die); rc = dwarf_siblingof(dbg, child_die, &next_die, &err); DWARF_ASSERT(rc, err); dwarf_dealloc(dbg, child_die, DW_DLA_DIE); child_die = next_die; } while (rc != DW_DLV_NO_ENTRY); dwarf_dealloc(dbg, cu_die, DW_DLA_DIE); } return subprograms; }