Skip to content

Commit

Permalink
DIE iteration optimizations
Browse files Browse the repository at this point in the history
When iterating through all the CU DIEs, only inspect those that have the
DW_TAG_compile_unit tag. When finishing the iteration, only keep going
to reset libdwarf's internal CU iterator if we found a DIE.
  • Loading branch information
Pedro Navarro committed May 26, 2018
1 parent d6bd449 commit 9524b15
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions backward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3032,28 +3032,37 @@ class TraceResolverLinuxImpl<trace_resolver_tag::libdwarf>:
// The search for aranges failed. Try to find our address by scanning
// all compilation units.
Dwarf_Unsigned next_cu_header;
while (dwarf_next_cu_header_d(dwarf, 1, 0, 0, 0, 0, 0, 0, 0, 0,
Dwarf_Half tag = 0;
returnDie = 0;

while (!found && dwarf_next_cu_header_d(dwarf, 1, 0, 0, 0, 0, 0, 0, 0, 0,
&next_cu_header, 0, &error) == DW_DLV_OK) {
if (dwarf_siblingof(dwarf, 0, &returnDie, &error) == DW_DLV_OK) {
if (die_has_pc(fobj, returnDie, addr)) {
found = true;
break;
}

if (returnDie)
dwarf_dealloc(dwarf, returnDie, DW_DLA_DIE);

if (dwarf_siblingof(dwarf, 0, &returnDie, &error) == DW_DLV_OK) {
if ((dwarf_tag(returnDie, &tag, &error) == DW_DLV_OK)
&& tag == DW_TAG_compile_unit) {
if (die_has_pc(fobj, returnDie, addr)) {
found = true;
}
}
}
}

while (dwarf_next_cu_header_d(dwarf, 1, 0, 0, 0, 0, 0, 0, 0, 0,
&next_cu_header, 0, &error) == DW_DLV_OK) {
// Reset the cu header state. Unfortunately, libdwarf's
// next_cu_header API keeps its own iterator per Dwarf_Debug that
// can't be reset. We need to keep fetching elements until the end.
if (found) {
while (dwarf_next_cu_header_d(dwarf, 1, 0, 0, 0, 0, 0, 0, 0, 0,
&next_cu_header, 0, &error) == DW_DLV_OK) {
// Reset the cu header state. Libdwarf's next_cu_header API
// keeps its own iterator per Dwarf_Debug that can't be reset.
// We need to keep fetching elements until the end.
}
}

if (found)
return returnDie;


// We couldn't find any compilation units with ranges or a high/low pc.
// Try again by looking at all DIEs in all compilation units.
Dwarf_Die cudie;
Expand All @@ -3071,11 +3080,13 @@ class TraceResolverLinuxImpl<trace_resolver_tag::libdwarf>:
}
}

while (dwarf_next_cu_header_d(dwarf, 1, 0, 0, 0, 0, 0, 0, 0, 0,
&next_cu_header, 0, &error) == DW_DLV_OK) {
// Reset the cu header state. Unfortunately, libdwarf's
// next_cu_header API keeps its own iterator per Dwarf_Debug that
// can't be reset. We need to keep fetching elements until the end.
if (found) {
while (dwarf_next_cu_header_d(dwarf, 1, 0, 0, 0, 0, 0, 0, 0, 0,
&next_cu_header, 0, &error) == DW_DLV_OK) {
// Reset the cu header state. Libdwarf's next_cu_header API
// keeps its own iterator per Dwarf_Debug that can't be reset.
// We need to keep fetching elements until the end.
}
}

if (found)
Expand Down

0 comments on commit 9524b15

Please sign in to comment.