TestFunctionTypes.py revision 41950cc77813637e6c67b069e4ad2faf8c5f6fa7
1fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen"""Test variable with function ptr type and that break on the function works."""
2fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
3fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chenimport os, time
475e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chenimport unittest2
5a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chenimport lldb
6d85dae5a089177582aff128c897c78332167fe08Johnny Chenfrom lldbtest import *
7fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
81c42e8684d26e1473f92c799eeae65a3eec991d6Johnny Chenclass FunctionTypesTestCase(TestBase):
9fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
10a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chen    mydir = "function_types"
11fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
12d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
13d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen    def test_with_dsym(self):
14d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen        """Test 'callback' has function ptr type, then break on the function."""
15d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen        self.buildDsym()
16d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen        self.function_types()
17d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen
18d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen    def test_with_dwarf(self):
19d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen        """Test 'callback' has function ptr type, then break on the function."""
20d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen        self.buildDwarf()
21d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen        self.function_types()
22d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen
23143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen    def setUp(self):
240910eb32b94bd67b0357d34d0951aad197742569Johnny Chen        # Call super's setUp().
250910eb32b94bd67b0357d34d0951aad197742569Johnny Chen        TestBase.setUp(self)
26143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen        # Find the line number to break inside main().
27143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen        self.line = line_number('main.c', '// Set break point at this line.')
28143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen
29d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen    def function_types(self):
30fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        """Test 'callback' has function ptr type, then break on the function."""
31fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
324f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
33fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
34fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Break inside the main.
35143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen        self.expect("breakpoint set -f main.c -l %d" % self.line,
36143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen                    BREAKPOINT_CREATED,
37143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
38143914211a7e009c90a7d88e7584513d7a4af67fJohnny Chen                        self.line)
39fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
401bb9f9a3917c7ac7228d0a81a0ff8a225165800aJohnny Chen        self.runCmd("run", RUN_SUCCEEDED)
41fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
42fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # The stop reason of the thread should be breakpoint.
434f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
448a87d5244a61570e06f9b48b9bc04773e82e301eJohnny Chen            substrs = ['state is stopped',
454f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'stop reason = breakpoint'])
46fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
47fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # The breakpoint should have a hit count of 1.
4841950cc77813637e6c67b069e4ad2faf8c5f6fa7Caroline Tice        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
494f995f0718299696719089084a622835b6a7b4b8Johnny Chen            substrs = [' resolved, hit count = 1'])
50fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
51fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Check that the 'callback' variable display properly.
52c401e37b99cca3482bacb7bc98cc09d69a1cd2acJohnny Chen        self.expect("frame variable -t callback", VARIABLES_DISPLAYED_CORRECTLY,
53397636ec9b675f4d917765400419d6b4805bb8a3Johnny Chen            startstr = '(int (*)(const char *)) callback =')
54fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
55fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # And that we can break on the callback function.
564f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("breakpoint set -n string_not_empty", BREAKPOINT_CREATED)
574f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("continue")
58fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
59fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Check that we do indeed stop on the string_not_empty function.
604f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("process status", STOPPED_DUE_TO_BREAKPOINT,
6159ea45fc85deacf0b8ca8250f116b7cc7b3691a5Johnny Chen            substrs = ['a.out`string_not_empty',
624f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'stop reason = breakpoint'])
63fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
64fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
65fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chenif __name__ == '__main__':
6688f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    import atexit
67fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen    lldb.SBDebugger.Initialize()
6888f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
6975e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chen    unittest2.main()
70