]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/shared_lib/TestSharedLib.py
Vendor import of lldb trunk r290819:
[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.lldbtest import *
9 import lldbsuite.test.lldbutil as lldbutil
10
11
12 class SharedLibTestCase(TestBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     def test_expr(self):
17         """Test that types work when defined in a shared library and forward-declared in the main executable"""
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()
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     @unittest2.expectedFailure("rdar://problem/10704639")
35     def test_frame_variable(self):
36         """Test that types work when defined in a shared library and forward-declared in the main executable"""
37         self.build()
38         self.common_setup()
39
40         # This should display correctly.
41         self.expect(
42             "frame variable --show-types -- *my_foo_ptr",
43             VARIABLES_DISPLAYED_CORRECTLY,
44             substrs=[
45                 "(foo)",
46                 "(sub_foo)",
47                 "other_element = 3"])
48
49     def setUp(self):
50         # Call super's setUp().
51         TestBase.setUp(self)
52         # Find the line number to break inside main().
53         self.source = 'main.c'
54         self.line = line_number(self.source, '// Set breakpoint 0 here.')
55         self.shlib_names = ["foo"]
56
57     def common_setup(self):
58         # Run in synchronous mode
59         self.dbg.SetAsync(False)
60
61         # Create a target by the debugger.
62         target = self.dbg.CreateTarget("a.out")
63         self.assertTrue(target, VALID_TARGET)
64
65         # Break inside the foo function which takes a bar_ptr argument.
66         lldbutil.run_break_set_by_file_and_line(
67             self, self.source, self.line, num_expected_locations=1, loc_exact=True)
68
69         # Register our shared libraries for remote targets so they get
70         # automatically uploaded
71         environment = self.registerSharedLibrariesWithTarget(
72             target, self.shlib_names)
73
74         # Now launch the process, and do not stop at entry point.
75         process = target.LaunchSimple(
76             None, environment, self.get_process_working_directory())
77         self.assertTrue(process, PROCESS_IS_VALID)
78
79         # The stop reason of the thread should be breakpoint.
80         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
81                     substrs=['stopped',
82                              'stop reason = breakpoint'])
83
84         # The breakpoint should have a hit count of 1.
85         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
86                     substrs=[' resolved, hit count = 1'])