]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoints/TestConsecutiveBreakpoints.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / breakpoint / consecutive_breakpoints / TestConsecutiveBreakpoints.py
1 """
2 Test that we handle breakpoints on consecutive instructions correctly.
3 """
4
5 from __future__ import print_function
6
7
8 import unittest2
9 import lldb
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13
14
15 class ConsecutiveBreakpointsTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def prepare_test(self):
20         self.build()
21         exe = os.path.join(os.getcwd(), "a.out")
22
23         # Create a target by the debugger.
24         self.target = self.dbg.CreateTarget(exe)
25         self.assertTrue(self.target, VALID_TARGET)
26
27         breakpoint1 = self.target.BreakpointCreateBySourceRegex(
28             "Set breakpoint here", lldb.SBFileSpec("main.cpp"))
29         self.assertTrue(
30             breakpoint1 and breakpoint1.GetNumLocations() == 1,
31             VALID_BREAKPOINT)
32
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)
37
38         # We should be stopped at the first breakpoint
39         self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(
40             self.process, breakpoint1)
41         self.assertIsNotNone(
42             self.thread,
43             "Expected one thread to be stopped at breakpoint 1")
44
45         # Set breakpoint to the next instruction
46         frame = self.thread.GetFrameAtIndex(0)
47
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))
54         self.assertTrue(
55             self.breakpoint2 and self.breakpoint2.GetNumLocations() == 1,
56             VALID_BREAKPOINT)
57
58     def finish_test(self):
59         # Run the process until termination
60         self.process.Continue()
61         self.assertEquals(self.process.GetState(), lldb.eStateExited)
62
63     @no_debug_info_test
64     def test_continue(self):
65         """Test that continue stops at the second breakpoint."""
66         self.prepare_test()
67
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)
73         self.assertIsNotNone(
74             self.thread,
75             "Expected one thread to be stopped at breakpoint 2")
76
77         self.finish_test()
78
79     @no_debug_info_test
80     def test_single_step(self):
81         """Test that single step stops at the second breakpoint."""
82         self.prepare_test()
83
84         step_over = False
85         self.thread.StepInstruction(step_over)
86
87         self.assertEquals(self.process.GetState(), lldb.eStateStopped)
88         self.assertEquals(
89             self.thread.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress(
90                 self.target), self.bkpt_address.GetLoadAddress(
91                 self.target))
92         self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(
93             self.process, self.breakpoint2)
94         self.assertIsNotNone(
95             self.thread,
96             "Expected one thread to be stopped at breakpoint 2")
97
98         self.finish_test()
99
100     @no_debug_info_test
101     def test_single_step_thread_specific(self):
102         """Test that single step stops, even though the second breakpoint is not valid."""
103         self.prepare_test()
104
105         # Choose a thread other than the current one. A non-existing thread is
106         # fine.
107         thread_index = self.process.GetNumThreads() + 1
108         self.assertFalse(self.process.GetThreadAtIndex(thread_index).IsValid())
109         self.breakpoint2.SetThreadIndex(thread_index)
110
111         step_over = False
112         self.thread.StepInstruction(step_over)
113
114         self.assertEquals(self.process.GetState(), lldb.eStateStopped)
115         self.assertEquals(
116             self.thread.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress(
117                 self.target), self.bkpt_address.GetLoadAddress(
118                 self.target))
119         self.assertEquals(
120             self.thread.GetStopReason(),
121             lldb.eStopReasonPlanComplete,
122             "Stop reason should be 'plan complete'")
123
124         self.finish_test()