tberghammer created this revision.
tberghammer added reviewers: labath, granata.enrico.
tberghammer added a subscriber: lldb-commits.
Herald added subscribers: mgorny, beanz.
Add data formatter for libstdc++ tuple
https://reviews.llvm.org/D25733
Files:
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp
source/Plugins/Language/CPlusPlus/CMakeLists.txt
source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
Index: source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
===================================================================
--- /dev/null
+++ source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
@@ -0,0 +1,110 @@
+//===-- LibStdcppTuple.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "LibStdcpp.h"
+
+#include <memory>
+#include <vector>
+
+#include "lldb/Core/ConstString.h"
+#include "lldb/Core/ValueObject.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
+#include "lldb/DataFormatters/TypeSynthetic.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::formatters;
+
+namespace {
+
+class LibStdcppTupleSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
+ public:
+ explicit LibStdcppTupleSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
+
+ size_t CalculateNumChildren() override;
+
+ lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
+
+ bool Update() override;
+
+ bool MightHaveChildren() override;
+
+ size_t GetIndexOfChildWithName(const ConstString &name) override;
+
+ private:
+ std::vector<ValueObjectSP> m_members;
+};
+
+} // end of anonymous namespace
+
+LibStdcppTupleSyntheticFrontEnd::LibStdcppTupleSyntheticFrontEnd(
+ lldb::ValueObjectSP valobj_sp)
+ : SyntheticChildrenFrontEnd(*valobj_sp) {
+ Update();
+}
+
+bool LibStdcppTupleSyntheticFrontEnd::Update() {
+ m_members.clear();
+
+ ValueObjectSP valobj_backend_sp = m_backend.GetSP();
+ if (!valobj_backend_sp) return false;
+
+ ValueObjectSP valobj_sp = valobj_backend_sp->GetNonSyntheticValue();
+ if (!valobj_sp) return false;
+
+ ValueObjectSP next_child_sp = valobj_sp;
+ while (next_child_sp != nullptr) {
+ ValueObjectSP current_child = next_child_sp;
+ next_child_sp = nullptr;
+
+ size_t child_count = current_child->GetNumChildren();
+ for (size_t i = 0; i < child_count; ++i) {
+ ValueObjectSP child_sp = current_child->GetChildAtIndex(i, true);
+ llvm::StringRef name_str = child_sp->GetName().GetStringRef();
+ if (name_str.startswith("std::_Tuple_impl<")) {
+ next_child_sp = child_sp;
+ } else if (name_str.startswith("std::_Head_base<")) {
+ ValueObjectSP value_sp =
+ child_sp->GetChildMemberWithName(ConstString("_M_head_impl"), true);
+ if (value_sp) {
+ StreamString name;
+ name.Printf("[%" PRIu64 "]", m_members.size());
+ value_sp->SetName(ConstString(name.GetData()));
+
+ m_members.push_back(value_sp);
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
+bool LibStdcppTupleSyntheticFrontEnd::MightHaveChildren() { return true; }
+
+lldb::ValueObjectSP LibStdcppTupleSyntheticFrontEnd::GetChildAtIndex(
+ size_t idx) {
+ if (idx < m_members.size()) return m_members[idx];
+ return lldb::ValueObjectSP();
+}
+
+size_t LibStdcppTupleSyntheticFrontEnd::CalculateNumChildren() {
+ return m_members.size();
+}
+
+size_t LibStdcppTupleSyntheticFrontEnd::GetIndexOfChildWithName(
+ const ConstString &name) {
+ return ExtractIndexFromString(name.GetCString());
+}
+
+SyntheticChildrenFrontEnd *
+lldb_private::formatters::LibStdcppTupleSyntheticFrontEndCreator(
+ CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
+ return (valobj_sp ? new LibStdcppTupleSyntheticFrontEnd(valobj_sp) : nullptr);
+}
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -803,16 +803,31 @@
AddCXXSynthetic(
cpp_category_sp,
+ lldb_private::formatters::LibStdcppUniquePtrSyntheticFrontEndCreator,
+ "std::unique_ptr synthetic children",
+ ConstString("^std::unique_ptr<.+>(( )?&)?$"), stl_synth_flags, true);
+ AddCXXSynthetic(
+ cpp_category_sp,
lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator,
"std::shared_ptr synthetic children",
ConstString("^std::shared_ptr<.+>(( )?&)?$"), stl_synth_flags, true);
AddCXXSynthetic(
cpp_category_sp,
lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator,
"std::weak_ptr synthetic children",
ConstString("^std::weak_ptr<.+>(( )?&)?$"), stl_synth_flags, true);
+ AddCXXSynthetic(
+ cpp_category_sp,
+ lldb_private::formatters::LibStdcppTupleSyntheticFrontEndCreator,
+ "std::tuple synthetic children", ConstString("^std::tuple<.+>(( )?&)?$"),
+ stl_synth_flags, true);
AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::LibStdcppUniquePointerSummaryProvider,
+ "libstdc++ std::unique_ptr summary provider",
+ ConstString("^std::unique_ptr<.+>(( )?&)?$"), stl_summary_flags,
+ true);
+ AddCXXSummary(cpp_category_sp,
lldb_private::formatters::LibStdcppSmartPointerSummaryProvider,
"libstdc++ std::shared_ptr summary provider",
ConstString("^std::shared_ptr<.+>(( )?&)?$"), stl_summary_flags,
Index: source/Plugins/Language/CPlusPlus/CMakeLists.txt
===================================================================
--- source/Plugins/Language/CPlusPlus/CMakeLists.txt
+++ source/Plugins/Language/CPlusPlus/CMakeLists.txt
@@ -11,4 +11,6 @@
LibCxxVector.cpp
LibStdcpp.cpp
LibStdcppSmartPointer.cpp
+ LibStdcppTuple.cpp
+ LibStdcppUniquePointer.cpp
)
Index: packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp
@@ -0,0 +1,9 @@
+#include <memory>
+#include <string>
+
+int main() {
+ std::tuple<int> ti{1};
+ std::tuple<std::string> ts{"foobar"};
+ std::tuple<int, std::string, int> tt{1, "baz", 2};
+ return 0; // Set break point at this line.
+}
Index: packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py
@@ -0,0 +1,42 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+from __future__ import print_function
+
+import os
+import time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class StdTupleDataFormatterTestCase(TestBase):
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipIfFreeBSD
+ @skipIfWindows # libstdcpp not ported to Windows
+ @skipIfDarwin # doesn't compile on Darwin
+ def test_with_run_command(self):
+ self.build()
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+ lldbutil.run_break_set_by_source_regexp(
+ self, "Set break point at this line.")
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs=['stopped', 'stop reason = breakpoint'])
+
+ self.expect("frame variable ti", substrs=['[0] = 1'])
+ self.expect("frame variable ti[0]", substrs=['[0] = 1'])
+
+ self.expect("frame variable ts", substrs=['[0] = "foobar"'])
+ self.expect("frame variable ts[0]", substrs=['[0] = "foobar"'])
+
+ self.expect("frame variable tt", substrs=['[0] = 1', '[1] = "baz"', '[2] = 2'])
+ self.expect("frame variable tt[0]", substrs=['[0] = 1'])
+ self.expect("frame variable tt[1]", substrs=['[1] = "baz"'])
+ self.expect("frame variable tt[2]", substrs=['[2] = 2'])
Index: packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile
@@ -0,0 +1,15 @@
+LEVEL = ../../../../../make
+
+CXX_SOURCES := main.cpp
+
+CXXFLAGS := -O0
+USE_LIBSTDCPP := 1
+
+# clang-3.5+ outputs FullDebugInfo by default for Darwin/FreeBSD
+# targets. Other targets do not, which causes this test to fail.
+# This flag enables FullDebugInfo for all targets.
+ifneq (,$(findstring clang,$(CC)))
+ CFLAGS_EXTRAS += -fno-limit-debug-info
+endif
+
+include $(LEVEL)/Makefile.rules
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits