aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2024-09-16 10:11:49 +0100
committerGitHub <noreply@github.com>2024-09-16 10:11:49 +0100
commit9e9b1178ca435f690381ffe8241e4bf1bb7e60fb (patch)
treebde0c647e2c5f89b48532b2e960c4c0b7e065d6c /lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
parent8d89f83db0937db318947a546e690fc8b0d22beb (diff)
downloadllvm-9e9b1178ca435f690381ffe8241e4bf1bb7e60fb.zip
llvm-9e9b1178ca435f690381ffe8241e4bf1bb7e60fb.tar.gz
llvm-9e9b1178ca435f690381ffe8241e4bf1bb7e60fb.tar.bz2
[lldb] Support new libc++ __compressed_pair layout (#96538)
This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This is mostly reviewable now. With the new layout we no longer need to unwrap the `__compressed_pair`. Instead, we just need to look for child members. E.g., to get to the underlying pointer of `std::unique_ptr` we no longer do, ``` GetFirstValueOfCXXCompressedPair(GetChildMemberWithName("__ptr_")) ``` but instead do ``` GetChildMemberWithName("__ptr_") ``` We need to be slightly careful because previously the `__compressed_pair` had a member called `__value_`, whereas now `__value_` might be a member of the class that used to hold the `__compressed_pair`. So before unwrapping the pair, we added checks for `isOldCompressedLayout` (not sure yet whether folding this check into `GetFirstValueOfCXXCompressedPair` is better).
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp')
-rw-r--r--lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 5106a63..af3e41b 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -202,6 +202,8 @@ public:
size_t GetIndexOfChildWithName(ConstString name) override;
private:
+ llvm::Expected<uint32_t> CalculateNumChildrenForOldCompressedPairLayout();
+
/// Returns the ValueObject for the __tree_node type that
/// holds the key/value pair of the node at index \ref idx.
///
@@ -254,6 +256,27 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
Update();
}
+llvm::Expected<uint32_t>
+lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
+ CalculateNumChildrenForOldCompressedPairLayout() {
+ ValueObjectSP node_sp(m_tree->GetChildMemberWithName("__pair3_"));
+ if (!node_sp)
+ return 0;
+
+ if (!isOldCompressedPairLayout(*node_sp))
+ return llvm::createStringError("Unexpected std::map layout: expected "
+ "old __compressed_pair layout.");
+
+ node_sp = GetFirstValueOfLibCXXCompressedPair(*node_sp);
+
+ if (!node_sp)
+ return 0;
+
+ m_count = node_sp->GetValueAsUnsigned(0);
+
+ return m_count;
+}
+
llvm::Expected<uint32_t> lldb_private::formatters::
LibcxxStdMapSyntheticFrontEnd::CalculateNumChildren() {
if (m_count != UINT32_MAX)
@@ -262,17 +285,12 @@ llvm::Expected<uint32_t> lldb_private::formatters::
if (m_tree == nullptr)
return 0;
- ValueObjectSP size_node(m_tree->GetChildMemberWithName("__pair3_"));
- if (!size_node)
- return 0;
-
- size_node = GetFirstValueOfLibCXXCompressedPair(*size_node);
-
- if (!size_node)
- return 0;
+ if (auto node_sp = m_tree->GetChildMemberWithName("__size_")) {
+ m_count = node_sp->GetValueAsUnsigned(0);
+ return m_count;
+ }
- m_count = size_node->GetValueAsUnsigned(0);
- return m_count;
+ return CalculateNumChildrenForOldCompressedPairLayout();
}
ValueObjectSP
@@ -371,6 +389,7 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::Update() {
m_tree = m_backend.GetChildMemberWithName("__tree_").get();
if (!m_tree)
return lldb::ChildCacheState::eRefetch;
+
m_root_node = m_tree->GetChildMemberWithName("__begin_node_").get();
m_node_ptr_type =
m_tree->GetCompilerType().GetDirectNestedTypeWithName("__node_pointer");