TestBreakpointLocations.py revision a720ff4065a51f2a2545634faaf8c90a71fe9d2a
194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen""" 294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny ChenTest breakpoint commands for a breakpoint ID with multiple locations. 394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen""" 494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenimport os, time 694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenimport unittest2 794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenimport lldb 894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenfrom lldbtest import * 994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 1094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenclass BreakpointLocationsTestCase(TestBase): 1194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 1294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen mydir = "breakpoint_locations" 1394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 1494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 1594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen def test_with_dsym(self): 1694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen """Test breakpoint enable/disable for a breakpoint ID with multiple locations.""" 1794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.buildDsym() 1894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.breakpoint_locations_test() 1994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 2094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen def test_with_dwarf(self): 2194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen """Test breakpoint enable/disable for a breakpoint ID with multiple locations.""" 2294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.buildDwarf() 2394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.breakpoint_locations_test() 2494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 2575be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen def setUp(self): 260910eb32b94bd67b0357d34d0951aad197742569Johnny Chen # Call super's setUp(). 270910eb32b94bd67b0357d34d0951aad197742569Johnny Chen TestBase.setUp(self) 2875be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen # Find the line number to break inside main(). 2975be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen self.line = line_number('main.c', '// Set break point at this line.') 3075be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen 3194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen def breakpoint_locations_test(self): 3294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen """Test breakpoint enable/disable for a breakpoint ID with multiple locations.""" 3394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen exe = os.path.join(os.getcwd(), "a.out") 3494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 3594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 3694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # This should create a breakpoint with 3 locations. 3775be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen self.expect("breakpoint set -f main.c -l %d" % self.line, 3875be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen BREAKPOINT_CREATED, 3975be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 3" % 4075be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen self.line) 4194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 4294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # The breakpoint list should show 3 locations. 4394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.expect("breakpoint list", "Breakpoint locations shown correctly", 4475be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen substrs = ["1: file ='main.c', line = %d, locations = 3" % self.line], 45c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen patterns = ["where = a.out`func_inlined .+unresolved, hit count = 0", 46c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen "where = a.out`main .+\[inlined\].+unresolved, hit count = 0"]) 4794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 4894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # The 'breakpoint disable 3.*' command should fail gracefully. 4994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.expect("breakpoint disable 3.*", 5094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen "Disabling an invalid breakpoint should fail gracefully", 5194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen error=True, 5294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen startstr = "error: '3' is not a valid breakpoint ID.") 5394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 5494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # The 'breakpoint disable 1.*' command should disable all 3 locations. 5594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.expect("breakpoint disable 1.*", "All 3 breakpoint locatons disabled correctly", 5694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen startstr = "3 breakpoints disabled.") 5794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 5894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # Run the program. 5994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.runCmd("run", RUN_SUCCEEDED) 6094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 6194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # We should not stopped on any breakpoint at all. 6294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.expect("process status", "No stopping on any disabled breakpoint", 6394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen patterns = ["^Process [0-9]+ exited with status = 0"]) 6494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 6594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # The 'breakpoint enable 1.*' command should enable all 3 breakpoints. 6694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.expect("breakpoint enable 1.*", "All 3 breakpoint locatons enabled correctly", 6794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen startstr = "3 breakpoints enabled.") 6894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 6994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # The 'breakpoint disable 1.1' command should disable 1 location. 7094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.expect("breakpoint disable 1.1", "1 breakpoint locatons disabled correctly", 7194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen startstr = "1 breakpoints disabled.") 7294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 7394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen # Run the program againt. We should stop on the two breakpoint locations. 7494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.runCmd("run", RUN_SUCCEEDED) 7594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 76c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen # Stopped once. 77c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 78c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen substrs = ["stop reason = breakpoint 1."]) 7994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 80c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen # Continue the program, there should be another stop. 8194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen self.runCmd("process continue") 8294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 83c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen # Stopped again. 84c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 85c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen substrs = ["stop reason = breakpoint 1."]) 8694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 87a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen # At this point, 1.1 has a hit count of 0 and the other a hit count of 1". 88a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen self.expect("breakpoint list", "The breakpoints should report correct hit counts", 89a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen patterns = ["1\.1: .+ unresolved, hit count = 0 +Options: disabled", 90a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen "1\.2: .+ resolved, hit count = 1", 91a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen "1\.3: .+ resolved, hit count = 1"]) 9294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 9394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen 9494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenif __name__ == '__main__': 9594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen import atexit 9694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen lldb.SBDebugger.Initialize() 9794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen atexit.register(lambda: lldb.SBDebugger.Terminate()) 9894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen unittest2.main() 99