78 lines · python
1"""2When a rebuild causes a location to be removed, make sure3we still handle the remaining locations correctly.4"""5 6 7import lldb8import lldbsuite.test.lldbutil as lldbutil9from lldbsuite.test.lldbtest import *10from lldbsuite.test.decorators import skipIfWindows11import os12 13 14class TestLocationsAfterRebuild(TestBase):15 # If your test case doesn't stress debug info, then16 # set this to true. That way it won't be run once for17 # each debug info format.18 NO_DEBUG_INFO_TESTCASE = True19 20 # On Windows we cannot remove a file that lldb is debugging.21 @skipIfWindows22 def test_remaining_location_spec(self):23 """If we rebuild a couple of times some of the old locations24 get removed. Make sure the command-line breakpoint id25 validator still works correctly."""26 self.build(dictionary={"C_SOURCES": "main.c", "EXE": "a.out"})27 28 path_to_exe = self.getBuildArtifact()29 30 (target, process, thread, bkpt) = lldbutil.run_to_name_breakpoint(self, "main")31 32 # Let the process continue to exit:33 process.Continue()34 self.assertEqual(process.GetState(), lldb.eStateExited, "Ran to completion")35 os.remove(path_to_exe)36 37 # We have to rebuild twice with changed sources to get38 # us to remove the first set of locations:39 self.build(dictionary={"C_SOURCES": "second_main.c", "EXE": "a.out"})40 41 (target, process, thread, bkpt) = lldbutil.run_to_breakpoint_do_run(42 self, target, bkpt43 )44 45 # Let the process continue to exit:46 process.Continue()47 self.assertEqual(process.GetState(), lldb.eStateExited, "Ran to completion")48 49 os.remove(path_to_exe)50 51 self.build(dictionary={"C_SOURCES": "third_main.c", "EXE": "a.out"})52 53 (target, process, thread, bkpt) = lldbutil.run_to_breakpoint_do_run(54 self, target, bkpt55 )56 57 # After enabling locate_module callback for main executables,58 # the number of locations may vary depending on the platform.59 num_locs = bkpt.GetNumLocations()60 bkpt_id = bkpt.GetID()61 62 self.assertGreater(63 num_locs,64 0,65 f"Expected at least one breakpoint location, but found {num_locs}",66 )67 68 # Iterate through all valid locations and verify we can disable each one.69 # This tests that breakpoint location IDs remain valid after rebuilds.70 for loc_idx in range(num_locs):71 loc = bkpt.GetLocationAtIndex(loc_idx)72 self.assertTrue(loc.IsValid(), f"Location at index {loc_idx} is not valid")73 74 # Get the actual location ID from the location object75 loc_id = loc.GetID()76 loc_string = f"{bkpt_id}.{loc_id}"77 self.runCmd(f"break disable {loc_string}")78