TestFunctionTypes.py revision de2f1ed2a5dfe306aa6c5d48baf65808608cefb5
1"""Test variable with function ptr type and that break on the function works.""" 2 3import os, time 4import unittest2 5import lldb 6from lldbtest import * 7 8class FunctionTypesTestCase(TestBase): 9 10 mydir = os.path.join("lang", "c", "function_types") 11 12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 13 def test_with_dsym(self): 14 """Test 'callback' has function ptr type, then break on the function.""" 15 self.buildDsym() 16 self.function_types() 17 18 def test_with_dwarf(self): 19 """Test 'callback' has function ptr type, then break on the function.""" 20 self.buildDwarf() 21 self.function_types() 22 23 def setUp(self): 24 # Call super's setUp(). 25 TestBase.setUp(self) 26 # Find the line number to break inside main(). 27 self.line = line_number('main.c', '// Set break point at this line.') 28 29 def function_types(self): 30 """Test 'callback' has function ptr type, then break on the function.""" 31 exe = os.path.join(os.getcwd(), "a.out") 32 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 33 34 # Break inside the main. 35 self.expect("breakpoint set -f main.c -l %d" % self.line, 36 BREAKPOINT_CREATED, 37 startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" % 38 self.line) 39 40 self.runCmd("run", RUN_SUCCEEDED) 41 42 # The stop reason of the thread should be breakpoint. 43 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 44 substrs = ['stopped', 45 'stop reason = breakpoint']) 46 47 # The breakpoint should have a hit count of 1. 48 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 49 substrs = [' resolved, hit count = 1']) 50 51 # Check that the 'callback' variable display properly. 52 self.expect("frame variable -T callback", VARIABLES_DISPLAYED_CORRECTLY, 53 startstr = '(int (*)(const char *)) callback =') 54 55 # And that we can break on the callback function. 56 self.runCmd("breakpoint set -n string_not_empty", BREAKPOINT_CREATED) 57 self.runCmd("continue") 58 59 # Check that we do indeed stop on the string_not_empty function. 60 self.expect("process status", STOPPED_DUE_TO_BREAKPOINT, 61 substrs = ['a.out`string_not_empty', 62 'stop reason = breakpoint']) 63 64 65if __name__ == '__main__': 66 import atexit 67 lldb.SBDebugger.Initialize() 68 atexit.register(lambda: lldb.SBDebugger.Terminate()) 69 unittest2.main() 70