diff options
6 files changed, 107 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile new file mode 100644 index 00000000000..fdd717119d9 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../../../make +CXX_SOURCES := main.cpp +CXXFLAGS += -std=c++11 +USE_LIBCPP := 1 +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py new file mode 100644 index 00000000000..a5eec8a0362 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py @@ -0,0 +1,50 @@ +""" +Test lldb data formatter subsystem. +""" + +from __future__ import print_function + + + +import os, time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class LibCxxFunctionTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def get_variable(self, name): + var = self.frame().FindVariable(name) + var.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) + var.SetPreferSyntheticValue(True) + return var + + @skipIf(compiler="gcc") + @skipIfWindows # libc++ not ported to Windows yet + def test(self): + """Test that std::function as defined by libc++ is correctly printed by LLDB""" + self.build() + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID(lldbutil.run_break_set_by_source_regexp (self, "Set break point at this line.")) + + self.runCmd("run", RUN_SUCCEEDED) + + lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+")) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + f1 = self.get_variable('f1') + f2 = self.get_variable('f2') + + if self.TraceOn(): print(f1) + if self.TraceOn(): print(f2) + + self.assertTrue(f1.GetValueAsUnsigned(0) != 0, 'f1 has a valid value') + self.assertTrue(f2.GetValueAsUnsigned(0) != 0, 'f2 has a valid value') diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp new file mode 100644 index 00000000000..cfe689b29b0 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp @@ -0,0 +1,25 @@ +//===-- main.cpp --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <functional> + +int foo(int x, int y) { + return x + y - 1; +} + +int main () +{ + int acc = 42; + std::function<int (int,int)> f1 = foo; + std::function<int (int)> f2 = [acc,f1] (int x) -> int { + return x+f1(acc,x); + }; + return f1(acc,acc) + f2(acc); // Set break point at this line. +} + diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 0cd059e6a67..71bf160015e 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -566,6 +566,8 @@ LoadLibCxxFormatters (lldb::TypeCategoryImplSP cpp_category_sp) AddCXXSummary(cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::vector<bool> summary provider", ConstString("std::__(ndk)?1::vector<bool, std::__(ndk)?1::allocator<bool> >"), stl_summary_flags); AddCXXSynthetic(cpp_category_sp, lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator, "std::map iterator synthetic children", ConstString("^std::__(ndk)?1::__map_iterator<.+>$"), stl_synth_flags, true); + + AddCXXSynthetic(cpp_category_sp, lldb_private::formatters::LibcxxFunctionFrontEndCreator, "std::function synthetic value provider", ConstString("^std::__1::function<.+>$"), stl_synth_flags, true); #endif } diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index beb89b89c63..1567fffd0b1 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -645,3 +645,26 @@ lldb_private::formatters::LibcxxStringSummaryProvider (ValueObject& valobj, Stre return true; } + +class LibcxxFunctionFrontEnd : public SyntheticValueProviderFrontEnd +{ +public: + LibcxxFunctionFrontEnd (ValueObject &backend) : + SyntheticValueProviderFrontEnd(backend) + {} + + lldb::ValueObjectSP + GetSyntheticValue() override + { + static ConstString g___f_("__f_"); + return m_backend.GetChildMemberWithName(g___f_, true); + } +}; + +SyntheticChildrenFrontEnd* +lldb_private::formatters::LibcxxFunctionFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp) +{ + if (valobj_sp) + return new LibcxxFunctionFrontEnd(*valobj_sp); + return nullptr; +} diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h index ae00bc0ade3..cc92b81cd17 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h @@ -134,6 +134,8 @@ namespace lldb_private { SyntheticChildrenFrontEnd* LibcxxStdUnorderedMapSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); SyntheticChildrenFrontEnd* LibcxxInitializerListSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); + + SyntheticChildrenFrontEnd* LibcxxFunctionFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); } // namespace formatters } // namespace lldb_private |