103 lines · python
1"""2Test the WasHit feature of scripted breakpoints3"""4 5import os6import lldb7import lldbsuite.test.lldbutil as lldbutil8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10 11 12class TestWasHit(TestBase):13 NO_DEBUG_INFO_TESTCASE = True14 15 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")16 def test_was_hit_resolver(self):17 """Use facade breakpoints to emulate hitting some locations"""18 self.build()19 self.do_test()20 21 def make_target_and_import(self):22 target = lldbutil.run_to_breakpoint_make_target(self)23 self.import_resolver_script()24 return target25 26 def import_resolver_script(self):27 interp = self.dbg.GetCommandInterpreter()28 error = lldb.SBError()29 30 script_name = os.path.join(self.getSourceDir(), "bkpt_resolver.py")31 32 command = "command script import " + script_name33 self.runCmd(command)34 35 def make_extra_args(self, sym_name, num_locs, loc_to_miss):36 return f" -k symbol -v {sym_name} -k num_locs -v {num_locs} -k loc_to_miss -v {loc_to_miss} "37 38 def do_test(self):39 """This reads in a python file and sets a breakpoint using it."""40 41 target = self.make_target_and_import()42 extra_args = self.make_extra_args("stop_symbol", 4, 2)43 44 bkpt_no = lldbutil.run_break_set_by_script(45 self, "bkpt_resolver.FacadeExample", extra_args, 446 )47 48 # Make sure the help text shows up in the "break list" output:49 self.expect(50 "break list",51 substrs=["I am a facade resolver - sym: stop_symbol - num_locs: 4"],52 msg="Help is listed in break list",53 )54 55 bkpt = target.FindBreakpointByID(bkpt_no)56 self.assertTrue(bkpt.IsValid(), "Found the right breakpoint")57 58 # Now continue. We should hit locations 1, 3 and 4:59 (target, process, thread, bkpt) = lldbutil.run_to_breakpoint_do_run(60 self, target, bkpt61 )62 # This location should be bkpt_no.1:63 self.assertEqual(64 thread.stop_reason_data[0], bkpt_no, "Hit the right breakpoint"65 )66 self.assertEqual(thread.stop_reason_data[1], 1, "First location hit is 1")67 68 for loc in [3, 4]:69 process.Continue()70 self.assertEqual(71 thread.stop_reason, lldb.eStopReasonBreakpoint, "Hit breakpoint"72 )73 self.assertEqual(74 thread.stop_reason_data[0], bkpt_no, "Hit the right breakpoint"75 )76 self.assertEqual(77 thread.stop_reason_data[1], loc, f"Hit the right location: {loc}"78 )79 80 # At this point we should have hit three of the four locations, and not location 1.2.81 # Check that that is true, and that the descriptions for the location are the ones82 # the resolver provided.83 self.assertEqual(bkpt.hit_count, 3, "Hit three locations")84 for loc_id in range(1, 4):85 bkpt_loc = bkpt.FindLocationByID(loc_id)86 self.assertTrue(bkpt_loc.IsValid(), f"{loc_id} was invalid.")87 if loc_id != 2:88 self.assertEqual(89 bkpt_loc.hit_count, 1, f"Loc {loc_id} hit count was wrong"90 )91 else:92 self.assertEqual(bkpt_loc.hit_count, 0, "We didn't skip loc 2")93 stream = lldb.SBStream()94 self.assertTrue(95 bkpt_loc.GetDescription(stream, lldb.eDescriptionLevelFull),96 f"Didn't get description for {loc_id}",97 )98 self.assertIn(99 f"Location index: {loc_id}",100 stream.GetData(),101 f"Wrong desciption for {loc_id}",102 )103