[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 13:53:00 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 1/2] [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)});
>From 8ff81e25de4f991d8eae6e5ec1d31868d57a41cf Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Mon, 9 Oct 2023 21:51:15 +0100
Subject: [PATCH 2/2] fixup! provide more context in comment
---
.../source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 0200c2b46360c13..ac3362b3dbb601c 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -168,7 +168,10 @@ lldb::ValueObjectSP lldb_private::formatters::
value_sp = node_sp->GetChildMemberWithName("__value_");
if (!value_sp) {
- // Newer libc++ versions wrap the `__value_` in an anonymous union.
+ // Since D101206, libc++ wraps the `__value_` in an anonymous union.
+ // Child 0: __hash_node_base base class
+ // Child 1: __hash_
+ // Child 2: anonymous union
auto anon_union_sp = node_sp->GetChildAtIndex(2);
if (!anon_union_sp)
return nullptr;
More information about the lldb-commits
mailing list