[llvm] [DebugNames] Implement Entry::GetParentEntry query (PR #78760)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 13:08:37 PST 2024


================
@@ -460,6 +460,16 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
     /// Returns the Offset of the DIE within the containing CU or TU.
     std::optional<uint64_t> getDIEUnitOffset() const;
 
+    /// Returns true if this Entry has information about its parent DIE (i.e. if
+    /// it has an IDX_parent attribute)
+    bool hasParentInformation() const;
+
+    /// Returns the Entry corresponding to the parent of the DIE represented by
+    /// `this` Entry. If the parent is not in the table, nullopt is returned.
+    /// Precondition: hasParentInformation() == true.
+    /// An error is returned for ill-formed tables.
+    Expected<std::optional<DWARFDebugNames::Entry>> getParentDIEEntry() const;
----------------
felipepiovezan wrote:

Yeah, this is the bit about this patch that I really dislike. But we have two distinct things we need to account for here:

1. Invalid data: a bad offset for some reason. This is what the `Expected` is handling.
2. When the parent is present but not indexed by the table (e.g. the end of the parent chain). This is what the `optional` is handling.

We could remove the error handling portion (the `Expected`) and treat case 1 as if it were case 2, but it would make debugging the invalid data case a bit difficult, if we ever have to do that.

What do you think?

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


More information about the llvm-commits mailing list