2 Test breakpoint commands for a breakpoint ID with multiple locations.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class BreakpointLocationsTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
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."""
24 self.breakpoint_locations_test()
26 def test_shadowed_cond_options(self):
27 """Test that options set on the breakpoint and location behave correctly."""
29 self.shadowed_bkpt_cond_test()
32 def test_shadowed_command_options(self):
33 """Test that options set on the breakpoint and location behave correctly."""
35 self.shadowed_bkpt_command_test()
38 # Call super's setUp().
40 # Find the line number to break inside main().
41 self.line = line_number('main.c', '// Set break point at this line.')
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))
48 # This should create a breakpoint with 3 locations.
50 bkpt = target.BreakpointCreateByLocation("main.c", self.line)
52 # The breakpoint list should show 3 locations.
53 self.assertEqual(bkpt.GetNumLocations(), 3, "Wrong number of locations")
57 "Breakpoint locations shown correctly",
59 "1: file = 'main.c', line = %d, exact_match = 0, locations = 3" %
62 "where = a.out`func_inlined .+unresolved, hit count = 0",
63 "where = a.out`main .+\[inlined\].+unresolved, hit count = 0"])
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.
74 bkpt = self.set_breakpoint()
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")
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")
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.")
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")
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.
105 bkpt = self.set_breakpoint()
106 commands = ["AAAAAA", "BBBBBB", "CCCCCC"]
107 str_list = lldb.SBStringList()
108 str_list.AppendList(commands, len(commands))
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.")
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)
125 loc_list_size = loc_list.GetSize()
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.")
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.")
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")
142 def breakpoint_locations_test(self):
143 """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
144 self.set_breakpoint()
146 # The 'breakpoint disable 3.*' command should fail gracefully.
147 self.expect("breakpoint disable 3.*",
148 "Disabling an invalid breakpoint should fail gracefully",
150 startstr="error: '3' is not a valid breakpoint ID.")
152 # The 'breakpoint disable 1.*' command should disable all 3 locations.
154 "breakpoint disable 1.*",
155 "All 3 breakpoint locatons disabled correctly",
156 startstr="3 breakpoints disabled.")
159 self.runCmd("run", RUN_SUCCEEDED)
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"])
165 # The 'breakpoint enable 1.*' command should enable all 3 breakpoints.
167 "breakpoint enable 1.*",
168 "All 3 breakpoint locatons enabled correctly",
169 startstr="3 breakpoints enabled.")
171 # The 'breakpoint disable 1.1' command should disable 1 location.
173 "breakpoint disable 1.1",
174 "1 breakpoint locatons disabled correctly",
175 startstr="1 breakpoints disabled.")
177 # Run the program again. We should stop on the two breakpoint
179 self.runCmd("run", RUN_SUCCEEDED)
182 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
183 substrs=["stop reason = breakpoint 1."])
185 # Continue the program, there should be another stop.
186 self.runCmd("process continue")
189 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
190 substrs=["stop reason = breakpoint 1."])
192 # At this point, 1.1 has a hit count of 0 and the other a hit count of
195 "breakpoint list -f",
196 "The breakpoints should report correct hit counts",
198 "1\.1: .+ unresolved, hit count = 0 +Options: disabled",
199 "1\.2: .+ resolved, hit count = 1",
200 "1\.3: .+ resolved, hit count = 1"])