]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/shared_lib/TestSharedLib.py
Vendor import of lldb trunk r321017:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / shared_lib / TestSharedLib.py
1 """Test that types defined in shared libraries work correctly."""
2
3 from __future__ import print_function
4
5
6 import unittest2
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 import lldbsuite.test.lldbutil as lldbutil
11
12
13 class SharedLibTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def common_test_expr(self, preload_symbols):
18         if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion():
19             self.skipTest(
20                 "llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef")
21
22         self.build()
23         self.common_setup(preload_symbols)
24
25         # This should display correctly.
26         self.expect(
27             "expression --show-types -- *my_foo_ptr",
28             VARIABLES_DISPLAYED_CORRECTLY,
29             substrs=[
30                 "(foo)",
31                 "(sub_foo)",
32                 "other_element = 3"])
33
34         self.expect(
35             "expression GetMeASubFoo(my_foo_ptr)",
36             startstr="(sub_foo *) $")
37
38     @expectedFailureAll(oslist=["windows"])
39     def test_expr(self):
40         """Test that types work when defined in a shared library and forward-declared in the main executable"""
41         self.common_test_expr(True)
42
43     @expectedFailureAll(oslist=["windows"])
44     def test_expr_no_preload(self):
45         """Test that types work when defined in a shared library and forward-declared in the main executable, but with preloading disabled"""
46         self.common_test_expr(False)
47
48     @unittest2.expectedFailure("rdar://problem/10704639")
49     def test_frame_variable(self):
50         """Test that types work when defined in a shared library and forward-declared in the main executable"""
51         self.build()
52         self.common_setup()
53
54         # This should display correctly.
55         self.expect(
56             "frame variable --show-types -- *my_foo_ptr",
57             VARIABLES_DISPLAYED_CORRECTLY,
58             substrs=[
59                 "(foo)",
60                 "(sub_foo)",
61                 "other_element = 3"])
62
63     def setUp(self):
64         # Call super's setUp().
65         TestBase.setUp(self)
66         # Find the line number to break inside main().
67         self.source = 'main.c'
68         self.line = line_number(self.source, '// Set breakpoint 0 here.')
69         self.shlib_names = ["foo"]
70
71     def common_setup(self, preload_symbols = True):
72         # Run in synchronous mode
73         self.dbg.SetAsync(False)
74
75         # Create a target by the debugger.
76         target = self.dbg.CreateTarget("a.out")
77         self.assertTrue(target, VALID_TARGET)
78
79         self.runCmd("settings set target.preload-symbols " + str(preload_symbols).lower())
80
81         # Break inside the foo function which takes a bar_ptr argument.
82         lldbutil.run_break_set_by_file_and_line(
83             self, self.source, self.line, num_expected_locations=1, loc_exact=True)
84
85         # Register our shared libraries for remote targets so they get
86         # automatically uploaded
87         environment = self.registerSharedLibrariesWithTarget(
88             target, self.shlib_names)
89
90         # Now launch the process, and do not stop at entry point.
91         process = target.LaunchSimple(
92             None, environment, self.get_process_working_directory())
93         self.assertTrue(process, PROCESS_IS_VALID)
94
95         # The stop reason of the thread should be breakpoint.
96         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
97                     substrs=['stopped',
98                              'stop reason = breakpoint'])
99
100         # The breakpoint should have a hit count of 1.
101         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
102                     substrs=[' resolved, hit count = 1'])