1"""
2Tests calling a function by basename
3"""
4
5import lldb
6from lldbtest import *
7import lldbutil
8
9class CallCPPFunctionTestCase(TestBase):
10
11    mydir = os.path.join("lang", "cpp", "call-function")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @dsym_test
15    def test_with_dsym_and_run_command(self):
16        """Test calling a function by basename"""
17        self.buildDsym()
18        self.call_cpp_function()
19
20    @dwarf_test
21    def test_with_dwarf_and_run_command(self):
22        """Test calling a function by basename"""
23        self.buildDwarf()
24        self.call_cpp_function()
25
26    def setUp(self):
27        TestBase.setUp(self)
28        self.line = line_number('main.cpp', '// breakpoint')
29
30    def call_cpp_function(self):
31        """Test calling a function by basename"""
32        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33
34        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
35
36        self.runCmd("process launch", RUN_SUCCEEDED)
37
38        # The stop reason of the thread should be breakpoint.
39        self.expect("thread list",
40                    STOPPED_DUE_TO_BREAKPOINT,
41                    substrs = ['stopped', 'stop reason = breakpoint'])
42
43        self.expect("expression -- a_function_to_call()",
44                    startstr = "(int) $0 = 0")
45
46if __name__ == '__main__':
47    import atexit
48    lldb.SBDebugger.Initialize()
49    atexit.register(lambda: lldb.SBDebugger.Terminate())
50    unittest2.main()
51