2 Test that we handle breakpoints on consecutive instructions correctly.
5 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
15 class ConsecutiveBreakpointsTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
19 def prepare_test(self):
21 exe = os.path.join(os.getcwd(), "a.out")
23 # Create a target by the debugger.
24 self.target = self.dbg.CreateTarget(exe)
25 self.assertTrue(self.target, VALID_TARGET)
27 breakpoint1 = self.target.BreakpointCreateBySourceRegex(
28 "Set breakpoint here", lldb.SBFileSpec("main.cpp"))
30 breakpoint1 and breakpoint1.GetNumLocations() == 1,
33 # Now launch the process, and do not stop at entry point.
34 self.process = self.target.LaunchSimple(
35 None, None, self.get_process_working_directory())
36 self.assertIsNotNone(self.process, PROCESS_IS_VALID)
38 # We should be stopped at the first breakpoint
39 self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(
40 self.process, breakpoint1)
43 "Expected one thread to be stopped at breakpoint 1")
45 # Set breakpoint to the next instruction
46 frame = self.thread.GetFrameAtIndex(0)
48 address = frame.GetPCAddress()
49 instructions = self.target.ReadInstructions(address, 2)
50 self.assertTrue(len(instructions) == 2)
51 self.bkpt_address = instructions[1].GetAddress()
52 self.breakpoint2 = self.target.BreakpointCreateByAddress(
53 self.bkpt_address.GetLoadAddress(self.target))
55 self.breakpoint2 and self.breakpoint2.GetNumLocations() == 1,
58 def finish_test(self):
59 # Run the process until termination
60 self.process.Continue()
61 self.assertEquals(self.process.GetState(), lldb.eStateExited)
64 def test_continue(self):
65 """Test that continue stops at the second breakpoint."""
68 self.process.Continue()
69 self.assertEquals(self.process.GetState(), lldb.eStateStopped)
70 # We should be stopped at the second breakpoint
71 self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(
72 self.process, self.breakpoint2)
75 "Expected one thread to be stopped at breakpoint 2")
80 def test_single_step(self):
81 """Test that single step stops at the second breakpoint."""
85 self.thread.StepInstruction(step_over)
87 self.assertEquals(self.process.GetState(), lldb.eStateStopped)
89 self.thread.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress(
90 self.target), self.bkpt_address.GetLoadAddress(
92 self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(
93 self.process, self.breakpoint2)
96 "Expected one thread to be stopped at breakpoint 2")
101 def test_single_step_thread_specific(self):
102 """Test that single step stops, even though the second breakpoint is not valid."""
105 # Choose a thread other than the current one. A non-existing thread is
107 thread_index = self.process.GetNumThreads() + 1
108 self.assertFalse(self.process.GetThreadAtIndex(thread_index).IsValid())
109 self.breakpoint2.SetThreadIndex(thread_index)
112 self.thread.StepInstruction(step_over)
114 self.assertEquals(self.process.GetState(), lldb.eStateStopped)
116 self.thread.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress(
117 self.target), self.bkpt_address.GetLoadAddress(
120 self.thread.GetStopReason(),
121 lldb.eStopReasonPlanComplete,
122 "Stop reason should be 'plan complete'")