blob: adc515cebc08eaa2591670ce7db4b84c108b6ac1 [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,
Jim Ingham2bdbfd52014-09-29 23:17:18 +000047 lldb::RunMode stop_others,
48 bool given_ranges_only) :
Jim Ingham35b21fe2010-07-10 02:23:31 +000049 ThreadPlan (kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050 m_addr_context (addr_context),
Jim Inghamc4c9fed2011-10-15 00:24:48 +000051 m_address_ranges (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052 m_stop_others (stop_others),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053 m_stack_id (),
Jim Ingham862d1bb2014-08-06 01:49:59 +000054 m_parent_stack_id(),
Greg Claytonc982c762010-07-09 20:39:50 +000055 m_no_more_plans (false),
Jim Ingham0c61dee2013-03-13 01:56:41 +000056 m_first_run_event (true),
Jim Ingham2bdbfd52014-09-29 23:17:18 +000057 m_use_fast_step(false),
58 m_given_ranges_only (given_ranges_only)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059{
Jason Molenda975abff2013-08-01 21:50:20 +000060 m_use_fast_step = GetTarget().GetUseFastStepping();
Jim Inghamc4c9fed2011-10-15 00:24:48 +000061 AddRange(range);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham76447852014-08-11 23:57:43 +000063 StackFrameSP parent_stack = m_thread.GetStackFrameAtIndex(1);
64 if (parent_stack)
65 m_parent_stack_id = parent_stack->GetStackID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066}
67
68ThreadPlanStepRange::~ThreadPlanStepRange ()
69{
Jim Ingham564d8bc22012-03-09 04:10:47 +000070 ClearNextBranchBreakpoint();
Jim Ingham56d40422013-07-31 02:19:15 +000071
72 size_t num_instruction_ranges = m_instruction_ranges.size();
73
74 // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
75 // I'll fix that but for now, just clear the list and it will go away nicely.
76 for (size_t i = 0; i < num_instruction_ranges; i++)
77 {
78 if (m_instruction_ranges[i])
79 m_instruction_ranges[i]->GetInstructionList().Clear();
80 }
Jim Ingham564d8bc22012-03-09 04:10:47 +000081}
82
83void
84ThreadPlanStepRange::DidPush ()
85{
86 // See if we can find a "next range" breakpoint:
87 SetNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088}
89
90bool
91ThreadPlanStepRange::ValidatePlan (Stream *error)
92{
93 return true;
94}
95
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096Vote
97ThreadPlanStepRange::ShouldReportStop (Event *event_ptr)
98{
Greg Clayton5160ce52013-03-27 23:08:40 +000099 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton2cad65a2010-09-03 17:10:42 +0000100
101 const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
102 if (log)
Greg Clayton411c0ce2011-01-18 21:44:45 +0000103 log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000104 return vote;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105}
106
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000107void
108ThreadPlanStepRange::AddRange(const AddressRange &new_range)
109{
110 // For now I'm just adding the ranges. At some point we may want to
111 // condense the ranges if they overlap, though I don't think it is likely
112 // to be very important.
113 m_address_ranges.push_back (new_range);
Jim Ingham56d40422013-07-31 02:19:15 +0000114
115 // Fill the slot for this address range with an empty DisassemblerSP in the instruction ranges. I want the
116 // 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 +0000117 m_instruction_ranges.push_back (DisassemblerSP());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000118}
119
120void
121ThreadPlanStepRange::DumpRanges(Stream *s)
122{
123 size_t num_ranges = m_address_ranges.size();
124 if (num_ranges == 1)
125 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000126 m_address_ranges[0].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000127 }
128 else
129 {
130 for (size_t i = 0; i < num_ranges; i++)
131 {
132 s->PutCString("%d: ");
Greg Clayton1ac04c32012-02-21 00:09:25 +0000133 m_address_ranges[i].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000134 }
135 }
136}
137
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138bool
139ThreadPlanStepRange::InRange ()
140{
Greg Clayton5160ce52013-03-27 23:08:40 +0000141 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142 bool ret_value = false;
143
144 lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
145
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000146 size_t num_ranges = m_address_ranges.size();
147 for (size_t i = 0; i < num_ranges; i++)
148 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000149 ret_value = m_address_ranges[i].ContainsLoadAddress(pc_load_addr, m_thread.CalculateTarget().get());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000150 if (ret_value)
151 break;
152 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000154 if (!ret_value && !m_given_ranges_only)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155 {
156 // See if we've just stepped to another part of the same line number...
Jason Molendab57e4a12013-11-04 09:33:30 +0000157 StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158
159 SymbolContext new_context(frame->GetSymbolContext(eSymbolContextEverything));
160 if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid())
161 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000162 if (m_addr_context.line_entry.file == new_context.line_entry.file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000164 if (m_addr_context.line_entry.line == new_context.line_entry.line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000166 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000167 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000168 ret_value = true;
169 if (log)
170 {
171 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000172 m_addr_context.line_entry.Dump (&s,
173 m_thread.CalculateTarget().get(),
174 true,
175 Address::DumpStyleLoadAddress,
176 Address::DumpStyleLoadAddress,
177 true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178
Jim Ingham843bfb22011-09-23 21:08:11 +0000179 log->Printf ("Step range plan stepped to another range of same line: %s", s.GetData());
180 }
181 }
Jim Ingham2b89a532013-09-27 01:15:46 +0000182 else if (new_context.line_entry.line == 0)
183 {
184 new_context.line_entry.line = m_addr_context.line_entry.line;
185 m_addr_context = new_context;
186 AddRange(m_addr_context.line_entry.range);
187 ret_value = true;
188 if (log)
189 {
190 StreamString s;
191 m_addr_context.line_entry.Dump (&s,
192 m_thread.CalculateTarget().get(),
193 true,
194 Address::DumpStyleLoadAddress,
195 Address::DumpStyleLoadAddress,
196 true);
197
198 log->Printf ("Step range plan stepped to a range at linenumber 0 stepping through that range: %s", s.GetData());
199 }
200 }
Greg Clayton1ac04c32012-02-21 00:09:25 +0000201 else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(m_thread.CalculateTarget().get())
Jim Ingham843bfb22011-09-23 21:08:11 +0000202 != pc_load_addr)
203 {
204 // Another thing that sometimes happens here is that we step out of one line into the MIDDLE of another
205 // line. So far I mostly see this due to bugs in the debug information.
206 // But we probably don't want to be in the middle of a line range, so in that case reset the stepping
207 // range to the line we've stepped into the middle of and continue.
208 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000209 m_address_ranges.clear();
210 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000211 ret_value = true;
212 if (log)
213 {
214 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000215 m_addr_context.line_entry.Dump (&s,
216 m_thread.CalculateTarget().get(),
217 true,
218 Address::DumpStyleLoadAddress,
219 Address::DumpStyleLoadAddress,
220 true);
Jim Ingham843bfb22011-09-23 21:08:11 +0000221
222 log->Printf ("Step range plan stepped to the middle of new line(%d): %s, continuing to clear this line.",
223 new_context.line_entry.line,
224 s.GetData());
225 }
226
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 }
228 }
Jim Ingham843bfb22011-09-23 21:08:11 +0000229
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 }
231
232 }
233
234 if (!ret_value && log)
Daniel Malead01b2952012-11-29 21:49:15 +0000235 log->Printf ("Step range plan out of range to 0x%" PRIx64, pc_load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000236
237 return ret_value;
238}
239
240bool
241ThreadPlanStepRange::InSymbol()
242{
243 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244 if (m_addr_context.function != NULL)
245 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000246 return m_addr_context.function->GetAddressRange().ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247 }
Greg Claytone7612132012-03-07 21:03:09 +0000248 else if (m_addr_context.symbol)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249 {
Greg Claytone7612132012-03-07 21:03:09 +0000250 AddressRange range(m_addr_context.symbol->GetAddress(), m_addr_context.symbol->GetByteSize());
251 return range.ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 }
253 return false;
254}
255
256// FIXME: This should also handle inlining if we aren't going to do inlining in the
257// main stack.
258//
259// Ideally we should remember the whole stack frame list, and then compare that
260// to the current list.
261
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000262lldb::FrameComparison
263ThreadPlanStepRange::CompareCurrentFrameToStartFrame()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264{
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000265 FrameComparison frame_order;
Jim Ingham7ce490c2010-09-16 00:58:09 +0000266
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000267 StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham7ce490c2010-09-16 00:58:09 +0000268
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000269 if (cur_frame_id == m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000271 frame_order = eFrameCompareEqual;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000273 else if (cur_frame_id < m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000275 frame_order = eFrameCompareYounger;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 }
277 else
278 {
Jim Ingham76447852014-08-11 23:57:43 +0000279 StackFrameSP cur_parent_frame = m_thread.GetStackFrameAtIndex(1);
280 StackID cur_parent_id;
281 if (cur_parent_frame)
282 cur_parent_id = cur_parent_frame->GetStackID();
Jim Ingham862d1bb2014-08-06 01:49:59 +0000283 if (m_parent_stack_id.IsValid()
284 && cur_parent_id.IsValid()
285 && m_parent_stack_id == cur_parent_id)
286 frame_order = eFrameCompareSameParent;
287 else
288 frame_order = eFrameCompareOlder;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000290 return frame_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291}
292
293bool
294ThreadPlanStepRange::StopOthers ()
295{
296 if (m_stop_others == lldb::eOnlyThisThread
297 || m_stop_others == lldb::eOnlyDuringStepping)
298 return true;
299 else
300 return false;
301}
302
Jim Ingham564d8bc22012-03-09 04:10:47 +0000303InstructionList *
304ThreadPlanStepRange::GetInstructionsForAddress(lldb::addr_t addr, size_t &range_index, size_t &insn_offset)
305{
306 size_t num_ranges = m_address_ranges.size();
307 for (size_t i = 0; i < num_ranges; i++)
308 {
309 if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget()))
310 {
311 // Some joker added a zero size range to the stepping range...
312 if (m_address_ranges[i].GetByteSize() == 0)
313 return NULL;
314
315 if (!m_instruction_ranges[i])
316 {
317 //Disassemble the address range given:
318 ExecutionContext exe_ctx (m_thread.GetProcess());
Jim Ingham0f063ba2013-03-02 00:26:47 +0000319 const char *plugin_name = NULL;
320 const char *flavor = NULL;
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000321 const bool prefer_file_cache = true;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000322 m_instruction_ranges[i] = Disassembler::DisassembleRange(GetTarget().GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000323 plugin_name,
324 flavor,
Jim Ingham564d8bc22012-03-09 04:10:47 +0000325 exe_ctx,
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000326 m_address_ranges[i],
327 prefer_file_cache);
Jim Ingham564d8bc22012-03-09 04:10:47 +0000328
329 }
330 if (!m_instruction_ranges[i])
331 return NULL;
332 else
333 {
334 // Find where we are in the instruction list as well. If we aren't at an instruction,
335 // return NULL. In this case, we're probably lost, and shouldn't try to do anything fancy.
336
337 insn_offset = m_instruction_ranges[i]->GetInstructionList().GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
338 if (insn_offset == UINT32_MAX)
339 return NULL;
340 else
341 {
342 range_index = i;
343 return &m_instruction_ranges[i]->GetInstructionList();
344 }
345 }
346 }
347 }
348 return NULL;
349}
350
351void
352ThreadPlanStepRange::ClearNextBranchBreakpoint()
353{
354 if (m_next_branch_bp_sp)
355 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000356 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham0c61dee2013-03-13 01:56:41 +0000357 if (log)
358 log->Printf ("Removing next branch breakpoint: %d.", m_next_branch_bp_sp->GetID());
Jim Ingham564d8bc22012-03-09 04:10:47 +0000359 GetTarget().RemoveBreakpointByID (m_next_branch_bp_sp->GetID());
360 m_next_branch_bp_sp.reset();
361 }
362}
363
364bool
365ThreadPlanStepRange::SetNextBranchBreakpoint ()
366{
Jim Ingham0c61dee2013-03-13 01:56:41 +0000367 if (m_next_branch_bp_sp)
368 return true;
369
Greg Clayton5160ce52013-03-27 23:08:40 +0000370 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000371 // Stepping through ranges using breakpoints doesn't work yet, but with this off we fall back to instruction
372 // single stepping.
Jim Ingham0c61dee2013-03-13 01:56:41 +0000373 if (!m_use_fast_step)
374 return false;
375
Jim Ingham564d8bc22012-03-09 04:10:47 +0000376 lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
377 // Find the current address in our address ranges, and fetch the disassembly if we haven't already:
378 size_t pc_index;
379 size_t range_index;
380 InstructionList *instructions = GetInstructionsForAddress (cur_addr, range_index, pc_index);
381 if (instructions == NULL)
382 return false;
383 else
384 {
385 uint32_t branch_index;
386 branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index);
387
388 Address run_to_address;
389
390 // If we didn't find a branch, run to the end of the range.
391 if (branch_index == UINT32_MAX)
392 {
Jim Ingham0c61dee2013-03-13 01:56:41 +0000393 branch_index = instructions->GetSize() - 1;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000394 }
Jim Ingham0c61dee2013-03-13 01:56:41 +0000395
Jim Ingham564d8bc22012-03-09 04:10:47 +0000396 if (branch_index - pc_index > 1)
397 {
398 const bool is_internal = true;
399 run_to_address = instructions->GetInstructionAtIndex(branch_index)->GetAddress();
Greg Claytoneb023e72013-10-11 19:48:25 +0000400 m_next_branch_bp_sp = GetTarget().CreateBreakpoint(run_to_address, is_internal, false);
Jim Ingham29950772013-01-26 02:19:28 +0000401 if (m_next_branch_bp_sp)
402 {
Jim Ingham0c61dee2013-03-13 01:56:41 +0000403 if (log)
404 {
405 lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
406 BreakpointLocationSP bp_loc = m_next_branch_bp_sp->GetLocationAtIndex(0);
407 if (bp_loc)
408 {
409 BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
410 if (bp_site)
411 {
412 bp_site_id = bp_site->GetID();
413 }
414 }
415 log->Printf ("ThreadPlanStepRange::SetNextBranchBreakpoint - Setting breakpoint %d (site %d) to run to address 0x%" PRIx64,
416 m_next_branch_bp_sp->GetID(),
417 bp_site_id,
418 run_to_address.GetLoadAddress(&m_thread.GetProcess()->GetTarget()));
419 }
Jim Ingham29950772013-01-26 02:19:28 +0000420 m_next_branch_bp_sp->SetThreadID(m_thread.GetID());
421 m_next_branch_bp_sp->SetBreakpointKind ("next-branch-location");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000422 return true;
Jim Ingham29950772013-01-26 02:19:28 +0000423 }
424 else
425 return false;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000426 }
427 }
428 return false;
429}
430
431bool
432ThreadPlanStepRange::NextRangeBreakpointExplainsStop (lldb::StopInfoSP stop_info_sp)
433{
Greg Clayton5160ce52013-03-27 23:08:40 +0000434 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000435 if (!m_next_branch_bp_sp)
436 return false;
437
438 break_id_t bp_site_id = stop_info_sp->GetValue();
439 BreakpointSiteSP bp_site_sp = m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id);
Jim Ingham0c61dee2013-03-13 01:56:41 +0000440 if (!bp_site_sp)
441 return false;
442 else if (!bp_site_sp->IsBreakpointAtThisSite (m_next_branch_bp_sp->GetID()))
Jim Ingham564d8bc22012-03-09 04:10:47 +0000443 return false;
444 else
Jim Ingham0c61dee2013-03-13 01:56:41 +0000445 {
446 // If we've hit the next branch breakpoint, then clear it.
447 size_t num_owners = bp_site_sp->GetNumberOfOwners();
448 bool explains_stop = true;
449 // If all the owners are internal, then we are probably just stepping over this range from multiple threads,
450 // or multiple frames, so we want to continue. If one is not internal, then we should not explain the stop,
451 // and let the user breakpoint handle the stop.
452 for (size_t i = 0; i < num_owners; i++)
453 {
454 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
455 {
456 explains_stop = false;
457 break;
458 }
459 }
460 if (log)
Deepak Panickal99fbc072014-03-03 15:39:47 +0000461 log->Printf ("ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit next range breakpoint which has %" PRIu64 " owners - explains stop: %u.",
462 (uint64_t)num_owners,
Jim Ingham0c61dee2013-03-13 01:56:41 +0000463 explains_stop);
464 ClearNextBranchBreakpoint();
465 return explains_stop;
466 }
Jim Ingham564d8bc22012-03-09 04:10:47 +0000467}
468
469bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470ThreadPlanStepRange::WillStop ()
471{
472 return true;
473}
474
475StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000476ThreadPlanStepRange::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477{
Jim Ingham564d8bc22012-03-09 04:10:47 +0000478 if (m_next_branch_bp_sp)
479 return eStateRunning;
480 else
481 return eStateStepping;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482}
483
484bool
485ThreadPlanStepRange::MischiefManaged ()
486{
Jim Ingham927bfa32012-09-10 23:42:44 +0000487 // If we have pushed some plans between ShouldStop & MischiefManaged, then we're not done...
488 // I do this check first because we might have stepped somewhere that will fool InRange into
489 // thinking it needs to step past the end of that line. This happens, for instance, when stepping
490 // over inlined code that is in the middle of the current line.
491
492 if (!m_no_more_plans)
493 return false;
494
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 bool done = true;
496 if (!IsPlanComplete())
497 {
498 if (InRange())
499 {
500 done = false;
501 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000502 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000504 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
505 if (frame_order != eFrameCompareOlder)
506 {
507 if (m_no_more_plans)
508 done = true;
509 else
510 done = false;
511 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 else
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000513 done = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515 }
516
517 if (done)
518 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000519 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 if (log)
521 log->Printf("Completed step through range plan.");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000522 ClearNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 ThreadPlan::MischiefManaged ();
524 return true;
525 }
526 else
527 {
528 return false;
529 }
530
531}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000532
533bool
534ThreadPlanStepRange::IsPlanStale ()
535{
Greg Clayton5160ce52013-03-27 23:08:40 +0000536 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000537 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
538
539 if (frame_order == eFrameCompareOlder)
540 {
541 if (log)
542 {
543 log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've stepped out.");
544 }
545 return true;
546 }
547 else if (frame_order == eFrameCompareEqual && InSymbol())
548 {
549 // If we are not in a place we should step through, we've gotten stale.
550 // One tricky bit here is that some stubs don't push a frame, so we should.
551 // check that we are in the same symbol.
552 if (!InRange())
553 {
554 return true;
555 }
556 }
557 return false;
558}