]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/function_types/TestFunctionTypes.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / function_types / TestFunctionTypes.py
1 """Test variable with function ptr type and that break on the function works."""
2
3 from __future__ import print_function
4
5
6 import os
7 import time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class FunctionTypesTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line number to break inside main().
22         self.line = line_number('main.c', '// Set break point at this line.')
23
24     def test(self):
25         """Test 'callback' has function ptr type, then break on the function."""
26         self.build()
27         self.runToBreakpoint()
28
29         # Check that the 'callback' variable display properly.
30         self.expect(
31             "frame variable --show-types callback",
32             VARIABLES_DISPLAYED_CORRECTLY,
33             startstr='(int (*)(const char *)) callback =')
34
35         # And that we can break on the callback function.
36         lldbutil.run_break_set_by_symbol(
37             self,
38             "string_not_empty",
39             num_expected_locations=1,
40             sym_exact=True)
41         self.runCmd("continue")
42
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'])
47
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."""
51         self.build()
52         self.runToBreakpoint()
53
54         self.expect("expr string_not_empty",
55                     substrs=['(int (*)(const char *)) $0 = ', '(a.out`'])
56
57         if self.platformIsDarwin():
58             regexps = ['lib.*\.dylib`printf']
59         else:
60             regexps = ['printf']
61         self.expect("expr (int (*)(const char*, ...))printf",
62                     substrs=['(int (*)(const char *, ...)) $1 = '],
63                     patterns=regexps)
64
65         self.expect("expr $1(\"Hello world\\n\")",
66                     startstr='(int) $2 = 12')
67
68     def runToBreakpoint(self):
69         exe = os.path.join(os.getcwd(), "a.out")
70         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
71
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)
75
76         self.runCmd("run", RUN_SUCCEEDED)
77
78         # The stop reason of the thread should be breakpoint.
79         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
80                     substrs=['stopped',
81                              'stop reason = breakpoint'])
82
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'])