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