Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symbolizer: cache each DWARF DIE's nextOffset and nextSiblingOffset #2111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions folly/experimental/symbolizer/DwarfImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,13 @@ size_t DwarfImpl::forEachChild(
const CompilationUnit& cu,
const Die& die,
folly::FunctionRef<bool(const Die& die)> f) const {
size_t nextDieOffset =
forEachAttribute(cu, die, [&](const Attribute&) { return true; });
size_t nextDieOffset = die.nextOffset;
if (!nextDieOffset) {
nextDieOffset =
forEachAttribute(cu, die, [&](const Attribute&) { return true; });
}
if (!die.abbr.hasChildren) {
die.nextSiblingOffset = nextDieOffset;
return nextDieOffset;
}

Expand All @@ -387,15 +391,20 @@ size_t DwarfImpl::forEachChild(
return childDie.offset;
}

// NOTE: Don't run `f` over grandchildren, just skip over them.
size_t siblingOffset =
forEachChild(cu, childDie, [](const Die&) { return true; });
// Use childDie.nextSiblingOffset to skip grandchildren if known
size_t siblingOffset = childDie.nextSiblingOffset;
if (!siblingOffset) {
// NOTE: Don't run `f` over grandchildren, just skip over them.
siblingOffset =
forEachChild(cu, childDie, [](const Die&) { return true; });
}
childDie = getDieAtOffset(cu, siblingOffset);
}

// childDie is now a dummy die whose offset is to the code 0 marking the
// end of the children. Need to add one to get the offset of the next die.
return childDie.offset + 1;
die.nextSiblingOffset = childDie.offset + 1;
return die.nextSiblingOffset;;
}

bool DwarfImpl::isAddrInRangeList(
Expand Down
7 changes: 6 additions & 1 deletion folly/experimental/symbolizer/DwarfUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,13 @@ size_t forEachAttribute(
if (!f(attr)) {
return static_cast<size_t>(-1);
}
if (spec.name == DW_AT_sibling && !die.nextSiblingOffset &&
spec.form != DW_FORM_ref_addr) {
die.nextSiblingOffset = cu.offset + boost::get<uint64_t>(attr.attrValue);
}
}
return values.data() - cu.debugSections.debugInfo.data();
die.nextOffset = values.data() - cu.debugSections.debugInfo.data();
return die.nextOffset;
}

folly::StringPiece getFunctionNameFromDie(
Expand Down
17 changes: 17 additions & 0 deletions folly/experimental/symbolizer/DwarfUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ struct Die {
uint8_t attrOffset = 0;
// Offset within debug info.
uint32_t offset = 0;

// If nonzero, nextOffset is the offset within .debug_info
// corresponding to the beginning of this DIE's first child or next
// sibling (depending on whether abbr.hasChildren). This is what
// forEachAttribute() would return. So nextOffset - offset is the
// length of this DIE. If this points to a zero byte then there
// are no children or no further siblings. If the offset itself
// is zero, we don't know yet what it should be.
mutable uint32_t nextOffset = 0;

// If nonzero, nextSiblingOffset is the offset within .debug_info
// corresponding to the beginning of this DIE's next sibling.
// This is what forEachChild() would return. If this points to
// a zero byte then there are no further siblings. If the offset
// itself is zero, we don't know yet what it should be.
mutable uint32_t nextSiblingOffset = 0;

uint64_t code = 0;
DIEAbbreviation abbr;
};
Expand Down