1 """Test that lldb can invoke blocks and access variables inside them"""
5 from lldbsuite
.test
.lldbtest
import *
6 from lldbsuite
.test
.decorators
import *
7 import lldbsuite
.test
.lldbutil
as lldbutil
10 class BlocksTestCase(TestBase
):
14 # Call super's setUp().
16 # Find the line numbers to break at.
17 self
.lines
.append(line_number("main.c", "// Set breakpoint 0 here."))
18 self
.lines
.append(line_number("main.c", "// Set breakpoint 1 here."))
19 self
.lines
.append(line_number("main.c", "// Set breakpoint 2 here."))
21 def launch_common(self
):
23 exe
= self
.getBuildArtifact("a.out")
24 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
26 self
.is_started
= False
28 # Break inside the foo function which takes a bar_ptr argument.
29 for line
in self
.lines
:
30 lldbutil
.run_break_set_by_file_and_line(
31 self
, "main.c", line
, num_expected_locations
=1, loc_exact
=True
34 self
.wait_for_breakpoint()
40 self
.expect("expression a + b", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["= 7"])
42 self
.expect("expression c", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["= 1"])
44 self
.wait_for_breakpoint()
46 # This should display correctly.
48 "expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["= 12"]
51 self
.wait_for_breakpoint()
53 self
.expect_expr("h(cg)", result_type
="int", result_value
="42")
56 def test_define(self
):
60 "expression int (^$add)(int, int) = ^int(int a, int b) { return a + b; };"
63 "expression $add(2,3)", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=[" = 5"]
66 self
.runCmd("expression int $a = 3")
68 "expression int (^$addA)(int) = ^int(int b) { return $a + b; };",
69 "Proper error is reported on capture",
73 def wait_for_breakpoint(self
):
74 if not self
.is_started
:
75 self
.is_started
= True
76 self
.runCmd("process launch", RUN_SUCCEEDED
)
78 self
.runCmd("process continue", RUN_SUCCEEDED
)
80 # The stop reason of the thread should be breakpoint.
83 STOPPED_DUE_TO_BREAKPOINT
,
84 substrs
=["stopped", "stop reason = breakpoint"],