TestFunctionTypes.py revision 75e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74
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 6a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chenimport lldbtest 7fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 83097439ac52d25909e706503afe5c0772f2aead2Johnny Chenclass TestFunctionTypes(lldbtest.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.""" 14a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chen res = self.res 15fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen exe = os.path.join(os.getcwd(), "a.out") 16fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("file " + exe, res) 17fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 18fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 19fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen # Break inside the main. 20fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("breakpoint set -f main.c -l 21", res) 21fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 22fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.GetOutput().startswith( 23fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen "Breakpoint created: 1: file ='main.c', line = 21, locations = 1")) 24fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 25fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("run", res) 26fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen time.sleep(0.1) 27fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 28fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 29fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen # The stop reason of the thread should be breakpoint. 30fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("thread list", res) 31fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen print "thread list ->", res.GetOutput() 32fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 33f8f1b0a7c96be2db0314dba1426a0a64df6f07ebJohnny Chen self.assertTrue(res.GetOutput().find('state is Stopped') > 0 and 34f8f1b0a7c96be2db0314dba1426a0a64df6f07ebJohnny Chen res.GetOutput().find('stop reason = breakpoint') > 0) 35fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 36fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen # The breakpoint should have a hit count of 1. 37fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("breakpoint list", res) 38fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 39f8f1b0a7c96be2db0314dba1426a0a64df6f07ebJohnny Chen self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0) 40fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 41fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen # Check that the 'callback' variable display properly. 42fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("variable list callback", res); 43fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 44fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen output = res.GetOutput() 45fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(output.startswith('(int (*)(char const *)) callback =')) 46fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 47fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen # And that we can break on the callback function. 48fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("breakpoint set -n string_not_empty", res); 49fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 50fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("continue", res) 51fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 52fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 53fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen # Check that we do indeed stop on the string_not_empty function. 54fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("process status", res) 55fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 56fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen output = res.GetOutput() 57fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen #print "process status =", output 58f8f1b0a7c96be2db0314dba1426a0a64df6f07ebJohnny Chen self.assertTrue(output.find('where = a.out`string_not_empty') > 0 and 59f8f1b0a7c96be2db0314dba1426a0a64df6f07ebJohnny Chen output.find('main.c:12') > 0 and 60f8f1b0a7c96be2db0314dba1426a0a64df6f07ebJohnny Chen output.find('stop reason = breakpoint') > 0) 61fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 62fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.ci.HandleCommand("continue", res) 63fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen self.assertTrue(res.Succeeded()) 64fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 65fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen 66fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chenif __name__ == '__main__': 6788f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen import atexit 68fce55e0f97822a11a92cacb556c38bf69c79af25Johnny Chen lldb.SBDebugger.Initialize() 6988f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen atexit.register(lambda: lldb.SBDebugger.Terminate()) 7075e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chen unittest2.main() 71