TestFunctionTypes.py revision d9ed552026a5d2842d95b2852f33346e867e9799
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
23d9ed552026a5d2842d95b2852f33346e867e9799Johnny Chen    def function_types(self):
24fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        """Test 'callback' has function ptr type, then break on the function."""
25fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
264f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
27fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
28fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Break inside the main.
294f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("breakpoint set -f main.c -l 21", BREAKPOINT_CREATED,
304f995f0718299696719089084a622835b6a7b4b8Johnny Chen            startstr = "Breakpoint created: 1: file ='main.c', line = 21, locations = 1")
31fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
321bb9f9a3917c7ac7228d0a81a0ff8a225165800aJohnny Chen        self.runCmd("run", RUN_SUCCEEDED)
33fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
34fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # The stop reason of the thread should be breakpoint.
354f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
364f995f0718299696719089084a622835b6a7b4b8Johnny Chen            substrs = ['state is Stopped',
374f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'stop reason = breakpoint'])
38fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
39fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # The breakpoint should have a hit count of 1.
404f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("breakpoint list", BREAKPOINT_HIT_ONCE,
414f995f0718299696719089084a622835b6a7b4b8Johnny Chen            substrs = [' resolved, hit count = 1'])
42fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
43fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Check that the 'callback' variable display properly.
448b09b32b95810a2dc617148271ed0dd6281259a8Johnny Chen        self.expect("frame variable callback", VARIABLES_DISPLAYED_CORRECTLY,
454f995f0718299696719089084a622835b6a7b4b8Johnny Chen            startstr = '(int (*)(char const *)) callback =')
46fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
47fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # And that we can break on the callback function.
484f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("breakpoint set -n string_not_empty", BREAKPOINT_CREATED)
494f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.runCmd("continue")
50fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
51fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen        # Check that we do indeed stop on the string_not_empty function.
524f995f0718299696719089084a622835b6a7b4b8Johnny Chen        self.expect("process status", STOPPED_DUE_TO_BREAKPOINT,
5359ea45fc85deacf0b8ca8250f116b7cc7b3691a5Johnny Chen            substrs = ['a.out`string_not_empty',
544f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'main.c:12',
554f995f0718299696719089084a622835b6a7b4b8Johnny Chen                       'stop reason = breakpoint'])
56fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
57fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen
58fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chenif __name__ == '__main__':
5988f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    import atexit
60fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen    lldb.SBDebugger.Initialize()
6188f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
6275e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chen    unittest2.main()
63