1 """Test variable with function ptr type and that break on the function works."""
3 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class FunctionTypesTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 # Find the line number to break inside main().
22 self.line = line_number('main.c', '// Set break point at this line.')
25 """Test 'callback' has function ptr type, then break on the function."""
27 self.runToBreakpoint()
29 # Check that the 'callback' variable display properly.
31 "frame variable --show-types callback",
32 VARIABLES_DISPLAYED_CORRECTLY,
33 startstr='(int (*)(const char *)) callback =')
35 # And that we can break on the callback function.
36 lldbutil.run_break_set_by_symbol(
39 num_expected_locations=1,
41 self.runCmd("continue")
43 # Check that we do indeed stop on the string_not_empty function.
44 self.expect("process status", STOPPED_DUE_TO_BREAKPOINT,
45 substrs=['a.out`string_not_empty',
46 'stop reason = breakpoint'])
48 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
49 def test_pointers(self):
50 """Test that a function pointer to 'printf' works and can be called."""
52 self.runToBreakpoint()
54 self.expect("expr string_not_empty",
55 substrs=['(int (*)(const char *)) $0 = ', '(a.out`'])
57 if self.platformIsDarwin():
58 regexps = ['lib.*\.dylib`printf']
61 self.expect("expr (int (*)(const char*, ...))printf",
62 substrs=['(int (*)(const char *, ...)) $1 = '],
65 self.expect("expr $1(\"Hello world\\n\")",
66 startstr='(int) $2 = 12')
68 def runToBreakpoint(self):
69 exe = os.path.join(os.getcwd(), "a.out")
70 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
72 # Break inside the main.
73 lldbutil.run_break_set_by_file_and_line(
74 self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
76 self.runCmd("run", RUN_SUCCEEDED)
78 # The stop reason of the thread should be breakpoint.
79 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
81 'stop reason = breakpoint'])
83 # The breakpoint should have a hit count of 1.
84 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
85 substrs=[' resolved, hit count = 1'])