blob: 510a62740de3edf2f4ffe0a3a80c5406c653e682 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ThreadPlanStepRange.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/ThreadPlanStepRange.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17#include "lldb/lldb-private-log.h"
Jim Ingham0c61dee2013-03-13 01:56:41 +000018#include "lldb/Breakpoint/BreakpointLocation.h"
19#include "lldb/Breakpoint/BreakpointSite.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000020#include "lldb/Core/Disassembler.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/Log.h"
22#include "lldb/Core/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Symbol/Function.h"
24#include "lldb/Symbol/Symbol.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000025#include "lldb/Target/ExecutionContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000026#include "lldb/Target/Process.h"
27#include "lldb/Target/RegisterContext.h"
28#include "lldb/Target/StopInfo.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000029#include "lldb/Target/Target.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000030#include "lldb/Target/Thread.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000031#include "lldb/Target/ThreadPlanRunToAddress.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
33using namespace lldb;
34using namespace lldb_private;
35
36
37//----------------------------------------------------------------------
38// ThreadPlanStepRange: Step through a stack range, either stepping over or into
39// based on the value of \a type.
40//----------------------------------------------------------------------
41
Jim Ingham242e0ad2011-02-08 04:27:50 +000042ThreadPlanStepRange::ThreadPlanStepRange (ThreadPlanKind kind,
43 const char *name,
44 Thread &thread,
45 const AddressRange &range,
46 const SymbolContext &addr_context,
47 lldb::RunMode stop_others) :
Jim Ingham35b21fe2010-07-10 02:23:31 +000048 ThreadPlan (kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049 m_addr_context (addr_context),
Jim Inghamc4c9fed2011-10-15 00:24:48 +000050 m_address_ranges (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051 m_stop_others (stop_others),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052 m_stack_id (),
Greg Claytonc982c762010-07-09 20:39:50 +000053 m_no_more_plans (false),
Jim Ingham0c61dee2013-03-13 01:56:41 +000054 m_first_run_event (true),
55 m_use_fast_step(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056{
Jason Molenda975abff2013-08-01 21:50:20 +000057 m_use_fast_step = GetTarget().GetUseFastStepping();
Jim Inghamc4c9fed2011-10-15 00:24:48 +000058 AddRange(range);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059 m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
60}
61
62ThreadPlanStepRange::~ThreadPlanStepRange ()
63{
Jim Ingham564d8bc22012-03-09 04:10:47 +000064 ClearNextBranchBreakpoint();
Jim Ingham56d40422013-07-31 02:19:15 +000065
66 size_t num_instruction_ranges = m_instruction_ranges.size();
67
68 // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
69 // I'll fix that but for now, just clear the list and it will go away nicely.
70 for (size_t i = 0; i < num_instruction_ranges; i++)
71 {
72 if (m_instruction_ranges[i])
73 m_instruction_ranges[i]->GetInstructionList().Clear();
74 }
Jim Ingham564d8bc22012-03-09 04:10:47 +000075}
76
77void
78ThreadPlanStepRange::DidPush ()
79{
80 // See if we can find a "next range" breakpoint:
81 SetNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082}
83
84bool
85ThreadPlanStepRange::ValidatePlan (Stream *error)
86{
87 return true;
88}
89
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090Vote
91ThreadPlanStepRange::ShouldReportStop (Event *event_ptr)
92{
Greg Clayton5160ce52013-03-27 23:08:40 +000093 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton2cad65a2010-09-03 17:10:42 +000094
95 const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
96 if (log)
Greg Clayton411c0ce2011-01-18 21:44:45 +000097 log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote);
Greg Clayton2cad65a2010-09-03 17:10:42 +000098 return vote;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099}
100
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000101void
102ThreadPlanStepRange::AddRange(const AddressRange &new_range)
103{
104 // For now I'm just adding the ranges. At some point we may want to
105 // condense the ranges if they overlap, though I don't think it is likely
106 // to be very important.
107 m_address_ranges.push_back (new_range);
Jim Ingham56d40422013-07-31 02:19:15 +0000108
109 // Fill the slot for this address range with an empty DisassemblerSP in the instruction ranges. I want the
110 // indices to match, but I don't want to do the work to disassemble this range if I don't step into it.
Jim Ingham564d8bc22012-03-09 04:10:47 +0000111 m_instruction_ranges.push_back (DisassemblerSP());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000112}
113
114void
115ThreadPlanStepRange::DumpRanges(Stream *s)
116{
117 size_t num_ranges = m_address_ranges.size();
118 if (num_ranges == 1)
119 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000120 m_address_ranges[0].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000121 }
122 else
123 {
124 for (size_t i = 0; i < num_ranges; i++)
125 {
126 s->PutCString("%d: ");
Greg Clayton1ac04c32012-02-21 00:09:25 +0000127 m_address_ranges[i].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000128 }
129 }
130}
131
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132bool
133ThreadPlanStepRange::InRange ()
134{
Greg Clayton5160ce52013-03-27 23:08:40 +0000135 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136 bool ret_value = false;
137
138 lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
139
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000140 size_t num_ranges = m_address_ranges.size();
141 for (size_t i = 0; i < num_ranges; i++)
142 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000143 ret_value = m_address_ranges[i].ContainsLoadAddress(pc_load_addr, m_thread.CalculateTarget().get());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000144 if (ret_value)
145 break;
146 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147
148 if (!ret_value)
149 {
150 // See if we've just stepped to another part of the same line number...
151 StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
152
153 SymbolContext new_context(frame->GetSymbolContext(eSymbolContextEverything));
154 if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid())
155 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000156 if (m_addr_context.line_entry.file == new_context.line_entry.file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000158 if (m_addr_context.line_entry.line == new_context.line_entry.line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000160 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000161 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000162 ret_value = true;
163 if (log)
164 {
165 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000166 m_addr_context.line_entry.Dump (&s,
167 m_thread.CalculateTarget().get(),
168 true,
169 Address::DumpStyleLoadAddress,
170 Address::DumpStyleLoadAddress,
171 true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172
Jim Ingham843bfb22011-09-23 21:08:11 +0000173 log->Printf ("Step range plan stepped to another range of same line: %s", s.GetData());
174 }
175 }
Jim Ingham2b89a532013-09-27 01:15:46 +0000176 else if (new_context.line_entry.line == 0)
177 {
178 new_context.line_entry.line = m_addr_context.line_entry.line;
179 m_addr_context = new_context;
180 AddRange(m_addr_context.line_entry.range);
181 ret_value = true;
182 if (log)
183 {
184 StreamString s;
185 m_addr_context.line_entry.Dump (&s,
186 m_thread.CalculateTarget().get(),
187 true,
188 Address::DumpStyleLoadAddress,
189 Address::DumpStyleLoadAddress,
190 true);
191
192 log->Printf ("Step range plan stepped to a range at linenumber 0 stepping through that range: %s", s.GetData());
193 }
194 }
Greg Clayton1ac04c32012-02-21 00:09:25 +0000195 else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(m_thread.CalculateTarget().get())
Jim Ingham843bfb22011-09-23 21:08:11 +0000196 != pc_load_addr)
197 {
198 // Another thing that sometimes happens here is that we step out of one line into the MIDDLE of another
199 // line. So far I mostly see this due to bugs in the debug information.
200 // But we probably don't want to be in the middle of a line range, so in that case reset the stepping
201 // range to the line we've stepped into the middle of and continue.
202 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000203 m_address_ranges.clear();
204 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000205 ret_value = true;
206 if (log)
207 {
208 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000209 m_addr_context.line_entry.Dump (&s,
210 m_thread.CalculateTarget().get(),
211 true,
212 Address::DumpStyleLoadAddress,
213 Address::DumpStyleLoadAddress,
214 true);
Jim Ingham843bfb22011-09-23 21:08:11 +0000215
216 log->Printf ("Step range plan stepped to the middle of new line(%d): %s, continuing to clear this line.",
217 new_context.line_entry.line,
218 s.GetData());
219 }
220
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221 }
222 }
Jim Ingham843bfb22011-09-23 21:08:11 +0000223
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 }
225
226 }
227
228 if (!ret_value && log)
Daniel Malead01b2952012-11-29 21:49:15 +0000229 log->Printf ("Step range plan out of range to 0x%" PRIx64, pc_load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230
231 return ret_value;
232}
233
234bool
235ThreadPlanStepRange::InSymbol()
236{
237 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238 if (m_addr_context.function != NULL)
239 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000240 return m_addr_context.function->GetAddressRange().ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241 }
Greg Claytone7612132012-03-07 21:03:09 +0000242 else if (m_addr_context.symbol)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 {
Greg Claytone7612132012-03-07 21:03:09 +0000244 AddressRange range(m_addr_context.symbol->GetAddress(), m_addr_context.symbol->GetByteSize());
245 return range.ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246 }
247 return false;
248}
249
250// FIXME: This should also handle inlining if we aren't going to do inlining in the
251// main stack.
252//
253// Ideally we should remember the whole stack frame list, and then compare that
254// to the current list.
255
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000256lldb::FrameComparison
257ThreadPlanStepRange::CompareCurrentFrameToStartFrame()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258{
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000259 FrameComparison frame_order;
Jim Ingham7ce490c2010-09-16 00:58:09 +0000260
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000261 StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham7ce490c2010-09-16 00:58:09 +0000262
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000263 if (cur_frame_id == m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000265 frame_order = eFrameCompareEqual;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000267 else if (cur_frame_id < m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000269 frame_order = eFrameCompareYounger;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 }
271 else
272 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000273 frame_order = eFrameCompareOlder;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000275 return frame_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276}
277
278bool
279ThreadPlanStepRange::StopOthers ()
280{
281 if (m_stop_others == lldb::eOnlyThisThread
282 || m_stop_others == lldb::eOnlyDuringStepping)
283 return true;
284 else
285 return false;
286}
287
Jim Ingham564d8bc22012-03-09 04:10:47 +0000288InstructionList *
289ThreadPlanStepRange::GetInstructionsForAddress(lldb::addr_t addr, size_t &range_index, size_t &insn_offset)
290{
291 size_t num_ranges = m_address_ranges.size();
292 for (size_t i = 0; i < num_ranges; i++)
293 {
294 if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget()))
295 {
296 // Some joker added a zero size range to the stepping range...
297 if (m_address_ranges[i].GetByteSize() == 0)
298 return NULL;
299
300 if (!m_instruction_ranges[i])
301 {
302 //Disassemble the address range given:
303 ExecutionContext exe_ctx (m_thread.GetProcess());
Jim Ingham0f063ba2013-03-02 00:26:47 +0000304 const char *plugin_name = NULL;
305 const char *flavor = NULL;
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000306 const bool prefer_file_cache = true;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000307 m_instruction_ranges[i] = Disassembler::DisassembleRange(GetTarget().GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000308 plugin_name,
309 flavor,
Jim Ingham564d8bc22012-03-09 04:10:47 +0000310 exe_ctx,
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000311 m_address_ranges[i],
312 prefer_file_cache);
Jim Ingham564d8bc22012-03-09 04:10:47 +0000313
314 }
315 if (!m_instruction_ranges[i])
316 return NULL;
317 else
318 {
319 // Find where we are in the instruction list as well. If we aren't at an instruction,
320 // return NULL. In this case, we're probably lost, and shouldn't try to do anything fancy.
321
322 insn_offset = m_instruction_ranges[i]->GetInstructionList().GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
323 if (insn_offset == UINT32_MAX)
324 return NULL;
325 else
326 {
327 range_index = i;
328 return &m_instruction_ranges[i]->GetInstructionList();
329 }
330 }
331 }
332 }
333 return NULL;
334}
335
336void
337ThreadPlanStepRange::ClearNextBranchBreakpoint()
338{
339 if (m_next_branch_bp_sp)
340 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000341 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham0c61dee2013-03-13 01:56:41 +0000342 if (log)
343 log->Printf ("Removing next branch breakpoint: %d.", m_next_branch_bp_sp->GetID());
Jim Ingham564d8bc22012-03-09 04:10:47 +0000344 GetTarget().RemoveBreakpointByID (m_next_branch_bp_sp->GetID());
345 m_next_branch_bp_sp.reset();
346 }
347}
348
349bool
350ThreadPlanStepRange::SetNextBranchBreakpoint ()
351{
Jim Ingham0c61dee2013-03-13 01:56:41 +0000352 if (m_next_branch_bp_sp)
353 return true;
354
Greg Clayton5160ce52013-03-27 23:08:40 +0000355 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000356 // Stepping through ranges using breakpoints doesn't work yet, but with this off we fall back to instruction
357 // single stepping.
Jim Ingham0c61dee2013-03-13 01:56:41 +0000358 if (!m_use_fast_step)
359 return false;
360
Jim Ingham564d8bc22012-03-09 04:10:47 +0000361 lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
362 // Find the current address in our address ranges, and fetch the disassembly if we haven't already:
363 size_t pc_index;
364 size_t range_index;
365 InstructionList *instructions = GetInstructionsForAddress (cur_addr, range_index, pc_index);
366 if (instructions == NULL)
367 return false;
368 else
369 {
370 uint32_t branch_index;
371 branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index);
372
373 Address run_to_address;
374
375 // If we didn't find a branch, run to the end of the range.
376 if (branch_index == UINT32_MAX)
377 {
Jim Ingham0c61dee2013-03-13 01:56:41 +0000378 branch_index = instructions->GetSize() - 1;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000379 }
Jim Ingham0c61dee2013-03-13 01:56:41 +0000380
Jim Ingham564d8bc22012-03-09 04:10:47 +0000381 if (branch_index - pc_index > 1)
382 {
383 const bool is_internal = true;
384 run_to_address = instructions->GetInstructionAtIndex(branch_index)->GetAddress();
385 m_next_branch_bp_sp = GetTarget().CreateBreakpoint(run_to_address, is_internal);
Jim Ingham29950772013-01-26 02:19:28 +0000386 if (m_next_branch_bp_sp)
387 {
Jim Ingham0c61dee2013-03-13 01:56:41 +0000388 if (log)
389 {
390 lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
391 BreakpointLocationSP bp_loc = m_next_branch_bp_sp->GetLocationAtIndex(0);
392 if (bp_loc)
393 {
394 BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
395 if (bp_site)
396 {
397 bp_site_id = bp_site->GetID();
398 }
399 }
400 log->Printf ("ThreadPlanStepRange::SetNextBranchBreakpoint - Setting breakpoint %d (site %d) to run to address 0x%" PRIx64,
401 m_next_branch_bp_sp->GetID(),
402 bp_site_id,
403 run_to_address.GetLoadAddress(&m_thread.GetProcess()->GetTarget()));
404 }
Jim Ingham29950772013-01-26 02:19:28 +0000405 m_next_branch_bp_sp->SetThreadID(m_thread.GetID());
406 m_next_branch_bp_sp->SetBreakpointKind ("next-branch-location");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000407 return true;
Jim Ingham29950772013-01-26 02:19:28 +0000408 }
409 else
410 return false;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000411 }
412 }
413 return false;
414}
415
416bool
417ThreadPlanStepRange::NextRangeBreakpointExplainsStop (lldb::StopInfoSP stop_info_sp)
418{
Greg Clayton5160ce52013-03-27 23:08:40 +0000419 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000420 if (!m_next_branch_bp_sp)
421 return false;
422
423 break_id_t bp_site_id = stop_info_sp->GetValue();
424 BreakpointSiteSP bp_site_sp = m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id);
Jim Ingham0c61dee2013-03-13 01:56:41 +0000425 if (!bp_site_sp)
426 return false;
427 else if (!bp_site_sp->IsBreakpointAtThisSite (m_next_branch_bp_sp->GetID()))
Jim Ingham564d8bc22012-03-09 04:10:47 +0000428 return false;
429 else
Jim Ingham0c61dee2013-03-13 01:56:41 +0000430 {
431 // If we've hit the next branch breakpoint, then clear it.
432 size_t num_owners = bp_site_sp->GetNumberOfOwners();
433 bool explains_stop = true;
434 // If all the owners are internal, then we are probably just stepping over this range from multiple threads,
435 // or multiple frames, so we want to continue. If one is not internal, then we should not explain the stop,
436 // and let the user breakpoint handle the stop.
437 for (size_t i = 0; i < num_owners; i++)
438 {
439 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
440 {
441 explains_stop = false;
442 break;
443 }
444 }
445 if (log)
446 log->Printf ("ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit next range breakpoint which has %zu owners - explains stop: %u.",
447 num_owners,
448 explains_stop);
449 ClearNextBranchBreakpoint();
450 return explains_stop;
451 }
Jim Ingham564d8bc22012-03-09 04:10:47 +0000452}
453
454bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455ThreadPlanStepRange::WillStop ()
456{
457 return true;
458}
459
460StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000461ThreadPlanStepRange::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462{
Jim Ingham564d8bc22012-03-09 04:10:47 +0000463 if (m_next_branch_bp_sp)
464 return eStateRunning;
465 else
466 return eStateStepping;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467}
468
469bool
470ThreadPlanStepRange::MischiefManaged ()
471{
Jim Ingham927bfa32012-09-10 23:42:44 +0000472 // If we have pushed some plans between ShouldStop & MischiefManaged, then we're not done...
473 // I do this check first because we might have stepped somewhere that will fool InRange into
474 // thinking it needs to step past the end of that line. This happens, for instance, when stepping
475 // over inlined code that is in the middle of the current line.
476
477 if (!m_no_more_plans)
478 return false;
479
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 bool done = true;
481 if (!IsPlanComplete())
482 {
483 if (InRange())
484 {
485 done = false;
486 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000487 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000489 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
490 if (frame_order != eFrameCompareOlder)
491 {
492 if (m_no_more_plans)
493 done = true;
494 else
495 done = false;
496 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497 else
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000498 done = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500 }
501
502 if (done)
503 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000504 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 if (log)
506 log->Printf("Completed step through range plan.");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000507 ClearNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508 ThreadPlan::MischiefManaged ();
509 return true;
510 }
511 else
512 {
513 return false;
514 }
515
516}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000517
518bool
519ThreadPlanStepRange::IsPlanStale ()
520{
Greg Clayton5160ce52013-03-27 23:08:40 +0000521 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000522 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
523
524 if (frame_order == eFrameCompareOlder)
525 {
526 if (log)
527 {
528 log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've stepped out.");
529 }
530 return true;
531 }
532 else if (frame_order == eFrameCompareEqual && InSymbol())
533 {
534 // If we are not in a place we should step through, we've gotten stale.
535 // One tricky bit here is that some stubs don't push a frame, so we should.
536 // check that we are in the same symbol.
537 if (!InRange())
538 {
539 return true;
540 }
541 }
542 return false;
543}