1f513b5fcSPavel Labath"""Test that types defined in shared libraries work correctly.""" 2f513b5fcSPavel Labath 3f513b5fcSPavel Labath 4f513b5fcSPavel Labathimport lldb 5f513b5fcSPavel Labathfrom lldbsuite.test.decorators import * 6f513b5fcSPavel Labathfrom lldbsuite.test.lldbtest import * 7f513b5fcSPavel Labathimport lldbsuite.test.lldbutil as lldbutil 8f513b5fcSPavel Labath 9f513b5fcSPavel Labath 10f513b5fcSPavel Labathclass SharedLibTestCase(TestBase): 11f513b5fcSPavel Labath def setUp(self): 12f513b5fcSPavel Labath # Call super's setUp(). 13f513b5fcSPavel Labath TestBase.setUp(self) 14f513b5fcSPavel Labath # Find the line number to break inside main(). 15f513b5fcSPavel Labath self.source = "shared.c" 16f513b5fcSPavel Labath self.line = line_number(self.source, "// Set breakpoint 0 here.") 17f513b5fcSPavel Labath self.shlib_names = ["foo"] 18f513b5fcSPavel Labath 19f513b5fcSPavel Labath def common_setup(self): 20f513b5fcSPavel Labath # Run in synchronous mode 21f513b5fcSPavel Labath self.dbg.SetAsync(False) 22f513b5fcSPavel Labath self.runCmd("settings set symbols.load-on-demand true") 23f513b5fcSPavel Labath 24f513b5fcSPavel Labath # Create a target by the debugger. 25f513b5fcSPavel Labath self.target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 26f513b5fcSPavel Labath self.assertTrue(self.target, VALID_TARGET) 27f513b5fcSPavel Labath 28f513b5fcSPavel Labath # Register our shared libraries for remote targets so they get 29f513b5fcSPavel Labath # automatically uploaded 30f513b5fcSPavel Labath self.environment = self.registerSharedLibrariesWithTarget( 31f513b5fcSPavel Labath self.target, self.shlib_names 32f513b5fcSPavel Labath ) 33f513b5fcSPavel Labath 34f513b5fcSPavel Labath ctx = self.platformContext 35f513b5fcSPavel Labath self.shared_lib_name = ctx.shlib_prefix + "foo." + ctx.shlib_extension 36f513b5fcSPavel Labath 37f513b5fcSPavel Labath @skipIfWindows 38f513b5fcSPavel Labath def test_source_line_breakpoint(self): 39f513b5fcSPavel Labath self.build() 40f513b5fcSPavel Labath self.common_setup() 41f513b5fcSPavel Labath 42f513b5fcSPavel Labath lldbutil.run_break_set_by_file_and_line( 43f513b5fcSPavel Labath self, "foo.c", 4, num_expected_locations=1, loc_exact=True 44f513b5fcSPavel Labath ) 45f513b5fcSPavel Labath 46f513b5fcSPavel Labath # Now launch the process, and do not stop at entry point. 47f513b5fcSPavel Labath process = self.target.LaunchSimple( 48f513b5fcSPavel Labath None, self.environment, self.get_process_working_directory() 49f513b5fcSPavel Labath ) 50f513b5fcSPavel Labath self.assertTrue(process, PROCESS_IS_VALID) 51f513b5fcSPavel Labath 52f513b5fcSPavel Labath # The stop reason of the thread should be breakpoint. 53f513b5fcSPavel Labath self.expect( 54f513b5fcSPavel Labath "thread list", 55f513b5fcSPavel Labath STOPPED_DUE_TO_BREAKPOINT, 56f513b5fcSPavel Labath substrs=["stopped", "stop reason = breakpoint"], 57f513b5fcSPavel Labath ) 58f513b5fcSPavel Labath # The breakpoint should have a hit count of 1. 59f513b5fcSPavel Labath lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1) 60f513b5fcSPavel Labath 61f513b5fcSPavel Labath thread = process.GetSelectedThread() 62*0bfc9514SDave Lee stack_frames = thread.frames 63f513b5fcSPavel Labath self.assertGreater(len(stack_frames), 2) 64f513b5fcSPavel Labath 65f513b5fcSPavel Labath leaf_frame = stack_frames[0] 66f513b5fcSPavel Labath self.assertEqual("foo.c", leaf_frame.GetLineEntry().GetFileSpec().GetFilename()) 67f513b5fcSPavel Labath self.assertEqual(4, leaf_frame.GetLineEntry().GetLine()) 68f513b5fcSPavel Labath 69f513b5fcSPavel Labath parent_frame = stack_frames[1] 70f513b5fcSPavel Labath self.assertEqual( 71f513b5fcSPavel Labath "shared.c", parent_frame.GetLineEntry().GetFileSpec().GetFilename() 72f513b5fcSPavel Labath ) 73f513b5fcSPavel Labath self.assertEqual(7, parent_frame.GetLineEntry().GetLine()) 74f513b5fcSPavel Labath 75f513b5fcSPavel Labath @skipIfWindows 76f513b5fcSPavel Labath def test_symbolic_breakpoint(self): 77f513b5fcSPavel Labath self.build() 78f513b5fcSPavel Labath self.common_setup() 79f513b5fcSPavel Labath 80f513b5fcSPavel Labath lldbutil.run_break_set_by_symbol( 81f513b5fcSPavel Labath self, "foo", sym_exact=True, num_expected_locations=1 82f513b5fcSPavel Labath ) 83f513b5fcSPavel Labath 84f513b5fcSPavel Labath # Now launch the process, and do not stop at entry point. 85f513b5fcSPavel Labath process = self.target.LaunchSimple( 86f513b5fcSPavel Labath None, self.environment, self.get_process_working_directory() 87f513b5fcSPavel Labath ) 88f513b5fcSPavel Labath self.assertTrue(process, PROCESS_IS_VALID) 89f513b5fcSPavel Labath 90f513b5fcSPavel Labath # The stop reason of the thread should be breakpoint. 91f513b5fcSPavel Labath self.expect( 92f513b5fcSPavel Labath "thread list", 93f513b5fcSPavel Labath STOPPED_DUE_TO_BREAKPOINT, 94f513b5fcSPavel Labath substrs=["stopped", "stop reason = breakpoint"], 95f513b5fcSPavel Labath ) 96f513b5fcSPavel Labath # The breakpoint should have a hit count of 1. 97f513b5fcSPavel Labath lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1) 98f513b5fcSPavel Labath 99f513b5fcSPavel Labath thread = process.GetSelectedThread() 100*0bfc9514SDave Lee stack_frames = thread.frames 101f513b5fcSPavel Labath self.assertGreater(len(stack_frames), 2) 102f513b5fcSPavel Labath 103f513b5fcSPavel Labath leaf_frame = stack_frames[0] 104f513b5fcSPavel Labath self.assertEqual("foo.c", leaf_frame.GetLineEntry().GetFileSpec().GetFilename()) 105f513b5fcSPavel Labath self.assertEqual(4, leaf_frame.GetLineEntry().GetLine()) 106f513b5fcSPavel Labath 107f513b5fcSPavel Labath parent_frame = stack_frames[1] 108f513b5fcSPavel Labath self.assertEqual( 109f513b5fcSPavel Labath "shared.c", parent_frame.GetLineEntry().GetFileSpec().GetFilename() 110f513b5fcSPavel Labath ) 111f513b5fcSPavel Labath self.assertEqual(7, parent_frame.GetLineEntry().GetLine()) 112f513b5fcSPavel Labath 113f513b5fcSPavel Labath @skipIfWindows 114f513b5fcSPavel Labath def test_global_variable_hydration(self): 115f513b5fcSPavel Labath self.build() 116f513b5fcSPavel Labath self.common_setup() 117f513b5fcSPavel Labath 118f513b5fcSPavel Labath lldbutil.run_break_set_by_file_and_line( 119f513b5fcSPavel Labath self, self.source, self.line, num_expected_locations=1, loc_exact=True 120f513b5fcSPavel Labath ) 121f513b5fcSPavel Labath 122f513b5fcSPavel Labath # Now launch the process, and do not stop at entry point. 123f513b5fcSPavel Labath process = self.target.LaunchSimple( 124f513b5fcSPavel Labath None, self.environment, self.get_process_working_directory() 125f513b5fcSPavel Labath ) 126f513b5fcSPavel Labath self.assertTrue(process, PROCESS_IS_VALID) 127f513b5fcSPavel Labath 128f513b5fcSPavel Labath # The stop reason of the thread should be breakpoint. 129f513b5fcSPavel Labath self.expect( 130f513b5fcSPavel Labath "thread list", 131f513b5fcSPavel Labath STOPPED_DUE_TO_BREAKPOINT, 132f513b5fcSPavel Labath substrs=["stopped", "stop reason = breakpoint"], 133f513b5fcSPavel Labath ) 134f513b5fcSPavel Labath 135f513b5fcSPavel Labath # The breakpoint should have a hit count of 1. 136f513b5fcSPavel Labath lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1) 137f513b5fcSPavel Labath 138f513b5fcSPavel Labath self.expect( 139f513b5fcSPavel Labath "target variable --shlib a.out", 140f513b5fcSPavel Labath "Breakpoint in a.out should have hydrated the debug info", 141f513b5fcSPavel Labath substrs=["global_shared = 897"], 142f513b5fcSPavel Labath ) 143f513b5fcSPavel Labath 144f513b5fcSPavel Labath self.expect( 145f513b5fcSPavel Labath "target variable --shlib " + self.shared_lib_name, 146f513b5fcSPavel Labath "shared library should not have debug info by default", 147f513b5fcSPavel Labath matching=False, 148f513b5fcSPavel Labath substrs=["global_foo"], 149f513b5fcSPavel Labath ) 150f513b5fcSPavel Labath 151f513b5fcSPavel Labath self.expect( 152f513b5fcSPavel Labath "target variable global_foo --shlib " + self.shared_lib_name, 153f513b5fcSPavel Labath "Match global_foo in symbol table should hydrate debug info", 154f513b5fcSPavel Labath matching=True, 155f513b5fcSPavel Labath substrs=["global_foo = 321"], 156f513b5fcSPavel Labath ) 157