1"""Test that lldb can invoke blocks and access variables inside them"""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class AnonymousTestCase(TestBase):
10
11    mydir = os.path.join("lang", "c", "blocks")
12    lines = []
13
14    @unittest2.expectedFailure
15    @dsym_test
16    def test_expr_with_dsym(self):
17        self.buildDsym()
18        self.expr()
19
20    @unittest2.expectedFailure
21    @dwarf_test
22    def test_expr_with_dwarf(self):
23        self.buildDwarf()
24        self.expr()
25
26    def setUp(self):
27        # Call super's setUp().
28        TestBase.setUp(self)
29        # Find the line numbers to break at.
30        self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
31        self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
32
33    def common_setup(self):
34        exe = os.path.join(os.getcwd(), "a.out")
35        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
36
37	self.is_started = False
38
39        # Break inside the foo function which takes a bar_ptr argument.
40	for line in self.lines:
41            lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True)
42
43    def wait_for_breakpoint(self):
44        if self.is_started == False:
45            self.is_started = True
46            self.runCmd("process launch", RUN_SUCCEEDED)
47        else:
48            self.runCmd("process continue", RUN_SUCCEEDED)
49
50        # The stop reason of the thread should be breakpoint.
51        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
52            substrs = ['stopped',
53                       'stop reason = breakpoint'])
54
55    def expr(self):
56        self.common_setup()
57
58        self.wait_for_breakpoint()
59
60        self.expect("expression a + b", VARIABLES_DISPLAYED_CORRECTLY,
61            substrs = ["= 7"])
62
63        self.expect("expression c", VARIABLES_DISPLAYED_CORRECTLY,
64            substrs = ["= 1"])
65
66        self.wait_for_breakpoint()
67
68        # This should display correctly.
69        self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
70            substrs = ["= 12"])
71
72if __name__ == '__main__':
73    import atexit
74    lldb.SBDebugger.Initialize()
75    atexit.register(lambda: lldb.SBDebugger.Terminate())
76    unittest2.main()
77