diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/Makefile similarity index 51% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/Makefile index b016f006747da..99998b20bcb05 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/Makefile @@ -1,5 +1,3 @@ CXX_SOURCES := main.cpp -CXXFLAGS_EXTRAS := -std=c++11 -USE_LIBCPP := 1 include Makefile.rules diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/TestDataFormatterStdFunction.py similarity index 85% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/TestDataFormatterStdFunction.py index 80461b996328f..f4e0cd2f2b3dc 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/TestDataFormatterStdFunction.py @@ -2,14 +2,13 @@ Test lldb data formatter subsystem. """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil -class LibCxxFunctionTestCase(TestBase): +class StdFunctionTestCase(TestBase): # Run frame var for a variable twice. Verify we do not hit the cache # the first time but do the second time. def run_frame_var_check_cache_use( @@ -34,10 +33,8 @@ def run_frame_var_check_cache_use( substrs=["lldb_private::CompileUnit::FindFunction"], ) - @add_test_categories(["libc++"]) - def test(self): - """Test that std::function as defined by libc++ is correctly printed by LLDB""" - self.build() + def do_test(self): + """Test that std::function is correctly printed by LLDB""" self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) bkpt = self.target().FindBreakpointByID( @@ -56,20 +53,20 @@ def test(self): ) self.run_frame_var_check_cache_use( - "foo2_f", "Lambda in File main.cpp at Line 22" + "foo2_f", "Lambda in File main.cpp at Line 16" ) lldbutil.continue_to_breakpoint(self.process(), bkpt) self.run_frame_var_check_cache_use( - "add_num2_f", "Lambda in File main.cpp at Line 13" + "add_num2_f", "Lambda in File main.cpp at Line 9" ) lldbutil.continue_to_breakpoint(self.process(), bkpt) - self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 35") + self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 26") self.run_frame_var_check_cache_use( - "f3", "Lambda in File main.cpp at Line 39", True + "f3", "Lambda in File main.cpp at Line 30", True ) # TODO reenable this case when std::function formatter supports # general callable object case. @@ -82,3 +79,8 @@ def test(self): self.expect( "frame variable f5", substrs=["f5 = Function = Bar::add_num(int) const"] ) + + @add_test_categories(["libc++"]) + def test_libcxx(self): + self.build(dictionary={"USE_LIBCPP": 1}) + self.do_test() diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/main.cpp new file mode 100644 index 0000000000000..86ab18fd9cc43 --- /dev/null +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/main.cpp @@ -0,0 +1,43 @@ +#include + +int foo(int x, int y) { return x + y - 1; } + +struct Bar { + int operator()() { return 66; } + int add_num(int i) const { return i + 3; } + int add_num2(int i) { + std::function add_num2_f = [](int x) { return x + 1; }; + + return add_num2_f(i); // Set break point at this line. + } +}; + +int foo2() { + auto f = [](int x) { return x + 1; }; + + std::function foo2_f = f; + + return foo2_f(10); // Set break point at this line. +} + +int main(int argc, char *argv[]) { + int acc = 42; + std::function f1 = foo; + std::function f2 = [acc, f1](int x) -> int { + return x + f1(acc, x); + }; + + auto f = [](int x, int y) { return x + y; }; + auto g = [](int x, int y) { return x * y; }; + std::function f3 = argc % 2 ? f : g; + + Bar bar1; + std::function f4(bar1); + std::function f5 = &Bar::add_num; + + int foo2_result = foo2(); + int bar_add_num2_result = bar1.add_num2(10); + + return f1(acc, acc) + f2(acc) + f3(acc + 1, acc + 2) + f4() + + f5(bar1, 10); // Set break point at this line. +} diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp deleted file mode 100644 index ef7c97470652f..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include - -int foo(int x, int y) { - return x + y - 1; -} - -struct Bar { - int operator()() { - return 66 ; - } - int add_num(int i) const { return i + 3 ; } - int add_num2(int i) { - std::function add_num2_f = [](int x) { - return x+1; - }; - - return add_num2_f(i); // Set break point at this line. - } -} ; - -int foo2() { - auto f = [](int x) { - return x+1; - }; - - std::function foo2_f = f; - - return foo2_f(10); // Set break point at this line. -} - -int main (int argc, char *argv[]) -{ - int acc = 42; - std::function f1 = foo; - std::function f2 = [acc,f1] (int x) -> int { - return x+f1(acc,x); - }; - - auto f = [](int x, int y) { return x + y; }; - auto g = [](int x, int y) { return x * y; } ; - std::function f3 = argc %2 ? f : g ; - - Bar bar1 ; - std::function f4( bar1 ) ; - std::function f5 = &Bar::add_num; - - int foo2_result = foo2(); - int bar_add_num2_result = bar1.add_num2(10); - - return f1(acc,acc) + f2(acc) + f3(acc+1,acc+2) + f4() + f5(bar1, 10); // Set break point at this line. -}