[Lldb-commits] [lldb] 2f4a66e - Adapt LLDB dataformatters for libcxx change D129386
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 9 15:59:34 PDT 2022
Author: Adrian Prantl
Date: 2022-09-09T15:58:55-07:00
New Revision: 2f4a66eed68804929efa1ad3c10fc040a67fb3ff
URL: https://github.com/llvm/llvm-project/commit/2f4a66eed68804929efa1ad3c10fc040a67fb3ff
DIFF: https://github.com/llvm/llvm-project/commit/2f4a66eed68804929efa1ad3c10fc040a67fb3ff.diff
LOG: Adapt LLDB dataformatters for libcxx change D129386
Differential Revision: https://reviews.llvm.org/D133618
Added:
Modified:
lldb/include/lldb/DataFormatters/VectorIterator.h
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.h
lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/DataFormatters/VectorIterator.h b/lldb/include/lldb/DataFormatters/VectorIterator.h
index 33650a3dac8fc..3414298f255b6 100644
--- a/lldb/include/lldb/DataFormatters/VectorIterator.h
+++ b/lldb/include/lldb/DataFormatters/VectorIterator.h
@@ -15,13 +15,14 @@
#include "lldb/DataFormatters/TypeSynthetic.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/ConstString.h"
+#include "llvm/ADT/SmallVector.h"
namespace lldb_private {
namespace formatters {
class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
VectorIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp,
- ConstString item_name);
+ llvm::ArrayRef<ConstString> item_names);
size_t CalculateNumChildren() override;
@@ -35,7 +36,7 @@ class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
private:
ExecutionContextRef m_exe_ctx_ref;
- ConstString m_item_name;
+ llvm::SmallVector<ConstString, 2> m_item_names;
lldb::ValueObjectSP m_item_sp;
};
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 3b04b3a1b2acc..2480dbf8a2a60 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -34,6 +34,17 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
+lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName(
+ ValueObject &obj, llvm::ArrayRef<ConstString> alternative_names) {
+ for (ConstString name : alternative_names) {
+ lldb::ValueObjectSP child_sp = obj.GetChildMemberWithName(name, true);
+
+ if (child_sp)
+ return child_sp;
+ }
+ return {};
+}
+
bool lldb_private::formatters::LibcxxOptionalSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
@@ -538,12 +549,9 @@ lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEndCreator(
SyntheticChildrenFrontEnd *
lldb_private::formatters::LibCxxVectorIteratorSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
- static ConstString g_item_name;
- if (!g_item_name)
- g_item_name.SetCString("__i");
- return (valobj_sp
- ? new VectorIteratorSyntheticFrontEnd(valobj_sp, g_item_name)
- : nullptr);
+ return (valobj_sp ? new VectorIteratorSyntheticFrontEnd(
+ valobj_sp, {ConstString("__i_"), ConstString("__i")})
+ : nullptr);
}
lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::
@@ -992,11 +1000,10 @@ bool lldb_private::formatters::LibcxxStringSummaryProviderUTF32(
static std::tuple<bool, ValueObjectSP, size_t>
LibcxxExtractStringViewData(ValueObject& valobj) {
- ConstString g_data_name("__data");
- ConstString g_size_name("__size");
- auto dataobj = valobj.GetChildMemberWithName(g_data_name, true);
- auto sizeobj = valobj.GetChildMemberWithName(g_size_name, true);
-
+ auto dataobj = GetChildMemberWithName(
+ valobj, {ConstString("__data_"), ConstString("__data")});
+ auto sizeobj = GetChildMemberWithName(
+ valobj, {ConstString("__size_"), ConstString("__size")});
if (!dataobj || !sizeobj)
return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index b5ade4af8574a..96b4c10f32cea 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -18,6 +18,11 @@
namespace lldb_private {
namespace formatters {
+/// Find a child member of \c obj_sp, trying all alternative names in order.
+lldb::ValueObjectSP
+GetChildMemberWithName(ValueObject &obj,
+ llvm::ArrayRef<ConstString> alternative_names);
+
bool LibcxxStringSummaryProviderASCII(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options); // libc++ std::string
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index ca6f92d003ad9..04033df282b76 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -328,7 +328,7 @@ void lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
lldb::ValueObjectSP
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
size_t idx) {
- static ConstString g_cc("__cc");
+ static ConstString g_cc_("__cc_"), g_cc("__cc");
static ConstString g_nc("__nc");
static ConstString g_value_("__value_");
@@ -414,15 +414,17 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
switch (potential_child_sp->GetNumChildren()) {
case 1: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0, true);
- if (child0_sp && child0_sp->GetName() == g_cc)
+ if (child0_sp &&
+ (child0_sp->GetName() == g_cc_ || child0_sp->GetName() == g_cc))
potential_child_sp = child0_sp->Clone(ConstString(name.GetString()));
break;
}
case 2: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0, true);
auto child1_sp = potential_child_sp->GetChildAtIndex(1, true);
- if (child0_sp && child0_sp->GetName() == g_cc && child1_sp &&
- child1_sp->GetName() == g_nc)
+ if (child0_sp &&
+ (child0_sp->GetName() == g_cc_ || child0_sp->GetName() == g_cc) &&
+ child1_sp && child1_sp->GetName() == g_nc)
potential_child_sp = child0_sp->Clone(ConstString(name.GetString()));
break;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
index 0379ba2d85ad5..8cd035cbae296 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
@@ -94,8 +94,8 @@ lldb_private::formatters::LibcxxStdSpanSyntheticFrontEnd::GetChildAtIndex(
bool lldb_private::formatters::LibcxxStdSpanSyntheticFrontEnd::Update() {
// Get element type.
- ValueObjectSP data_type_finder_sp(
- m_backend.GetChildMemberWithName(ConstString("__data"), true));
+ ValueObjectSP data_type_finder_sp = GetChildMemberWithName(
+ m_backend, {ConstString("__data_"), ConstString("__data")});
if (!data_type_finder_sp)
return false;
@@ -111,8 +111,8 @@ bool lldb_private::formatters::LibcxxStdSpanSyntheticFrontEnd::Update() {
}
// Get number of elements.
- if (auto size_sp =
- m_backend.GetChildMemberWithName(ConstString("__size"), true)) {
+ if (auto size_sp = GetChildMemberWithName(
+ m_backend, {ConstString("__size_"), ConstString("__size")})) {
m_num_elements = size_sp->GetValueAsUnsigned(0);
} else if (auto arg =
m_backend.GetCompilerType().GetIntegralTemplateArgument(1)) {
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
index 951bf2896fb08..8f90c56890e43 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "LibCxxVariant.h"
+#include "LibCxx.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "llvm/ADT/Optional.h"
@@ -121,8 +122,8 @@ bool LibcxxVariantSummaryProvider(ValueObject &valobj, Stream &stream,
if (!valobj_sp)
return false;
- ValueObjectSP impl_sp(
- valobj_sp->GetChildMemberWithName(ConstString("__impl"), true));
+ ValueObjectSP impl_sp = GetChildMemberWithName(
+ *valobj_sp, {ConstString("__impl_"), ConstString("__impl")});
if (!impl_sp)
return false;
@@ -189,8 +190,8 @@ class VariantFrontEnd : public SyntheticChildrenFrontEnd {
bool VariantFrontEnd::Update() {
m_size = 0;
- ValueObjectSP impl_sp(
- m_backend.GetChildMemberWithName(ConstString("__impl"), true));
+ ValueObjectSP impl_sp = formatters::GetChildMemberWithName(
+ m_backend, {ConstString("__impl_"), ConstString("__impl")});
if (!impl_sp)
return false;
@@ -209,38 +210,40 @@ bool VariantFrontEnd::Update() {
ValueObjectSP VariantFrontEnd::GetChildAtIndex(size_t idx) {
if (idx >= m_size)
- return ValueObjectSP();
+ return {};
- ValueObjectSP impl_sp(
- m_backend.GetChildMemberWithName(ConstString("__impl"), true));
+ ValueObjectSP impl_sp = formatters::GetChildMemberWithName(
+ m_backend, {ConstString("__impl_"), ConstString("__impl")});
+ if (!impl_sp)
+ return {};
auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
if (!optional_index_value)
- return ValueObjectSP();
+ return {};
uint64_t index_value = *optional_index_value;
ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
if (!nth_head)
- return ValueObjectSP();
+ return {};
CompilerType head_type = nth_head->GetCompilerType();
if (!head_type)
- return ValueObjectSP();
+ return {};
CompilerType template_type = head_type.GetTypeTemplateArgument(1);
if (!template_type)
- return ValueObjectSP();
+ return {};
ValueObjectSP head_value(
nth_head->GetChildMemberWithName(ConstString("__value"), true));
if (!head_value)
- return ValueObjectSP();
+ return {};
return head_value->Clone(ConstString("Value"));
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.h
index b4c27ccb9d771..9488d94efda70 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.h
@@ -1,5 +1,4 @@
-//===-- LibCxxVariant.h -------------------------------------------*- C++
-//-*-===//
+//===-- LibCxxVariant.h ----------------------------------------*- C++ -*--===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index d8623641b03fb..6aa80f44d2485 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "LibStdcpp.h"
+#include "LibCxx.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/Core/ValueObject.h"
@@ -169,19 +170,16 @@ lldb_private::formatters::LibstdcppMapIteratorSyntheticFrontEndCreator(
SyntheticChildrenFrontEnd *
lldb_private::formatters::LibStdcppVectorIteratorSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
- static ConstString g_item_name;
- if (!g_item_name)
- g_item_name.SetCString("_M_current");
- return (valobj_sp
- ? new VectorIteratorSyntheticFrontEnd(valobj_sp, g_item_name)
- : nullptr);
+ return (valobj_sp ? new VectorIteratorSyntheticFrontEnd(
+ valobj_sp, {ConstString("_M_current")})
+ : nullptr);
}
lldb_private::formatters::VectorIteratorSyntheticFrontEnd::
VectorIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp,
- ConstString item_name)
+ llvm::ArrayRef<ConstString> item_names)
: SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(),
- m_item_name(item_name), m_item_sp() {
+ m_item_names(item_names), m_item_sp() {
if (valobj_sp)
Update();
}
@@ -196,7 +194,8 @@ bool VectorIteratorSyntheticFrontEnd::Update() {
if (!valobj_sp)
return false;
- ValueObjectSP item_ptr(valobj_sp->GetChildMemberWithName(m_item_name, true));
+ ValueObjectSP item_ptr =
+ formatters::GetChildMemberWithName(*valobj_sp, m_item_names);
if (!item_ptr)
return false;
if (item_ptr->GetValueAsUnsigned(0) == 0)
diff --git a/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py b/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
index 7b514b0c6dd77..5f397ab1218b9 100644
--- a/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
+++ b/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
@@ -10,7 +10,7 @@
class TestBasicDeque(TestBase):
@add_test_categories(["libc++"])
- @expectedFailureDarwin
+ @expectedFailureDarwin # FIXME: May need to force system libcxx here.
@skipIf(compiler=no_match("clang"))
def test(self):
self.build()
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
index b6682e5c7e930..55db9c2051cca 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
@@ -19,7 +19,6 @@ def setUp(self):
self.line = line_number('main.cpp', '// Set break point at this line.')
self.namespace = 'std'
- @expectedFailureDarwin # FIXME: May need to force system libcxx here.
@add_test_categories(["libc++"])
def test_with_run_command(self):
"""Test that libc++ iterators format properly."""
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
index 6d78659d43f45..3236544e21859 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
@@ -43,7 +43,6 @@ def check_numbers(self, var_name):
self.expect_var_path(f'{var_name}[4]', type='int', value='12345')
@add_test_categories(['libc++'])
- @expectedFailureDarwin # FIXME: May need to force system libcxx here.
@skipIf(compiler='clang', compiler_version=['<', '11.0'])
def test_with_run_command(self):
"""Test that std::span variables are formatted correctly when printed."""
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
index 1090e6c60c202..db82e7c65e033 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
@@ -21,7 +21,6 @@ def setUp(self):
self.line2 = line_number('main.cpp', '// Break here to look at bad string view.' )
@add_test_categories(["libc++"])
- @expectedFailureDarwin # FIXME: May need to force system libcxx here.
@expectedFailureAll(bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android")
# Inline namespace is randomly ignored as Clang due to broken lookup inside
# the std namespace.
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
index 9cb36e41c7326..fbd7c8b21b9e4 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
@@ -19,7 +19,6 @@ class LibcxxVariantDataFormatterTestCase(TestBase):
@skipIf(compiler="gcc", compiler_version=['<', '5.1'])
## std::get is unavailable for std::variant before macOS 10.14
@skipIf(macos_version=["<", "10.14"])
- @expectedFailureDarwin # FIXME: May need to force system libcxx here.
def test_with_run_command(self):
"""Test that that file and class static variables display correctly."""
self.build()
More information about the lldb-commits
mailing list