Skip to content

[lldb][test] Move std::function from libcxx to generic directory #147701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -std=c++11
USE_LIBCPP := 1

include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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.
Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <functional>

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<int(int)> 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<int(int)> foo2_f = f;

return foo2_f(10); // Set break point at this line.
}

int main(int argc, char *argv[]) {
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);
};

auto f = [](int x, int y) { return x + y; };
auto g = [](int x, int y) { return x * y; };
std::function<int(int, int)> f3 = argc % 2 ? f : g;

Bar bar1;
std::function<int()> f4(bar1);
std::function<int(const Bar &, int)> 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.
}

This file was deleted.

Loading