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