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