]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
Vendor import of lldb trunk r338536:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / breakpoint / breakpoint_locations / TestBreakpointLocations.py
1 """
2 Test breakpoint commands for a breakpoint ID with multiple locations.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class BreakpointLocationsTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
21     def test_enable(self):
22         """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
23         self.build()
24         self.breakpoint_locations_test()
25
26     def test_shadowed_cond_options(self):
27         """Test that options set on the breakpoint and location behave correctly."""
28         self.build()
29         self.shadowed_bkpt_cond_test()
30
31
32     def test_shadowed_command_options(self):
33         """Test that options set on the breakpoint and location behave correctly."""
34         self.build()
35         self.shadowed_bkpt_command_test()
36
37     def setUp(self):
38         # Call super's setUp().
39         TestBase.setUp(self)
40         # Find the line number to break inside main().
41         self.line = line_number('main.c', '// Set break point at this line.')
42
43     def set_breakpoint (self):
44         exe = self.getBuildArtifact("a.out")
45         target = self.dbg.CreateTarget(exe)
46         self.assertTrue(target, "Target %s is not valid"%(exe))
47
48         # This should create a breakpoint with 3 locations.
49
50         bkpt = target.BreakpointCreateByLocation("main.c", self.line)
51
52         # The breakpoint list should show 3 locations.
53         self.assertEqual(bkpt.GetNumLocations(), 3, "Wrong number of locations")
54
55         self.expect(
56             "breakpoint list -f",
57             "Breakpoint locations shown correctly",
58             substrs=[
59                 "1: file = 'main.c', line = %d, exact_match = 0, locations = 3" %
60                 self.line],
61             patterns=[
62                 "where = a.out`func_inlined .+unresolved, hit count = 0",
63                 "where = a.out`main .+\[inlined\].+unresolved, hit count = 0"])
64
65         return bkpt
66
67     def shadowed_bkpt_cond_test(self):
68         """Test that options set on the breakpoint and location behave correctly."""
69         # Breakpoint option propagation from bkpt to loc used to be done the first time
70         # a breakpoint location option was specifically set.  After that the other options
71         # on that location would stop tracking the breakpoint.  That got fixed, and this test
72         # makes sure only the option touched is affected.
73
74         bkpt = self.set_breakpoint()
75         bkpt_cond = "1 == 0"
76         bkpt.SetCondition(bkpt_cond)
77         self.assertEqual(bkpt.GetCondition(), bkpt_cond,"Successfully set condition")
78         self.assertTrue(bkpt.location[0].GetCondition() == bkpt.GetCondition(), "Conditions are the same")
79
80         # Now set a condition on the locations, make sure that this doesn't effect the bkpt:
81         bkpt_loc_1_cond = "1 == 1"
82         bkpt.location[0].SetCondition(bkpt_loc_1_cond)
83         self.assertEqual(bkpt.location[0].GetCondition(), bkpt_loc_1_cond, "Successfully changed location condition")
84         self.assertNotEqual(bkpt.GetCondition(), bkpt_loc_1_cond, "Changed location changed Breakpoint condition")
85         self.assertEqual(bkpt.location[1].GetCondition(), bkpt_cond, "Changed another location's condition")
86
87         # Now make sure that setting one options doesn't fix the value of another:
88         bkpt.SetIgnoreCount(10)
89         self.assertEqual(bkpt.GetIgnoreCount(), 10, "Set the ignore count successfully")
90         self.assertEqual(bkpt.location[0].GetIgnoreCount(), 10, "Location doesn't track top-level bkpt.")
91
92         # Now make sure resetting the condition to "" resets the tracking:
93         bkpt.location[0].SetCondition("")
94         bkpt_new_cond = "1 == 3"
95         bkpt.SetCondition(bkpt_new_cond)
96         self.assertEqual(bkpt.location[0].GetCondition(), bkpt_new_cond, "Didn't go back to tracking condition")
97
98     def shadowed_bkpt_command_test(self):
99         """Test that options set on the breakpoint and location behave correctly."""
100         # Breakpoint option propagation from bkpt to loc used to be done the first time
101         # a breakpoint location option was specifically set.  After that the other options
102         # on that location would stop tracking the breakpoint.  That got fixed, and this test
103         # makes sure only the option touched is affected.
104
105         bkpt = self.set_breakpoint()
106         commands = ["AAAAAA", "BBBBBB", "CCCCCC"]
107         str_list = lldb.SBStringList()
108         str_list.AppendList(commands, len(commands))
109
110         bkpt.SetCommandLineCommands(str_list)
111         cmd_list = lldb.SBStringList()
112         bkpt.GetCommandLineCommands(cmd_list)
113         list_size = str_list.GetSize()
114         self.assertEqual(cmd_list.GetSize() , list_size, "Added the right number of commands")
115         for i in range(0,list_size):
116             self.assertEqual(str_list.GetStringAtIndex(i), cmd_list.GetStringAtIndex(i), "Mismatched commands.")
117
118         commands = ["DDDDDD", "EEEEEE", "FFFFFF", "GGGGGG"]
119         loc_list = lldb.SBStringList()
120         loc_list.AppendList(commands, len(commands))
121         bkpt.location[1].SetCommandLineCommands(loc_list)
122         loc_cmd_list = lldb.SBStringList()
123         bkpt.location[1].GetCommandLineCommands(loc_cmd_list)
124
125         loc_list_size = loc_list.GetSize()
126
127         # Check that the location has the right commands:
128         self.assertEqual(loc_cmd_list.GetSize() , loc_list_size, "Added the right number of commands to location")
129         for i in range(0,loc_list_size):
130             self.assertEqual(loc_list.GetStringAtIndex(i), loc_cmd_list.GetStringAtIndex(i), "Mismatched commands.")
131
132         # Check that we didn't mess up the breakpoint level commands:
133         self.assertEqual(cmd_list.GetSize() , list_size, "Added the right number of commands")
134         for i in range(0,list_size):
135             self.assertEqual(str_list.GetStringAtIndex(i), cmd_list.GetStringAtIndex(i), "Mismatched commands.")
136
137         # And check we didn't mess up another location:
138         untouched_loc_cmds = lldb.SBStringList()
139         bkpt.location[0].GetCommandLineCommands(untouched_loc_cmds)
140         self.assertEqual(untouched_loc_cmds.GetSize() , 0, "Changed the wrong location")
141
142     def breakpoint_locations_test(self):
143         """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
144         self.set_breakpoint()
145
146         # The 'breakpoint disable 3.*' command should fail gracefully.
147         self.expect("breakpoint disable 3.*",
148                     "Disabling an invalid breakpoint should fail gracefully",
149                     error=True,
150                     startstr="error: '3' is not a valid breakpoint ID.")
151
152         # The 'breakpoint disable 1.*' command should disable all 3 locations.
153         self.expect(
154             "breakpoint disable 1.*",
155             "All 3 breakpoint locatons disabled correctly",
156             startstr="3 breakpoints disabled.")
157
158         # Run the program.
159         self.runCmd("run", RUN_SUCCEEDED)
160
161         # We should not stopped on any breakpoint at all.
162         self.expect("process status", "No stopping on any disabled breakpoint",
163                     patterns=["^Process [0-9]+ exited with status = 0"])
164
165         # The 'breakpoint enable 1.*' command should enable all 3 breakpoints.
166         self.expect(
167             "breakpoint enable 1.*",
168             "All 3 breakpoint locatons enabled correctly",
169             startstr="3 breakpoints enabled.")
170
171         # The 'breakpoint disable 1.1' command should disable 1 location.
172         self.expect(
173             "breakpoint disable 1.1",
174             "1 breakpoint locatons disabled correctly",
175             startstr="1 breakpoints disabled.")
176
177         # Run the program again.  We should stop on the two breakpoint
178         # locations.
179         self.runCmd("run", RUN_SUCCEEDED)
180
181         # Stopped once.
182         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
183                     substrs=["stop reason = breakpoint 1."])
184
185         # Continue the program, there should be another stop.
186         self.runCmd("process continue")
187
188         # Stopped again.
189         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
190                     substrs=["stop reason = breakpoint 1."])
191
192         # At this point, 1.1 has a hit count of 0 and the other a hit count of
193         # 1".
194         self.expect(
195             "breakpoint list -f",
196             "The breakpoints should report correct hit counts",
197             patterns=[
198                 "1\.1: .+ unresolved, hit count = 0 +Options: disabled",
199                 "1\.2: .+ resolved, hit count = 1",
200                 "1\.3: .+ resolved, hit count = 1"])