[Lldb-commits] [lldb] [lldb][DataFormatter] unordered_map: account for new libc++ __hash_node layout (PR #68574)

via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 9 04:02:20 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

<details>
<summary>Changes</summary>

Since D101206 the `__hash_node::__value_` member is wrapped in an anonymous union. `ValueObject::GetChildMemberWithName` doesn't see through the union.

This patch accounts for this possible new layout by getting a handle to the union before doing the by-name `__value_` lookup.

---
Full diff: https://github.com/llvm/llvm-project/pull/68574.diff


1 Files Affected:

- (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp (+10-2) 


``````````diff
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 14776cdf808157d..03619385b7d9968 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -162,10 +162,18 @@ lldb::ValueObjectSP lldb_private::formatters::
       if (!node_sp || error.Fail())
           return nullptr;
 
-      value_sp = node_sp->GetChildMemberWithName("__value_");
       hash_sp = node_sp->GetChildMemberWithName("__hash_");
-      if (!value_sp || !hash_sp)
+      if (!hash_sp)
         return nullptr;
+
+      value_sp = node_sp->GetChildMemberWithName("__value_");
+      if (!value_sp) {
+        // Newer libc++ versions wrap the `__value_` in an anonymous union.
+        auto anon_union = node_sp->GetChildAtIndex(2);
+        value_sp = anon_union->GetChildMemberWithName("__value_");
+        if (!value_sp)
+          return nullptr;
+      }
     }
     m_elements_cache.push_back(
         {value_sp.get(), hash_sp->GetValueAsUnsigned(0)});

``````````

</details>


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


More information about the lldb-commits mailing list