TestFunctionTypes.py revision 4f995f0718299696719089084a622835b6a7b4b8
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
8d85dae5a089177582aff128c897c78332167fe08Johnny Chenclass TestFunctionTypes(TestBase):
9fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
10a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chen    mydir = "function_types"
11fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
12fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen    def test_function_types(self):
13fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        """Test 'callback' has function ptr type, then break on the function."""
14fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
154f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
16fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
17fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Break inside the main.
184f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("breakpoint set -f main.c -l 21", BREAKPOINT_CREATED,
194f995f0718299696719089084a622835b6a7b4b8Johnny Chen            startstr = "Breakpoint created: 1: file ='main.c', line = 21, locations = 1")
20fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
214f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("run", RUN_STOPPED)
22fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
23fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # The stop reason of the thread should be breakpoint.
244f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
254f995f0718299696719089084a622835b6a7b4b8Johnny Chen            substrs = ['state is Stopped',
264f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'stop reason = breakpoint'])
27fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
28fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # The breakpoint should have a hit count of 1.
294f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("breakpoint list", BREAKPOINT_HIT_ONCE,
304f995f0718299696719089084a622835b6a7b4b8Johnny Chen            substrs = [' resolved, hit count = 1'])
31fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
32fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Check that the 'callback' variable display properly.
334f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("variable list callback", VARIABLES_DISPLAYED_CORRECTLY,
344f995f0718299696719089084a622835b6a7b4b8Johnny Chen            startstr = '(int (*)(char const *)) callback =')
35fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
36fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # And that we can break on the callback function.
374f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("breakpoint set -n string_not_empty", BREAKPOINT_CREATED)
384f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("continue")
39fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
40fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Check that we do indeed stop on the string_not_empty function.
414f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("process status", STOPPED_DUE_TO_BREAKPOINT,
424f995f0718299696719089084a622835b6a7b4b8Johnny Chen            substrs = ['where = a.out`string_not_empty',
434f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'main.c:12',
444f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'stop reason = breakpoint'])
45fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
46fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
47fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chenif __name__ == '__main__':
4888f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    import atexit
49fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen    lldb.SBDebugger.Initialize()
5088f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
5175e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chen    unittest2.main()
52