[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 294246a77e1bb16a34e9451bae65ad340c7ef7a9 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/4] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 ++- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++--- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 +++-- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++--- .../Language/CPlusPlus/LibCxxVector.cpp | 38 ++-- .../list/TestDataFormatterGenericList.py | 2 +- 8 files changed, 282 insertions(+), 151 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName( ValueObject , llvm::ArrayRef alternative_names) { for
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 294246a77e1bb16a34e9451bae65ad340c7ef7a9 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/3] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 ++- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++--- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 +++-- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++--- .../Language/CPlusPlus/LibCxxVector.cpp | 38 ++-- .../list/TestDataFormatterGenericList.py | 2 +- 8 files changed, 282 insertions(+), 151 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName( ValueObject , llvm::ArrayRef alternative_names) { for
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 0358143d3bf98d66c1e7112b9e07109eb7b852a1 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/3] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 ++- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++--- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 +++-- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++--- .../Language/CPlusPlus/LibCxxVector.cpp | 38 ++-- .../list/TestDataFormatterGenericList.py | 2 +- 8 files changed, 282 insertions(+), 151 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName( ValueObject , llvm::ArrayRef alternative_names) { for
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 231e0ddc5834ac7fe8e4860c79504f6ce8666db5 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/3] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 ++- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++--- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 +++-- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++--- .../Language/CPlusPlus/LibCxxVector.cpp | 38 ++-- .../list/TestDataFormatterGenericList.py | 2 +- .../libcxx/string/simulator/main.cpp | 1 + 9 files changed, 283 insertions(+), 151 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName(
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/96538 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
@@ -254,6 +256,29 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd:: Update(); } +llvm::Expected +lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd:: +CalculateNumChildrenForOldCompressedPairLayout() { + ValueObjectSP node_sp(m_tree->GetChildMemberWithName("__pair3_")); + if (!node_sp) +return 0; + + // TODO: or should this just be: assert + // (!isOldCompressedPairLayout(*node_sp)); labath wrote: I don't think so, as this could also be triggered by a some change in libc++, missing/corrupted debug info, etc. https://github.com/llvm/llvm-project/pull/96538 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/96538 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) Changes 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). --- Patch is 26.60 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96538.diff 9 Files Affected: - (modified) lldb/examples/synthetic/libcxx.py (+20-6) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp (+63-22) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxx.h (+2-1) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp (+43-29) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp (+31-10) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp (+103-63) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp (+19-19) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py (+1-1) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/main.cpp (+1) ``diff diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 ready_for_review https://github.com/llvm/llvm-project/pull/96538 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/96538 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 231e0ddc5834ac7fe8e4860c79504f6ce8666db5 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 ++- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++--- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 +++-- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++--- .../Language/CPlusPlus/LibCxxVector.cpp | 38 ++-- .../list/TestDataFormatterGenericList.py | 2 +- .../libcxx/string/simulator/main.cpp | 1 + 9 files changed, 283 insertions(+), 151 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName(
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 125e24426cd897292f8839fbc4c6465ce915ac05 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 ++- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++--- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 +++-- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++--- .../Language/CPlusPlus/LibCxxVector.cpp | 40 +++-- .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 2 +- 10 files changed, 289 insertions(+), 150 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + lldb::ValueObjectSP
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 7de2db47a5be90a41a211d21210429e01cda945d Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 41 ++--- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 82 +- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 2 +- 10 files changed, 228 insertions(+), 127 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} +
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 1b47b3f3b0735a5a127372e93775e99fd2977e6f Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 85 ++- .../Plugins/Language/CPlusPlus/LibCxx.h | 3 +- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 72 +--- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 46 +++--- .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 82 +- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 2 +- 10 files changed, 233 insertions(+), 127 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index feaa51a96843a..7d3b2410a7296 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,32 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isOldCompressedPairLayout( +ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, + llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} +
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 2b82d72874c396258378f9db2f01729e5be5bae1 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH] [lldb] Support new libc++ __compressed_pair layout --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 78 - .../Plugins/Language/CPlusPlus/LibCxx.h | 1 + .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 83 --- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 68 +++ .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 82 +- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 2 +- 10 files changed, 253 insertions(+), 131 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..f23b8697792da 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -34,6 +35,31 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +static bool isOldCompressedPairLayout(ValueObject _obj) { + return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair"); +} + +static void consumeInlineNamespace(llvm::StringRef ) { + // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+:: + auto scratch = name; + if (scratch.consume_front("__") && std::isalnum(scratch[0])) { +scratch = scratch.drop_while([](char c) { return std::isalnum(c); }); +if (scratch.consume_front("::")) { + // Successfully consumed a namespace. + name = scratch; +} + } +} + +bool lldb_private::formatters::isStdTemplate(ConstString type_name, llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may be prefixed with `std::__::`. + if (name.consume_front("std::")) +consumeInlineNamespace(name); + return name.consume_front(type) && name.starts_with("<"); +} + + lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName(
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 634ae8b82e7b14f28d092735f573ad8f301ba731 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/3] [lldb] Support new libc++ __compressed_pair layout This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This gets the formatter tests to at least pass. Currently in draft because there's still some cleanup to be done. --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 61 ++ .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 83 --- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 68 +++ .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 62 +- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 7 +- 9 files changed, 246 insertions(+), 105 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..df17b7bbd1dad 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -176,9 +177,9 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( if (!ptr_sp) return false; - ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp); - if (!ptr_sp) -return false; + if (ValueObjectSP compressed_pair_value__sp = + GetFirstValueOfLibCXXCompressedPair(*ptr_sp)) +ptr_sp = std::move(compressed_pair_value__sp); if (ptr_sp->GetValueAsUnsigned(0) == 0) { stream.Printf("nullptr"); @@ -510,15 +511,28 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::Update() { if (!ptr_sp) return lldb::ChildCacheState::eRefetch; + bool has_compressed_pair_layout = true; + ValueObjectSP deleter_sp(valobj_sp->GetChildMemberWithName("__deleter_")); + if (deleter_sp) +has_compressed_pair_layout = false; + // Retrieve the actual pointer and the deleter, and clone them to give them // user-friendly
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 0d39f1ecfb9643f944aa1352d4a307e5638ab08f Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/2] [lldb] Support new libc++ __compressed_pair layout This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This gets the formatter tests to at least pass. Currently in draft because there's still some cleanup to be done. --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 61 ++ .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 83 --- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 68 +++ .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 62 +- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 7 +- 9 files changed, 246 insertions(+), 105 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23a..060ff901008497 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 0f9f93b727ce86..1eee1d9cec7e82 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -176,9 +177,9 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( if (!ptr_sp) return false; - ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp); - if (!ptr_sp) -return false; + if (ValueObjectSP compressed_pair_value__sp = + GetFirstValueOfLibCXXCompressedPair(*ptr_sp)) +ptr_sp = std::move(compressed_pair_value__sp); if (ptr_sp->GetValueAsUnsigned(0) == 0) { stream.Printf("nullptr"); @@ -701,15 +702,28 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::Update() { if (!ptr_sp) return lldb::ChildCacheState::eRefetch; + bool has_compressed_pair_layout = true; + ValueObjectSP deleter_sp(valobj_sp->GetChildMemberWithName("__deleter_")); + if (deleter_sp) +has_compressed_pair_layout = false; + // Retrieve the actual pointer and the deleter, and clone them to give them // user-friendly
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96538 >From 3b4d9629a68c9e75dfd139ee2745bf00db979ecd Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH 1/2] [lldb] Support new libc++ __compressed_pair layout This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This gets the formatter tests to at least pass. Currently in draft because there's still some cleanup to be done. --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 61 ++ .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 83 --- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 68 +++ .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 73 +++- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 7 +- 9 files changed, 256 insertions(+), 106 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index b0e6fb7d6f5af..928b790317b6e 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -176,9 +177,9 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( if (!ptr_sp) return false; - ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp); - if (!ptr_sp) -return false; + if (ValueObjectSP compressed_pair_value__sp = + GetFirstValueOfLibCXXCompressedPair(*ptr_sp)) +ptr_sp = std::move(compressed_pair_value__sp); if (ptr_sp->GetValueAsUnsigned(0) == 0) { stream.Printf("nullptr"); @@ -701,15 +702,28 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::Update() { if (!ptr_sp) return lldb::ChildCacheState::eRefetch; + bool has_compressed_pair_layout = true; + ValueObjectSP deleter_sp(valobj_sp->GetChildMemberWithName("__deleter_")); + if (deleter_sp) +has_compressed_pair_layout = false; + // Retrieve the actual pointer and the deleter, and clone them to give them // user-friendly
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 62baf21daa377c4ec1a641b26931063c1117d262...3b4d9629a68c9e75dfd139ee2745bf00db979ecd lldb/examples/synthetic/libcxx.py lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py `` View the diff from darker here. ``diff --- examples/synthetic/libcxx.py2024-06-24 19:22:02.00 + +++ examples/synthetic/libcxx.py2024-06-24 19:26:18.844345 + @@ -762,11 +762,13 @@ if has_compressed_pair_layout: map_endcap = self._get_value_of_compressed_pair( map_.GetChildMemberWithName("__end_cap_") ) else: -map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) +map_endcap = map_.GetChildMemberWithName( +"__end_cap_" +).GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: logger.write("map pointers are not monotonic") return --- test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py 2024-06-24 19:22:02.00 + +++ test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py 2024-06-24 19:26:18.939102 + @@ -60,12 +60,12 @@ self.runCmd("type format add -f hex int") self.expect( "frame variable numbers_list --raw", matching=False, -#substrs=["size=0", "{}"], # TODO: if __padding_ members aren't added this isn't needed -substrs=["size=0"] +# substrs=["size=0", "{}"], # TODO: if __padding_ members aren't added this isn't needed +substrs=["size=0"], ) if stdlib_type == USE_LIBSTDCPP: self.expect( "frame variable _list._M_impl._M_node --raw", --- test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py 2024-06-24 19:22:02.00 + +++ test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py 2024-06-24 19:26:18.994855 + @@ -43,11 +43,11 @@ valobj = self.expect_var_path( "up_empty", type=self.make_expected_type("int"), summary="nullptr", -#children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter +# children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter children=[ValueCheck(name="pointer")], ) self.assertEqual( valobj.child[0].GetValueAsUnsigned(lldb.LLDB_INVALID_ADDRESS), 0 ) @@ -58,38 +58,38 @@ valobj = self.expect_var_path( "up_int", type=self.make_expected_type("int"), summary="10", -#children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter +# children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter children=[ValueCheck(name="pointer")], ) self.assertNotEqual(valobj.child[0].unsigned, 0) valobj = self.expect_var_path( "up_int_ref", type=self.make_expected_type("int", qualifiers="&"), summary="10", -#children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter +# children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter children=[ValueCheck(name="pointer")], ) self.assertNotEqual(valobj.child[0].unsigned, 0) valobj = self.expect_var_path( "up_int_ref_ref", type=self.make_expected_type("int", qualifiers="&&"), summary="10", -#children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter +# children=[ValueCheck(name="pointer"), ValueCheck(name="deleter")], # TODO: shouldn't be printing deleter children=[ValueCheck(name="pointer")], ) self.assertNotEqual(valobj.child[0].unsigned, 0) valobj = self.expect_var_path( "up_str", type=self.make_expected_basic_string_ptr(), summary='"hello"', -#children=[ValueCheck(name="pointer"),
[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/96538 This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This gets the formatter tests to at least pass. Currently in draft because there's still some cleanup to be done. >From 3b4d9629a68c9e75dfd139ee2745bf00db979ecd Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 29 Jan 2024 16:23:16 + Subject: [PATCH] [lldb] Support new libc++ __compressed_pair layout This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This gets the formatter tests to at least pass. Currently in draft because there's still some cleanup to be done. --- lldb/examples/synthetic/libcxx.py | 26 -- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 61 ++ .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 83 --- .../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 68 +++ .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 73 +++- .../Language/CPlusPlus/LibCxxVector.cpp | 40 + .../list/TestDataFormatterGenericList.py | 3 +- .../libcxx/string/simulator/main.cpp | 1 + .../TestDataFormatterLibcxxUniquePtr.py | 7 +- 9 files changed, 256 insertions(+), 106 deletions(-) diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 474aaa428fa23..060ff90100849 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair): def update(self): logger = lldb.formatters.Logger.Logger() try: +has_compressed_pair_layout = True +alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_") +size_valobj = self.valobj.GetChildMemberWithName("__size_") +if alloc_valobj.IsValid() and size_valobj.IsValid(): +has_compressed_pair_layout = False + # A deque is effectively a two-dim array, with fixed width. # 'map' contains pointers to the rows of this array. The # full memory area allocated by the deque is delimited @@ -734,9 +740,13 @@ def update(self): # variable tells which element in this NxM array is the 0th # one, and the 'size' element gives the number of elements # in the deque. -count = self._get_value_of_compressed_pair( -self.valobj.GetChildMemberWithName("__size_") -) +if has_compressed_pair_layout: +count = self._get_value_of_compressed_pair( +self.valobj.GetChildMemberWithName("__size_") +) +else: +count = size_valobj.GetValueAsUnsigned(0) + # give up now if we cant access memory reliably if self.block_size < 0: logger.write("block_size < 0") @@ -748,9 +758,13 @@ def update(self): self.map_begin = map_.GetChildMemberWithName("__begin_") map_begin = self.map_begin.GetValueAsUnsigned(0) map_end = map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0) -map_endcap = self._get_value_of_compressed_pair( -map_.GetChildMemberWithName("__end_cap_") -) + +if has_compressed_pair_layout: +map_endcap = self._get_value_of_compressed_pair( +map_.GetChildMemberWithName("__end_cap_") +) +else: +map_endcap = map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0) # check consistency if not map_first <= map_begin <= map_end <= map_endcap: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index b0e6fb7d6f5af..928b790317b6e 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -27,6 +27,7 @@ #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include #include @@ -176,9 +177,9 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( if (!ptr_sp) return false; - ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp); - if (!ptr_sp) -return false; + if (ValueObjectSP compressed_pair_value__sp = + GetFirstValueOfLibCXXCompressedPair(*ptr_sp)) +ptr_sp = std::move(compressed_pair_value__sp); if (ptr_sp->GetValueAsUnsigned(0) == 0) { stream.Printf("nullptr"); @@ -701,15 +702,28 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::Update() { if (!ptr_sp) return lldb::ChildCacheState::eRefetch; + bool has_compressed_pair_layout = true; +