Skip to content

Commit aa4b37b

Browse files
committed
Convert the ThreadPlanCommands test to use a scripted plan
that pushes a step over plan. Relax the listing checker so it will look past any entries after the ones listed in the input patterns. Then for the internal plans just check for the StepOver plan that our scripted plan pushes, and look past any others. This should make the test more robust on systems that don't use the step-in then push a step-out plan to step over a function.
1 parent f7de4b5 commit aa4b37b

File tree

2 files changed

+52
-29
lines changed

2 files changed

+52
-29
lines changed

lldb/test/API/functionalities/thread_plan/TestThreadPlanCommands.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,74 +46,75 @@ def check_list_output(self, command, active_plans = [], completed_plans = [], di
4646
self.assertTrue(result.Succeeded(), "command: '%s' failed: '%s'"%(command, result.GetError()))
4747
result_arr = result.GetOutput().splitlines()
4848
num_results = len(result_arr)
49-
50-
# Match the expected number of elements.
51-
# Adjust the count for the number of header lines we aren't matching:
52-
fudge = 0
5349

54-
if num_completed == 0 and num_discarded == 0:
55-
# The fudge is 3: Thread header, Active Plan header and base plan
56-
fudge = 3
57-
elif num_completed == 0 or num_discarded == 0:
58-
# The fudge is 4: The above plus either the Completed or Discarded Plan header:
59-
fudge = 4
60-
else:
61-
# The fudge is 5 since we have both headers:
62-
fudge = 5
63-
64-
self.assertEqual(num_results, num_active + num_completed + num_discarded + fudge,
65-
"Too many elements in match arrays for: \n%s\n"%result.GetOutput())
66-
6750
# Now iterate through the results array and pick out the results.
6851
result_idx = 0
6952
self.assertIn("thread #", result_arr[result_idx], "Found thread header") ; result_idx += 1
7053
self.assertIn("Active plan stack", result_arr[result_idx], "Found active header") ; result_idx += 1
7154
self.assertIn("Element 0: Base thread plan", result_arr[result_idx], "Found base plan") ; result_idx += 1
7255

7356
for text in active_plans:
74-
self.assertFalse("Completed plan stack" in result_arr[result_idx], "Found Completed header too early.")
7557
self.assertIn(text, result_arr[result_idx], "Didn't find active plan: %s"%(text)) ; result_idx += 1
58+
7659

7760
if len(completed_plans) > 0:
78-
self.assertIn("Completed plan stack:", result_arr[result_idx], "Found completed plan stack header") ; result_idx += 1
61+
# First consume any remaining active plans:
62+
while not "Completed plan stack:" in result_arr[result_idx]:
63+
result_idx += 1
64+
if result_idx == num_results:
65+
self.fail("There should have been completed plans, but I never saw the completed stack header")
66+
# We are at the Completed header, skip it:
67+
result_idx += 1
7968
for text in completed_plans:
8069
self.assertIn(text, result_arr[result_idx], "Didn't find completed plan: %s"%(text)) ; result_idx += 1
8170

8271
if len(discarded_plans) > 0:
83-
self.assertIn("Discarded plan stack:", result_arr[result_idx], "Found discarded plan stack header") ; result_idx += 1
72+
# First consume any remaining completed plans:
73+
while not "Discarded plan stack:" in result_arr[result_idx]:
74+
result_idx += 1
75+
if result_idx == num_results:
76+
self.fail("There should have been discarded plans, but I never saw the discarded stack header")
77+
78+
# We are at the Discarded header, skip it:
79+
result_idx += 1
8480
for text in discarded_plans:
85-
self.assertIn(text, result_arr[result_idx], "Didn't find completed plan: %s"%(text)) ; result_idx += 1
81+
self.assertIn(text, result_arr[result_idx], "Didn't find discarded plan: %s"%(text)) ; result_idx += 1
8682

8783

8884
def thread_plan_test(self):
8985
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
9086
"Set a breakpoint here", self.main_source_file)
9187

92-
# Now set a breakpoint in call_me and step over. We should have
93-
# two public thread plans
88+
# We need to have an internal plan so we can test listing one.
89+
# The most consistent way to do that is to use a scripted thread plan
90+
# that uses a sub-plan. Source that in now.
91+
source_path = os.path.join(self.getSourceDir(), "wrap_step_over.py")
92+
self.runCmd("command script import '%s'"%(source_path))
93+
94+
# Now set a breakpoint that we will hit by running our scripted step.
9495
call_me_bkpt = target.BreakpointCreateBySourceRegex("Set another here", self.main_source_file)
9596
self.assertTrue(call_me_bkpt.GetNumLocations() > 0, "Set the breakpoint successfully")
96-
thread.StepOver()
97+
thread.StepUsingScriptedThreadPlan("wrap_step_over.WrapStepOver")
9798
threads = lldbutil.get_threads_stopped_at_breakpoint(process, call_me_bkpt)
9899
self.assertEqual(len(threads), 1, "Hit my breakpoint while stepping over")
99100

100101
current_id = threads[0].GetIndexID()
101102
current_tid = threads[0].GetThreadID()
102103
# Run thread plan list without the -i flag:
103104
command = "thread plan list %d"%(current_id)
104-
self.check_list_output (command, ["Stepping over line main.c"], [])
105+
self.check_list_output (command, ["wrap_step_over.WrapStepOver"], [])
105106

106107
# Run thread plan list with the -i flag:
107108
command = "thread plan list -i %d"%(current_id)
108-
self.check_list_output(command, ["Stepping over line main.c", "Stepping out from"])
109+
self.check_list_output(command, ["WrapStepOver", "Stepping over line main.c"])
109110

110111
# Run thread plan list providing TID, output should be the same:
111112
command = "thread plan list -t %d"%(current_tid)
112-
self.check_list_output(command, ["Stepping over line main.c"])
113+
self.check_list_output(command, ["wrap_step_over.WrapStepOver"])
113114

114115
# Provide both index & tid, and make sure we only print once:
115116
command = "thread plan list -t %d %d"%(current_tid, current_id)
116-
self.check_list_output(command, ["Stepping over line main.c"])
117+
self.check_list_output(command, ["wrap_step_over.WrapStepOver"])
117118

118119
# Try a fake TID, and make sure that fails:
119120
fake_tid = 0
@@ -133,7 +134,7 @@ def thread_plan_test(self):
133134

134135
# Run thread plan list - there aren't any private plans at this point:
135136
command = "thread plan list %d"%(current_id)
136-
self.check_list_output(command, [], ["Stepping over line main.c"])
137+
self.check_list_output(command, [], ["wrap_step_over.WrapStepOver"])
137138

138139
# Set another breakpoint that we can run to, to try deleting thread plans.
139140
second_step_bkpt = target.BreakpointCreateBySourceRegex("Run here to step over again",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import lldb
2+
3+
class WrapStepOver():
4+
def __init__(self, thread_plan, args_data, dict):
5+
self.plan = thread_plan
6+
frame_0 = thread_plan.GetThread().frames[0]
7+
line_entry = frame_0.line_entry
8+
start_addr = line_entry.addr
9+
end_addr = line_entry.end_addr
10+
range_size = int(end_addr) - int(start_addr)
11+
error = lldb.SBError()
12+
self.sub_plan = thread_plan.QueueThreadPlanForStepOverRange(start_addr, range_size)
13+
14+
def should_step(self):
15+
return False
16+
17+
def should_stop(self, event):
18+
if self.sub_plan.IsPlanComplete():
19+
self.plan.SetPlanComplete(True)
20+
return True
21+
else:
22+
return False

0 commit comments

Comments
 (0)