e0b727e9734f8cb7afb59426576f4b8fecf06d79
[openbsd] /
1 """
2 Test that the breakpoint auto-continue flag works correctly.
3 """
4
5
6
7 import lldb
8 import lldbsuite.test.lldbutil as lldbutil
9 from lldbsuite.test.lldbtest import *
10
11
12 class BreakpointAutoContinue(TestBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     NO_DEBUG_INFO_TESTCASE = True
17
18     def test_breakpoint_auto_continue(self):
19         """Make sure the auto continue continues with no other complications"""
20         self.build()
21         self.simple_auto_continue()
22
23     def test_auto_continue_with_command(self):
24         """Add a command, make sure the command gets run"""
25         self.build()
26         self.auto_continue_with_command()
27
28     def test_auto_continue_on_location(self):
29         """Set auto-continue on a location and make sure only that location continues"""
30         self.build()
31         self.auto_continue_location()
32
33     def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
34                              pattern="Set a breakpoint here"):
35         exe = self.getBuildArtifact("a.out")
36         self.target = self.dbg.CreateTarget(exe)
37         self.assertTrue(self.target.IsValid(), "Target is not valid")
38
39         extra_options_txt = "--auto-continue 1 "
40         if additional_options:
41             extra_options_txt += additional_options
42         bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
43                                             extra_options = extra_options_txt,
44                                             num_expected_locations = num_expected_loc)
45         return bpno
46
47     def launch_it (self, expected_state):
48         error = lldb.SBError()
49         launch_info = lldb.SBLaunchInfo(None)
50         launch_info.SetWorkingDirectory(self.get_process_working_directory())
51
52         process = self.target.Launch(launch_info, error)
53         self.assertTrue(error.Success(), "Launch failed.")
54
55         state = process.GetState()
56         self.assertEqual(state, expected_state, "Didn't get expected state")
57
58         return process
59
60     def simple_auto_continue(self):
61         bpno = self.make_target_and_bkpt()
62         process = self.launch_it(lldb.eStateExited)
63
64         bkpt = self.target.FindBreakpointByID(bpno)
65         self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice")
66
67     def auto_continue_with_command(self):
68         bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'")
69         process = self.launch_it(lldb.eStateStopped)
70         state = process.GetState()
71         self.assertEqual(state, lldb.eStateStopped, "Process should be stopped")
72         bkpt = self.target.FindBreakpointByID(bpno)
73         threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
74         self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint")
75         self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")
76
77     def auto_continue_location(self):
78         bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2)
79         bkpt = self.target.FindBreakpointByID(bpno)
80         bkpt.SetAutoContinue(False)
81
82         loc = lldb.SBBreakpointLocation()
83         for i in range(0,2):
84             func_name = bkpt.location[i].GetAddress().function.name
85             if func_name == "main":
86                 loc = bkpt.location[i]
87
88         self.assertTrue(loc.IsValid(), "Didn't find a location in main")
89         loc.SetAutoContinue(True)
90
91         process = self.launch_it(lldb.eStateStopped)
92
93         threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
94         self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint")
95         func_name = threads[0].frame[0].function.name
96         self.assertEqual(func_name, "call_me")