1 """Test that lldb can invoke blocks and access variables inside them"""
3 from __future__ import print_function
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test.decorators import *
12 import lldbsuite.test.lldbutil as lldbutil
15 class BlocksTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
23 # Find the line numbers to break at.
24 self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
25 self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
27 def launch_common(self):
29 exe = os.path.join(os.getcwd(), "a.out")
30 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
32 self.is_started = False
34 # Break inside the foo function which takes a bar_ptr argument.
35 for line in self.lines:
36 lldbutil.run_break_set_by_file_and_line(
37 self, "main.c", line, num_expected_locations=1, loc_exact=True)
39 self.wait_for_breakpoint()
45 self.expect("expression a + b", VARIABLES_DISPLAYED_CORRECTLY,
48 self.expect("expression c", VARIABLES_DISPLAYED_CORRECTLY,
51 self.wait_for_breakpoint()
53 # This should display correctly.
54 self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
58 def test_define(self):
62 "expression int (^$add)(int, int) = ^int(int a, int b) { return a + b; };")
64 "expression $add(2,3)",
65 VARIABLES_DISPLAYED_CORRECTLY,
68 self.runCmd("expression int $a = 3")
70 "expression int (^$addA)(int) = ^int(int b) { return $a + b; };",
71 "Proper error is reported on capture",
74 def wait_for_breakpoint(self):
75 if not self.is_started:
76 self.is_started = True
77 self.runCmd("process launch", RUN_SUCCEEDED)
79 self.runCmd("process continue", RUN_SUCCEEDED)
81 # The stop reason of the thread should be breakpoint.
82 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
84 'stop reason = breakpoint'])