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