1import lldb 2from lldbsuite.test.decorators import * 3from lldbsuite.test.lldbtest import * 4from lldbsuite.test import lldbutil 5 6class TestBreakInLoadedDylib(TestBase): 7 """ Test that we can set a source regex breakpoint that will take in 8 a dlopened library that hasn't loaded when we set the breakpoint.""" 9 10 mydir = TestBase.compute_mydir(__file__) 11 NO_DEBUG_INFO_TESTCASE = True 12 13 @skipIfRemote 14 def common_setup(self): 15 self.build() 16 ctx = self.platformContext 17 self.main_spec = lldb.SBFileSpec("main.cpp") 18 self.b_spec = lldb.SBFileSpec("b.cpp") 19 self.lib_shortname = 'lib_b' 20 self.lib_fullname = ctx.shlib_prefix + self.lib_shortname + '.' + ctx.shlib_extension 21 self.lib_spec = lldb.SBFileSpec(self.lib_fullname) 22 23 def test_break_in_dlopen_dylib_using_lldbutils(self): 24 self.common_setup() 25 lldbutil.run_to_source_breakpoint(self, "Break here in dylib", self.b_spec, 26 bkpt_module=self.lib_fullname, 27 extra_images = [self.lib_shortname], 28 has_locations_before_run = False) 29 30 @skipIfRemote 31 def test_break_in_dlopen_dylib_using_target(self): 32 self.common_setup() 33 34 target, process, _, _ = lldbutil.run_to_source_breakpoint(self, "Break here before we dlopen", self.main_spec, 35 extra_images = [self.lib_shortname]) 36 37 # Now set some breakpoints that won't take till the library is loaded: 38 # This one is currently how lldbutils does it but test here in case that changes: 39 bkpt1 = target.BreakpointCreateBySourceRegex("Break here in dylib", self.b_spec, self.lib_fullname) 40 41 # Try the file list API as well. Put in some bogus entries too, to make sure those 42 # don't trip us up: 43 44 files_list = lldb.SBFileSpecList() 45 files_list.Append(self.b_spec) 46 files_list.Append(self.main_spec) 47 files_list.Append(lldb.SBFileSpec("I_bet_nobody_has_this_file.cpp")) 48 49 modules_list = lldb.SBFileSpecList() 50 modules_list.Append(self.lib_spec) 51 modules_list.Append(lldb.SBFileSpec("libI_bet_not_this_one_either.dylib")) 52 53 bkpt2 = target.BreakpointCreateBySourceRegex("Break here in dylib", modules_list, files_list) 54 55 lldbutil.continue_to_breakpoint(process, bkpt1) 56 self.assertEqual(bkpt1.GetHitCount(), 1, "Hit breakpoint 1") 57 self.assertEqual(bkpt2.GetHitCount(), 1, "Hit breakpoint 2") 58 59 60 61 62