[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
Fri Oct 13 08:26:22 PDT 2023
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/68574
>From a421f1883e5b3544ec4b2ceb2bba6fac912c3ffb 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/4] [lldb][DataFormatter] unordered_map: account for new
libc++ __hash_node layout
Since D101206 (`ba79fb2e1ff7130cde02fbbd325f0f96f8a522ca`) 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.
---
.../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 33475b1374a8adc1f5e9fc55e092e7aa9fe03ce6 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/4] 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;
>From 819c92f8793a0547293e419be9394559add46564 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 13 Oct 2023 16:07:49 +0100
Subject: [PATCH 3/4] fixup! add commit hash to comment
---
lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index ac3362b3dbb601c..03cc4b41661cfd8 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -168,7 +168,7 @@ lldb::ValueObjectSP lldb_private::formatters::
value_sp = node_sp->GetChildMemberWithName("__value_");
if (!value_sp) {
- // Since D101206, libc++ wraps the `__value_` in an anonymous union.
+ // Since D101206 (ba79fb2e1f), libc++ wraps the `__value_` in an anonymous union.
// Child 0: __hash_node_base base class
// Child 1: __hash_
// Child 2: anonymous union
>From 522abff41d1ddf0a26fdd80e89b66adc0481248f Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 13 Oct 2023 16:26:02 +0100
Subject: [PATCH 4/4] fixup! clang-format
---
.../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 03cc4b41661cfd8..2e8da396a4a7b25 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -168,10 +168,13 @@ lldb::ValueObjectSP lldb_private::formatters::
value_sp = node_sp->GetChildMemberWithName("__value_");
if (!value_sp) {
- // Since D101206 (ba79fb2e1f), libc++ wraps the `__value_` in an anonymous union.
+ // clang-format off
+ // Since D101206 (ba79fb2e1f), libc++ wraps the `__value_` in an
+ // anonymous union.
// Child 0: __hash_node_base base class
// Child 1: __hash_
// Child 2: anonymous union
+ // clang-format on
auto anon_union_sp = node_sp->GetChildAtIndex(2);
if (!anon_union_sp)
return nullptr;
More information about the lldb-commits
mailing list