2 Test that the breakpoint auto-continue flag works correctly.
5 from __future__ import print_function
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.lldbtest import *
16 class BreakpointAutoContinue(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
20 NO_DEBUG_INFO_TESTCASE = True
22 def test_breakpoint_auto_continue(self):
23 """Make sure the auto continue continues with no other complications"""
25 self.simple_auto_continue()
27 def test_auto_continue_with_command(self):
28 """Add a command, make sure the command gets run"""
30 self.auto_continue_with_command()
32 def test_auto_continue_on_location(self):
33 """Set auto-continue on a location and make sure only that location continues"""
35 self.auto_continue_location()
37 def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
38 pattern="Set a breakpoint here"):
39 exe = self.getBuildArtifact("a.out")
40 self.target = self.dbg.CreateTarget(exe)
41 self.assertTrue(self.target.IsValid(), "Target is not valid")
43 extra_options_txt = "--auto-continue 1 "
44 if additional_options:
45 extra_options_txt += additional_options
46 bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
47 extra_options = extra_options_txt,
48 num_expected_locations = num_expected_loc)
51 def launch_it (self, expected_state):
52 error = lldb.SBError()
53 launch_info = lldb.SBLaunchInfo(None)
54 launch_info.SetWorkingDirectory(self.get_process_working_directory())
56 process = self.target.Launch(launch_info, error)
57 self.assertTrue(error.Success(), "Launch failed.")
59 state = process.GetState()
60 self.assertEqual(state, expected_state, "Didn't get expected state")
65 # Call super's setUp().
68 def simple_auto_continue(self):
69 bpno = self.make_target_and_bkpt()
70 process = self.launch_it(lldb.eStateExited)
72 bkpt = self.target.FindBreakpointByID(bpno)
73 self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice")
75 def auto_continue_with_command(self):
76 bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'")
77 process = self.launch_it(lldb.eStateStopped)
78 state = process.GetState()
79 self.assertEqual(state, lldb.eStateStopped, "Process should be stopped")
80 bkpt = self.target.FindBreakpointByID(bpno)
81 threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
82 self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint")
83 self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")
85 def auto_continue_location(self):
86 bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2)
87 bkpt = self.target.FindBreakpointByID(bpno)
88 bkpt.SetAutoContinue(False)
90 loc = lldb.SBBreakpointLocation()
92 func_name = bkpt.location[i].GetAddress().function.name
93 if func_name == "main":
94 loc = bkpt.location[i]
96 self.assertTrue(loc.IsValid(), "Didn't find a location in main")
97 loc.SetAutoContinue(True)
99 process = self.launch_it(lldb.eStateStopped)
101 threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
102 self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint")
103 func_name = threads[0].frame[0].function.name
104 self.assertEqual(func_name, "call_me")