Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / objc / hidden-ivars / TestHiddenIvars.py
blob8153376b4c6feea6663058fb188b453df1be6f82
1 """Test that hidden ivars in a shared library are visible from the main executable."""
4 import subprocess
6 import lldb
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class HiddenIvarsTestCase(TestBase):
13 def setUp(self):
14 # Call super's setUp().
15 TestBase.setUp(self)
16 # Find the line number to break inside main().
17 self.source = "main.m"
18 self.line = line_number(self.source, "// breakpoint1")
19 # The makefile names of the shared libraries as they appear in DYLIB_NAME.
20 # The names should have no loading "lib" or extension as they will be
21 # localized
22 self.shlib_names = ["InternalDefiner"]
24 @skipIf(
25 debug_info=no_match("dsym"),
26 bugnumber="This test requires a stripped binary and a dSYM",
28 def test_expr_stripped(self):
29 if self.getArchitecture() == "i386":
30 self.skipTest("requires modern objc runtime")
31 else:
32 self.build()
33 self.expr(True)
35 def test_expr(self):
36 if self.getArchitecture() == "i386":
37 self.skipTest("requires modern objc runtime")
38 else:
39 self.build()
40 self.expr(False)
42 @skipIf(
43 debug_info=no_match("dsym"),
44 bugnumber="This test requires a stripped binary and a dSYM",
46 def test_frame_variable_stripped(self):
47 if self.getArchitecture() == "i386":
48 self.skipTest("requires modern objc runtime")
49 else:
50 self.build()
51 self.frame_var(True)
53 def test_frame_variable(self):
54 if self.getArchitecture() == "i386":
55 self.skipTest("requires modern objc runtime")
56 else:
57 self.build()
58 self.frame_var(False)
60 @expectedFailure("rdar://18683637")
61 def test_frame_variable_across_modules(self):
62 if self.getArchitecture() == "i386":
63 self.skipTest("requires modern objc runtime")
64 else:
65 self.build()
66 self.common_setup(False)
67 self.expect(
68 "frame variable k->bar", VARIABLES_DISPLAYED_CORRECTLY, substrs=["= 3"]
71 def common_setup(self, strip):
72 if strip:
73 exe = self.getBuildArtifact("stripped/a.out")
74 else:
75 exe = self.getBuildArtifact("a.out")
76 # Create a target by the debugger.
77 target = self.dbg.CreateTarget(exe)
78 self.assertTrue(target, VALID_TARGET)
80 # Create the breakpoint inside function 'main'.
81 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
82 self.assertTrue(breakpoint, VALID_BREAKPOINT)
84 # Register our shared libraries for remote targets so they get
85 # automatically uploaded
86 environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names)
88 # Now launch the process, and do not stop at entry point.
89 process = target.LaunchSimple(
90 None, environment, self.get_process_working_directory()
92 self.assertTrue(process, PROCESS_IS_VALID)
94 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
96 # Break inside the foo function which takes a bar_ptr argument.
97 lldbutil.run_break_set_by_file_and_line(
98 self, "main.m", self.line, num_expected_locations=1, loc_exact=True
101 self.runCmd("run", RUN_SUCCEEDED)
103 # The stop reason of the thread should be breakpoint.
104 self.expect(
105 "thread list",
106 STOPPED_DUE_TO_BREAKPOINT,
107 substrs=["stopped", "stop reason = breakpoint"],
110 # The breakpoint should have a hit count of 1.
111 lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
113 def expr(self, strip):
114 self.common_setup(strip)
116 # This should display correctly.
117 self.expect(
118 "expression (j->_definer->foo)",
119 VARIABLES_DISPLAYED_CORRECTLY,
120 substrs=["= 4"],
123 self.expect(
124 "expression (j->_definer->bar)",
125 VARIABLES_DISPLAYED_CORRECTLY,
126 substrs=["= 5"],
129 if strip:
130 self.expect(
131 "expression *(j->_definer)",
132 VARIABLES_DISPLAYED_CORRECTLY,
133 substrs=["foo = 4"],
135 else:
136 self.expect(
137 "expression *(j->_definer)",
138 VARIABLES_DISPLAYED_CORRECTLY,
139 substrs=["foo = 4", "bar = 5"],
142 self.expect(
143 "expression (k->foo)", VARIABLES_DISPLAYED_CORRECTLY, substrs=["= 2"]
146 self.expect(
147 "expression (k->bar)", VARIABLES_DISPLAYED_CORRECTLY, substrs=["= 3"]
150 self.expect(
151 "expression k.filteredDataSource",
152 VARIABLES_DISPLAYED_CORRECTLY,
153 substrs=[" = 0x", '"2 elements"'],
156 if strip:
157 self.expect(
158 "expression *(k)",
159 VARIABLES_DISPLAYED_CORRECTLY,
160 substrs=["foo = 2", " = 0x", '"2 elements"'],
162 else:
163 self.expect(
164 "expression *(k)",
165 VARIABLES_DISPLAYED_CORRECTLY,
166 substrs=[
167 "foo = 2",
168 "bar = 3",
169 "_filteredDataSource = 0x",
170 '"2 elements"',
174 def frame_var(self, strip):
175 self.common_setup(strip)
177 # This should display correctly.
178 self.expect(
179 "frame variable j->_definer->foo",
180 VARIABLES_DISPLAYED_CORRECTLY,
181 substrs=["= 4"],
184 if not strip:
185 self.expect(
186 "frame variable j->_definer->bar",
187 VARIABLES_DISPLAYED_CORRECTLY,
188 substrs=["= 5"],
191 if strip:
192 self.expect(
193 "frame variable *j->_definer",
194 VARIABLES_DISPLAYED_CORRECTLY,
195 substrs=["foo = 4"],
197 else:
198 self.expect(
199 "frame variable *j->_definer",
200 VARIABLES_DISPLAYED_CORRECTLY,
201 substrs=["foo = 4", "bar = 5"],
204 self.expect(
205 "frame variable k->foo", VARIABLES_DISPLAYED_CORRECTLY, substrs=["= 2"]
208 self.expect(
209 "frame variable k->_filteredDataSource",
210 VARIABLES_DISPLAYED_CORRECTLY,
211 substrs=[" = 0x", '"2 elements"'],
214 if strip:
215 self.expect(
216 "frame variable *k",
217 VARIABLES_DISPLAYED_CORRECTLY,
218 substrs=["foo = 2", "_filteredDataSource = 0x", '"2 elements"'],
220 else:
221 self.expect(
222 "frame variable *k",
223 VARIABLES_DISPLAYED_CORRECTLY,
224 substrs=[
225 "foo = 2",
226 "bar = 3",
227 "_filteredDataSource = 0x",
228 '"2 elements"',