1 """Test that types defined in shared libraries work correctly."""
3 from __future__ import print_function
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 import lldbsuite.test.lldbutil as lldbutil
13 class SharedLibTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 def common_test_expr(self, preload_symbols):
18 if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion():
20 "llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef")
23 self.common_setup(preload_symbols)
25 # This should display correctly.
27 "expression --show-types -- *my_foo_ptr",
28 VARIABLES_DISPLAYED_CORRECTLY,
35 "expression GetMeASubFoo(my_foo_ptr)",
36 startstr="(sub_foo *) $")
38 @expectedFailureAll(oslist=["windows"])
40 """Test that types work when defined in a shared library and forward-declared in the main executable"""
41 self.common_test_expr(True)
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)
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"""
54 # This should display correctly.
56 "frame variable --show-types -- *my_foo_ptr",
57 VARIABLES_DISPLAYED_CORRECTLY,
64 # Call super's setUp().
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"]
71 def common_setup(self, preload_symbols = True):
72 # Run in synchronous mode
73 self.dbg.SetAsync(False)
75 # Create a target by the debugger.
76 target = self.dbg.CreateTarget("a.out")
77 self.assertTrue(target, VALID_TARGET)
79 self.runCmd("settings set target.preload-symbols " + str(preload_symbols).lower())
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)
85 # Register our shared libraries for remote targets so they get
86 # automatically uploaded
87 environment = self.registerSharedLibrariesWithTarget(
88 target, self.shlib_names)
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)
95 # The stop reason of the thread should be breakpoint.
96 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
98 'stop reason = breakpoint'])
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'])