[PATCH] D110363: [DWARF][NFC] add ParentIdx and SiblingIdx to DWARFDebugInfoEntry for faster navigation.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 28 04:10:02 PDT 2021


avl added a comment.

> So the DWARFUnit class no longer needs to be involved in the getting the parent, sibling, child stuff if we end up setting ParentIdx and SiblingIdx as a relative offset. LLDB's DWARF parser stores, and yes has a bad name for, the parent index which is the offset to subtract from "this" where "this" is a DWARFDebugInfoEntry. Since the DWARFUnits store an vector of DWARFDebugInfoEntry items after it parses all of the DIEs, then you can just subtract "ParentIdx" (which might be better named "ParentOffset") from "this" and get the correct DWARFDebugInfoEntry. Same with the SiblingIdx, if it is non zero, it is the offset to add to "this" to get the sibling. See inlined comments and see LLDB's DWARFDebugInfoEntry.h/.cpp and DWARFDie.h/.cpp.

Oh, I missed the idea to not use DWARFUnit for navigation. Will change indexes to deltas.



================
Comment at: llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp:839
 
 DWARFDie DWARFUnit::getLastChild(const DWARFDebugInfoEntry *Die) {
   if (!Die->hasChildren())
----------------
clayborg wrote:
> This function could be done down in DWARFDebugInfoEntry now.
Only this part could not be moved into the DWARFDebugInfoEntry:


```
  uint32_t DieIdx = getDIEIndex(Die);
  if (DieIdx == 0 && DieArray.size() > 1 &&
      DieArray.back().getTag() == dwarf::DW_TAG_null) {
    // For the unit die we might take last item from DieArray.
    assert(DieIdx == getDIEIndex(getUnitDIE()) && "Bad unit die");
    return DWARFDie(this, &DieArray.back());
  }
```

Thus, it looks like getLastChild may still be implemented in DWARFUnit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110363/new/

https://reviews.llvm.org/D110363



More information about the llvm-commits mailing list