blob: 49c72dbf0911526c0bc6b2e42a0c0b2cd5e60531 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ThreadPlanStepRange.cpp ---------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +00009#include "lldb/Target/ThreadPlanStepRange.h"
Jim Ingham0c61dee2013-03-13 01:56:41 +000010#include "lldb/Breakpoint/BreakpointLocation.h"
11#include "lldb/Breakpoint/BreakpointSite.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000012#include "lldb/Core/Disassembler.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Symbol/Function.h"
14#include "lldb/Symbol/Symbol.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000015#include "lldb/Target/ExecutionContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000016#include "lldb/Target/Process.h"
17#include "lldb/Target/RegisterContext.h"
18#include "lldb/Target/StopInfo.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000019#include "lldb/Target/Target.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000020#include "lldb/Target/Thread.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000021#include "lldb/Target/ThreadPlanRunToAddress.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000022#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000023#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
25using namespace lldb;
26using namespace lldb_private;
27
Adrian Prantl05097242018-04-30 16:49:04 +000028// ThreadPlanStepRange: Step through a stack range, either stepping over or
29// into based on the value of \a type.
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
Kate Stoneb9c1b512016-09-06 20:57:50 +000031ThreadPlanStepRange::ThreadPlanStepRange(ThreadPlanKind kind, const char *name,
32 Thread &thread,
33 const AddressRange &range,
34 const SymbolContext &addr_context,
35 lldb::RunMode stop_others,
36 bool given_ranges_only)
37 : ThreadPlan(kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
38 m_addr_context(addr_context), m_address_ranges(),
39 m_stop_others(stop_others), m_stack_id(), m_parent_stack_id(),
40 m_no_more_plans(false), m_first_run_event(true), m_use_fast_step(false),
41 m_given_ranges_only(given_ranges_only) {
42 m_use_fast_step = GetTarget().GetUseFastStepping();
43 AddRange(range);
44 m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
45 StackFrameSP parent_stack = m_thread.GetStackFrameAtIndex(1);
46 if (parent_stack)
47 m_parent_stack_id = parent_stack->GetStackID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048}
49
Kate Stoneb9c1b512016-09-06 20:57:50 +000050ThreadPlanStepRange::~ThreadPlanStepRange() { ClearNextBranchBreakpoint(); }
51
52void ThreadPlanStepRange::DidPush() {
53 // See if we can find a "next range" breakpoint:
54 SetNextBranchBreakpoint();
Jim Ingham564d8bc22012-03-09 04:10:47 +000055}
56
Jonas Devliegheree103ae92018-11-15 01:18:15 +000057bool ThreadPlanStepRange::ValidatePlan(Stream *error) {
58 if (m_could_not_resolve_hw_bp) {
59 if (error)
60 error->PutCString(
61 "Could not create hardware breakpoint for thread plan.");
62 return false;
63 }
64 return true;
65}
Kate Stoneb9c1b512016-09-06 20:57:50 +000066
67Vote ThreadPlanStepRange::ShouldReportStop(Event *event_ptr) {
68 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
69
70 const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
71 if (log)
72 log->Printf("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n",
73 vote);
74 return vote;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077void ThreadPlanStepRange::AddRange(const AddressRange &new_range) {
Adrian Prantl05097242018-04-30 16:49:04 +000078 // For now I'm just adding the ranges. At some point we may want to condense
79 // the ranges if they overlap, though I don't think it is likely to be very
80 // important.
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 m_address_ranges.push_back(new_range);
82
83 // Fill the slot for this address range with an empty DisassemblerSP in the
Adrian Prantl05097242018-04-30 16:49:04 +000084 // instruction ranges. I want the indices to match, but I don't want to do
85 // the work to disassemble this range if I don't step into it.
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 m_instruction_ranges.push_back(DisassemblerSP());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089void ThreadPlanStepRange::DumpRanges(Stream *s) {
90 size_t num_ranges = m_address_ranges.size();
91 if (num_ranges == 1) {
92 m_address_ranges[0].Dump(s, m_thread.CalculateTarget().get(),
93 Address::DumpStyleLoadAddress);
94 } else {
95 for (size_t i = 0; i < num_ranges; i++) {
96 s->Printf(" %" PRIu64 ": ", uint64_t(i));
97 m_address_ranges[i].Dump(s, m_thread.CalculateTarget().get(),
98 Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +000099 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 }
101}
102
103bool ThreadPlanStepRange::InRange() {
104 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
105 bool ret_value = false;
106
107 lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
108
109 size_t num_ranges = m_address_ranges.size();
110 for (size_t i = 0; i < num_ranges; i++) {
111 ret_value = m_address_ranges[i].ContainsLoadAddress(
112 pc_load_addr, m_thread.CalculateTarget().get());
113 if (ret_value)
114 break;
115 }
116
117 if (!ret_value && !m_given_ranges_only) {
118 // See if we've just stepped to another part of the same line number...
119 StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
120
121 SymbolContext new_context(
122 frame->GetSymbolContext(eSymbolContextEverything));
123 if (m_addr_context.line_entry.IsValid() &&
124 new_context.line_entry.IsValid()) {
125 if (m_addr_context.line_entry.original_file ==
126 new_context.line_entry.original_file) {
127 if (m_addr_context.line_entry.line == new_context.line_entry.line) {
128 m_addr_context = new_context;
Greg Clayton8a777922019-05-06 20:01:21 +0000129 const bool include_inlined_functions =
130 GetKind() == eKindStepOverRange;
131 AddRange(m_addr_context.line_entry.GetSameLineContiguousAddressRange(
132 include_inlined_functions));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 ret_value = true;
134 if (log) {
135 StreamString s;
136 m_addr_context.line_entry.Dump(&s, m_thread.CalculateTarget().get(),
137 true, Address::DumpStyleLoadAddress,
138 Address::DumpStyleLoadAddress, true);
139
140 log->Printf(
141 "Step range plan stepped to another range of same line: %s",
142 s.GetData());
143 }
144 } else if (new_context.line_entry.line == 0) {
145 new_context.line_entry.line = m_addr_context.line_entry.line;
146 m_addr_context = new_context;
Greg Clayton8a777922019-05-06 20:01:21 +0000147 const bool include_inlined_functions =
148 GetKind() == eKindStepOverRange;
149 AddRange(m_addr_context.line_entry.GetSameLineContiguousAddressRange(
150 include_inlined_functions));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 ret_value = true;
152 if (log) {
153 StreamString s;
154 m_addr_context.line_entry.Dump(&s, m_thread.CalculateTarget().get(),
155 true, Address::DumpStyleLoadAddress,
156 Address::DumpStyleLoadAddress, true);
157
158 log->Printf("Step range plan stepped to a range at linenumber 0 "
159 "stepping through that range: %s",
160 s.GetData());
161 }
162 } else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(
163 m_thread.CalculateTarget().get()) != pc_load_addr) {
164 // Another thing that sometimes happens here is that we step out of
Adrian Prantl05097242018-04-30 16:49:04 +0000165 // one line into the MIDDLE of another line. So far I mostly see
166 // this due to bugs in the debug information. But we probably don't
167 // want to be in the middle of a line range, so in that case reset
168 // the stepping range to the line we've stepped into the middle of
169 // and continue.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000170 m_addr_context = new_context;
171 m_address_ranges.clear();
172 AddRange(m_addr_context.line_entry.range);
173 ret_value = true;
174 if (log) {
175 StreamString s;
176 m_addr_context.line_entry.Dump(&s, m_thread.CalculateTarget().get(),
177 true, Address::DumpStyleLoadAddress,
178 Address::DumpStyleLoadAddress, true);
179
180 log->Printf("Step range plan stepped to the middle of new "
181 "line(%d): %s, continuing to clear this line.",
182 new_context.line_entry.line, s.GetData());
183 }
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000184 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000185 }
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000186 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000187 }
188
189 if (!ret_value && log)
190 log->Printf("Step range plan out of range to 0x%" PRIx64, pc_load_addr);
191
192 return ret_value;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000193}
194
Kate Stoneb9c1b512016-09-06 20:57:50 +0000195bool ThreadPlanStepRange::InSymbol() {
196 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
197 if (m_addr_context.function != nullptr) {
198 return m_addr_context.function->GetAddressRange().ContainsLoadAddress(
199 cur_pc, m_thread.CalculateTarget().get());
200 } else if (m_addr_context.symbol && m_addr_context.symbol->ValueIsAddress()) {
201 AddressRange range(m_addr_context.symbol->GetAddressRef(),
202 m_addr_context.symbol->GetByteSize());
203 return range.ContainsLoadAddress(cur_pc, m_thread.CalculateTarget().get());
204 }
205 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206}
207
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208// FIXME: This should also handle inlining if we aren't going to do inlining in
209// the
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000210// main stack.
211//
212// Ideally we should remember the whole stack frame list, and then compare that
213// to the current list.
214
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215lldb::FrameComparison ThreadPlanStepRange::CompareCurrentFrameToStartFrame() {
216 FrameComparison frame_order;
217
218 StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
219
220 if (cur_frame_id == m_stack_id) {
221 frame_order = eFrameCompareEqual;
222 } else if (cur_frame_id < m_stack_id) {
223 frame_order = eFrameCompareYounger;
224 } else {
225 StackFrameSP cur_parent_frame = m_thread.GetStackFrameAtIndex(1);
226 StackID cur_parent_id;
227 if (cur_parent_frame)
228 cur_parent_id = cur_parent_frame->GetStackID();
229 if (m_parent_stack_id.IsValid() && cur_parent_id.IsValid() &&
230 m_parent_stack_id == cur_parent_id)
231 frame_order = eFrameCompareSameParent;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000233 frame_order = eFrameCompareOlder;
234 }
235 return frame_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000236}
237
Kate Stoneb9c1b512016-09-06 20:57:50 +0000238bool ThreadPlanStepRange::StopOthers() {
239 return (m_stop_others == lldb::eOnlyThisThread ||
240 m_stop_others == lldb::eOnlyDuringStepping);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241}
242
Kate Stoneb9c1b512016-09-06 20:57:50 +0000243InstructionList *ThreadPlanStepRange::GetInstructionsForAddress(
244 lldb::addr_t addr, size_t &range_index, size_t &insn_offset) {
245 size_t num_ranges = m_address_ranges.size();
246 for (size_t i = 0; i < num_ranges; i++) {
247 if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget())) {
248 // Some joker added a zero size range to the stepping range...
249 if (m_address_ranges[i].GetByteSize() == 0)
250 return nullptr;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000251
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252 if (!m_instruction_ranges[i]) {
253 // Disassemble the address range given:
254 ExecutionContext exe_ctx(m_thread.GetProcess());
255 const char *plugin_name = nullptr;
256 const char *flavor = nullptr;
257 const bool prefer_file_cache = true;
258 m_instruction_ranges[i] = Disassembler::DisassembleRange(
259 GetTarget().GetArchitecture(), plugin_name, flavor, exe_ctx,
260 m_address_ranges[i], prefer_file_cache);
261 }
262 if (!m_instruction_ranges[i])
263 return nullptr;
264 else {
265 // Find where we are in the instruction list as well. If we aren't at
Adrian Prantl05097242018-04-30 16:49:04 +0000266 // an instruction, return nullptr. In this case, we're probably lost,
267 // and shouldn't try to do anything fancy.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000268
269 insn_offset =
270 m_instruction_ranges[i]
271 ->GetInstructionList()
272 .GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
273 if (insn_offset == UINT32_MAX)
274 return nullptr;
275 else {
276 range_index = i;
277 return &m_instruction_ranges[i]->GetInstructionList();
Jim Ingham564d8bc22012-03-09 04:10:47 +0000278 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000279 }
Jim Ingham564d8bc22012-03-09 04:10:47 +0000280 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000281 }
282 return nullptr;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000283}
284
Kate Stoneb9c1b512016-09-06 20:57:50 +0000285void ThreadPlanStepRange::ClearNextBranchBreakpoint() {
286 if (m_next_branch_bp_sp) {
287 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
288 if (log)
289 log->Printf("Removing next branch breakpoint: %d.",
290 m_next_branch_bp_sp->GetID());
291 GetTarget().RemoveBreakpointByID(m_next_branch_bp_sp->GetID());
292 m_next_branch_bp_sp.reset();
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000293 m_could_not_resolve_hw_bp = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294 }
Jim Ingham564d8bc22012-03-09 04:10:47 +0000295}
296
Kate Stoneb9c1b512016-09-06 20:57:50 +0000297bool ThreadPlanStepRange::SetNextBranchBreakpoint() {
298 if (m_next_branch_bp_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300
Kate Stoneb9c1b512016-09-06 20:57:50 +0000301 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
302 // Stepping through ranges using breakpoints doesn't work yet, but with this
Adrian Prantl05097242018-04-30 16:49:04 +0000303 // off we fall back to instruction single stepping.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000304 if (!m_use_fast_step)
Jim Ingham64e7ead2012-05-03 21:19:36 +0000305 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000306
307 lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
308 // Find the current address in our address ranges, and fetch the disassembly
309 // if we haven't already:
310 size_t pc_index;
311 size_t range_index;
312 InstructionList *instructions =
313 GetInstructionsForAddress(cur_addr, range_index, pc_index);
314 if (instructions == nullptr)
315 return false;
316 else {
317 Target &target = GetThread().GetProcess()->GetTarget();
Greg Claytondf225762019-05-09 20:39:34 +0000318 const bool ignore_calls = GetKind() == eKindStepOverRange;
319 uint32_t branch_index =
320 instructions->GetIndexOfNextBranchInstruction(pc_index, target,
321 ignore_calls);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322
323 Address run_to_address;
324
325 // If we didn't find a branch, run to the end of the range.
326 if (branch_index == UINT32_MAX) {
327 uint32_t last_index = instructions->GetSize() - 1;
328 if (last_index - pc_index > 1) {
329 InstructionSP last_inst =
330 instructions->GetInstructionAtIndex(last_index);
331 size_t last_inst_size = last_inst->GetOpcode().GetByteSize();
332 run_to_address = last_inst->GetAddress();
333 run_to_address.Slide(last_inst_size);
334 }
335 } else if (branch_index - pc_index > 1) {
336 run_to_address =
337 instructions->GetInstructionAtIndex(branch_index)->GetAddress();
338 }
339
340 if (run_to_address.IsValid()) {
341 const bool is_internal = true;
342 m_next_branch_bp_sp =
343 GetTarget().CreateBreakpoint(run_to_address, is_internal, false);
344 if (m_next_branch_bp_sp) {
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000345
346 if (m_next_branch_bp_sp->IsHardware() &&
347 !m_next_branch_bp_sp->HasResolvedLocations())
348 m_could_not_resolve_hw_bp = true;
349
Kate Stoneb9c1b512016-09-06 20:57:50 +0000350 if (log) {
351 lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
352 BreakpointLocationSP bp_loc =
353 m_next_branch_bp_sp->GetLocationAtIndex(0);
354 if (bp_loc) {
355 BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
356 if (bp_site) {
357 bp_site_id = bp_site->GetID();
358 }
359 }
360 log->Printf("ThreadPlanStepRange::SetNextBranchBreakpoint - Setting "
361 "breakpoint %d (site %d) to run to address 0x%" PRIx64,
362 m_next_branch_bp_sp->GetID(), bp_site_id,
363 run_to_address.GetLoadAddress(
364 &m_thread.GetProcess()->GetTarget()));
365 }
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000366
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 m_next_branch_bp_sp->SetThreadID(m_thread.GetID());
368 m_next_branch_bp_sp->SetBreakpointKind("next-branch-location");
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000369
Kate Stoneb9c1b512016-09-06 20:57:50 +0000370 return true;
371 } else
372 return false;
373 }
374 }
375 return false;
376}
377
378bool ThreadPlanStepRange::NextRangeBreakpointExplainsStop(
379 lldb::StopInfoSP stop_info_sp) {
380 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
381 if (!m_next_branch_bp_sp)
382 return false;
383
384 break_id_t bp_site_id = stop_info_sp->GetValue();
385 BreakpointSiteSP bp_site_sp =
386 m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id);
387 if (!bp_site_sp)
388 return false;
389 else if (!bp_site_sp->IsBreakpointAtThisSite(m_next_branch_bp_sp->GetID()))
390 return false;
391 else {
392 // If we've hit the next branch breakpoint, then clear it.
393 size_t num_owners = bp_site_sp->GetNumberOfOwners();
394 bool explains_stop = true;
395 // If all the owners are internal, then we are probably just stepping over
Adrian Prantl05097242018-04-30 16:49:04 +0000396 // this range from multiple threads, or multiple frames, so we want to
397 // continue. If one is not internal, then we should not explain the stop,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000398 // and let the user breakpoint handle the stop.
399 for (size_t i = 0; i < num_owners; i++) {
400 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) {
401 explains_stop = false;
402 break;
403 }
404 }
405 if (log)
406 log->Printf("ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit "
407 "next range breakpoint which has %" PRIu64
408 " owners - explains stop: %u.",
409 (uint64_t)num_owners, explains_stop);
410 ClearNextBranchBreakpoint();
411 return explains_stop;
412 }
413}
414
415bool ThreadPlanStepRange::WillStop() { return true; }
416
417StateType ThreadPlanStepRange::GetPlanRunState() {
418 if (m_next_branch_bp_sp)
419 return eStateRunning;
420 else
421 return eStateStepping;
422}
423
424bool ThreadPlanStepRange::MischiefManaged() {
425 // If we have pushed some plans between ShouldStop & MischiefManaged, then
426 // we're not done...
427 // I do this check first because we might have stepped somewhere that will
428 // fool InRange into
429 // thinking it needs to step past the end of that line. This happens, for
Adrian Prantl05097242018-04-30 16:49:04 +0000430 // instance, when stepping over inlined code that is in the middle of the
431 // current line.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000432
433 if (!m_no_more_plans)
434 return false;
435
436 bool done = true;
437 if (!IsPlanComplete()) {
438 if (InRange()) {
439 done = false;
440 } else {
441 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
442 done = (frame_order != eFrameCompareOlder) ? m_no_more_plans : true;
443 }
444 }
445
446 if (done) {
447 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
448 if (log)
449 log->Printf("Completed step through range plan.");
450 ClearNextBranchBreakpoint();
451 ThreadPlan::MischiefManaged();
452 return true;
453 } else {
454 return false;
455 }
456}
457
458bool ThreadPlanStepRange::IsPlanStale() {
459 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
460 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
461
462 if (frame_order == eFrameCompareOlder) {
463 if (log) {
464 log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've "
465 "stepped out.");
466 }
467 return true;
468 } else if (frame_order == eFrameCompareEqual && InSymbol()) {
Adrian Prantl05097242018-04-30 16:49:04 +0000469 // If we are not in a place we should step through, we've gotten stale. One
470 // tricky bit here is that some stubs don't push a frame, so we should.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000471 // check that we are in the same symbol.
472 if (!InRange()) {
Boris Ulasevich86aaa8a2017-02-15 11:42:47 +0000473 // Set plan Complete when we reach next instruction just after the range
474 lldb::addr_t addr = m_thread.GetRegisterContext()->GetPC() - 1;
475 size_t num_ranges = m_address_ranges.size();
476 for (size_t i = 0; i < num_ranges; i++) {
477 bool in_range = m_address_ranges[i].ContainsLoadAddress(
478 addr, m_thread.CalculateTarget().get());
479 if (in_range) {
480 SetPlanComplete();
481 }
482 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000483 return true;
484 }
485 }
486 return false;
Jim Ingham64e7ead2012-05-03 21:19:36 +0000487}