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

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 9 05:43:18 PDT 2023


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

>From 9001e6a7ac69e14444a45f9d32153335feda5523 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Mon, 9 Oct 2023 11:54:56 +0100
Subject: [PATCH] [lldb][DataFormatter] unordered_map: account for new libc++
 __hash_node layout

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.

(cherry picked from commit 49233f786c986e2796af7a432c728596758495c5)
---
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp     | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 14776cdf808157d..0200c2b46360c13 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -162,10 +162,21 @@ 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_sp = node_sp->GetChildAtIndex(2);
+        if (!anon_union_sp)
+          return nullptr;
+
+        value_sp = anon_union_sp->GetChildMemberWithName("__value_");
+        if (!value_sp)
+          return nullptr;
+      }
     }
     m_elements_cache.push_back(
         {value_sp.get(), hash_sp->GetValueAsUnsigned(0)});



More information about the lldb-commits mailing list