[Lldb-commits] [lldb] [lldb][DWARF] Change GetAttributes to always visit current DIE before recursing (PR #123261)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 17 01:54:37 PST 2025


================
@@ -339,6 +348,39 @@ void DWARFDebugInfoEntry::GetAttributes(DWARFUnit *cu,
         DWARFFormValue::SkipValue(form, data, &offset, cu);
     }
   }
+
+  return true;
+}
+
+DWARFAttributes DWARFDebugInfoEntry::GetAttributes(const DWARFUnit *cu,
+                                                   Recurse recurse) const {
+  // FIXME: use ElaboratingDIEIterator to follow specifications/abstract origins
+  // instead of maintaining our own worklist/seen list.
+
+  DWARFAttributes attributes;
+
+  llvm::SmallVector<DWARFDIE, 3> worklist;
+  worklist.emplace_back(cu, this);
+
+  // Keep track if DIEs already seen to prevent infinite recursion.
+  // Value of '3' was picked for the same reason that
+  // DWARFDie::findRecursively does.
+  llvm::SmallSet<DWARFDebugInfoEntry const *, 3> seen;
+  seen.insert(this);
+
+  while (!worklist.empty()) {
+    if (!::GetAttributes(cu, worklist, seen, attributes)) {
+      attributes.Clear();
+      break;
+    }
+
+    // We visited the current DIE already and were asked not to check the
+    // rest of the worklist. So bail out.
+    if (recurse == Recurse::no)
+      break;
+  }
----------------
labath wrote:

```suggestion
  do {
    if (!::GetAttributes(cu, worklist, seen, attributes)) {
      attributes.Clear();
      break;
    }
  } while (!worklist.empty() && recurse == Recurse::yes);
```

If you want to be fancy :)

https://github.com/llvm/llvm-project/pull/123261


More information about the lldb-commits mailing list