2 Test the "process continue -b" option.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class TestContinueToBkpts(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
15 @add_test_categories(["pyapi"])
16 def test_continue_to_breakpoints(self
):
17 """Test that the continue to breakpoints feature works correctly."""
19 self
.do_test_continue_to_breakpoint()
22 # Call super's setUp().
24 self
.main_source_spec
= lldb
.SBFileSpec("main.c")
26 def continue_and_check(self
, stop_list
, bkpt_to_hit
, loc_to_hit
=0):
27 """Build up a command that will run a continue -b commands using the breakpoints on stop_list, and
28 ensure that we hit bkpt_to_hit.
29 If loc_to_hit is not 0, also verify that we hit that location."""
30 command
= "process continue"
31 for elem
in stop_list
:
32 command
+= " -b {0}".format(elem
)
34 self
.assertStopReason(
35 self
.thread
.stop_reason
, lldb
.eStopReasonBreakpoint
, "Hit a breakpoint"
38 self
.thread
.GetStopReasonDataAtIndex(0),
40 "Hit the right breakpoint",
44 self
.thread
.GetStopReasonDataAtIndex(1),
46 "Hit the right location",
48 for bkpt_id
in self
.bkpt_list
:
49 bkpt
= self
.target
.FindBreakpointByID(bkpt_id
)
50 self
.assertTrue(bkpt
.IsValid(), "Breakpoint id's round trip")
51 if bkpt
.MatchesName("disabled"):
54 "Disabled breakpoints stay disabled: {0}".format(bkpt
.GetID()),
59 "Enabled breakpoints stay enabled: {0}".format(bkpt
.GetID()),
61 # Also do our multiple location one:
62 bkpt
= self
.target
.FindBreakpointByID(self
.multiple_loc_id
)
63 self
.assertTrue(bkpt
.IsValid(), "Breakpoint with locations round trip")
65 loc
= bkpt
.FindLocationByID(i
)
66 self
.assertTrue(loc
.IsValid(), "Locations round trip")
69 loc
.IsEnabled(), "Locations that were enabled stay enabled"
73 loc
.IsEnabled(), "Locations that were disabled stay disabled"
76 def do_test_continue_to_breakpoint(self
):
77 """Test the continue to breakpoint feature."""
78 (self
.target
, process
, self
.thread
, bkpt
) = lldbutil
.run_to_source_breakpoint(
79 self
, "Stop here to get started", self
.main_source_spec
82 # Now set up all our breakpoints:
83 bkpt_pattern
= "This is the {0} stop"
96 disabled_bkpts
= ["first", "eigth"]
97 bkpts_for_MyBKPT
= ["first", "sixth", "nineth"]
99 for elem
in bkpt_elements
:
100 bkpt
= self
.target
.BreakpointCreateBySourceRegex(
101 bkpt_pattern
.format(elem
), self
.main_source_spec
103 self
.assertGreater(bkpt
.GetNumLocations(), 0, "Found a bkpt match")
104 self
.bkpt_list
.append(bkpt
.GetID())
106 if elem
in disabled_bkpts
:
107 bkpt
.AddName("disabled")
108 bkpt
.SetEnabled(False)
109 if elem
in bkpts_for_MyBKPT
:
110 bkpt
.AddName("MyBKPT")
111 # Also make one that has several locations, so we can test locations:
112 mult_bkpt
= self
.target
.BreakpointCreateBySourceRegex(
113 bkpt_pattern
.format("(seventh|eighth|nineth)"), self
.main_source_spec
115 self
.assertEqual(mult_bkpt
.GetNumLocations(), 3, "Got three matches")
116 mult_bkpt
.AddName("Locations")
117 # Disable all of these:
118 for i
in range(1, 4):
119 loc
= mult_bkpt
.FindLocationByID(i
)
120 self
.assertTrue(loc
.IsValid(), "Location {0} is valid".format(i
))
121 loc
.SetEnabled(False)
122 self
.assertFalse(loc
.IsEnabled(), "Loc {0} wasn't disabled".format(i
))
123 self
.multiple_loc_id
= mult_bkpt
.GetID()
125 # First test out various error conditions
127 # All locations of the multiple_loc_id are disabled, so running to this should be an error:
129 "process continue -b {0}".format(self
.multiple_loc_id
),
131 msg
="Running to a disabled breakpoint by number",
134 # Now re-enable the middle one so we can run to it:
135 loc
= mult_bkpt
.FindLocationByID(2)
139 "process continue -b {0}".format(self
.bkpt_list
[1]),
141 msg
="Running to a disabled breakpoint by number",
144 "process continue -b {0}.1".format(self
.bkpt_list
[1]),
146 msg
="Running to a location of a disabled breakpoint",
149 "process continue -b disabled",
151 msg
="Running to a disabled set of breakpoints",
154 "process continue -b {0}.{1}".format(self
.multiple_loc_id
, 1),
156 msg
="Running to a disabled breakpoint location",
159 "process continue -b {0}".format("THERE_ARE_NO_BREAKPOINTS_BY_THIS_NAME"),
161 msg
="Running to no such name",
164 "process continue -b {0}".format(1000),
166 msg
="Running to no such breakpoint",
169 "process continue -b {0}.{1}".format(self
.multiple_loc_id
, 1000),
171 msg
="Running to no such location",
174 # Now move forward, this time with breakpoint numbers. First time we don't skip other bkpts.
175 bkpt
= self
.bkpt_list
[0]
176 self
.continue_and_check([str(bkpt
)], bkpt
)
178 # Now skip to the third stop, do it by name and supply one of the later breakpoints as well:
179 # This continue has to muck with the sync mode of the debugger, so let's make sure we
180 # put it back. First try if it was in sync mode:
181 orig_async
= self
.dbg
.GetAsync()
182 self
.dbg
.SetAsync(True)
183 self
.continue_and_check([bkpt_elements
[2], bkpt_elements
[7]], self
.bkpt_list
[2])
184 after_value
= self
.dbg
.GetAsync()
185 self
.dbg
.SetAsync(orig_async
)
186 self
.assertTrue(after_value
, "Preserve async as True if it started that way")
188 # Now try a name that has several breakpoints.
189 # This time I'm also going to check that we put the debugger async mode back if
190 # if was False to begin with:
191 self
.dbg
.SetAsync(False)
192 self
.continue_and_check(["MyBKPT"], self
.bkpt_list
[6])
193 after_value
= self
.dbg
.GetAsync()
194 self
.dbg
.SetAsync(orig_async
)
195 self
.assertFalse(after_value
, "Preserve async as False if it started that way")
197 # Now let's run to a particular location. Also specify a breakpoint we've already hit:
198 self
.continue_and_check(
199 [self
.bkpt_list
[0], self
.multiple_loc_id
], self
.multiple_loc_id
, 2