blob: 3aed85859507a37e3fb64a767b074492d97f4108 [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
Jim Ingham0c61dee2013-03-13 01:56:41 +000016#include "lldb/Breakpoint/BreakpointLocation.h"
17#include "lldb/Breakpoint/BreakpointSite.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000018#include "lldb/Core/Disassembler.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/Log.h"
20#include "lldb/Core/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Symbol/Function.h"
22#include "lldb/Symbol/Symbol.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000023#include "lldb/Target/ExecutionContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000024#include "lldb/Target/Process.h"
25#include "lldb/Target/RegisterContext.h"
26#include "lldb/Target/StopInfo.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000027#include "lldb/Target/Target.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000028#include "lldb/Target/Thread.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000029#include "lldb/Target/ThreadPlanRunToAddress.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
31using namespace lldb;
32using namespace lldb_private;
33
34
35//----------------------------------------------------------------------
36// ThreadPlanStepRange: Step through a stack range, either stepping over or into
37// based on the value of \a type.
38//----------------------------------------------------------------------
39
Jim Ingham242e0ad2011-02-08 04:27:50 +000040ThreadPlanStepRange::ThreadPlanStepRange (ThreadPlanKind kind,
41 const char *name,
42 Thread &thread,
43 const AddressRange &range,
44 const SymbolContext &addr_context,
Jim Ingham2bdbfd52014-09-29 23:17:18 +000045 lldb::RunMode stop_others,
46 bool given_ranges_only) :
Jim Ingham35b21fe2010-07-10 02:23:31 +000047 ThreadPlan (kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 m_addr_context (addr_context),
Jim Inghamc4c9fed2011-10-15 00:24:48 +000049 m_address_ranges (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050 m_stop_others (stop_others),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051 m_stack_id (),
Jim Ingham862d1bb2014-08-06 01:49:59 +000052 m_parent_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),
Jim Ingham2bdbfd52014-09-29 23:17:18 +000055 m_use_fast_step(false),
56 m_given_ranges_only (given_ranges_only)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057{
Jason Molenda975abff2013-08-01 21:50:20 +000058 m_use_fast_step = GetTarget().GetUseFastStepping();
Jim Inghamc4c9fed2011-10-15 00:24:48 +000059 AddRange(range);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham76447852014-08-11 23:57:43 +000061 StackFrameSP parent_stack = m_thread.GetStackFrameAtIndex(1);
62 if (parent_stack)
63 m_parent_stack_id = parent_stack->GetStackID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064}
65
66ThreadPlanStepRange::~ThreadPlanStepRange ()
67{
Jim Ingham564d8bc22012-03-09 04:10:47 +000068 ClearNextBranchBreakpoint();
Jim Ingham56d40422013-07-31 02:19:15 +000069
70 size_t num_instruction_ranges = m_instruction_ranges.size();
71
72 // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
73 // I'll fix that but for now, just clear the list and it will go away nicely.
74 for (size_t i = 0; i < num_instruction_ranges; i++)
75 {
76 if (m_instruction_ranges[i])
77 m_instruction_ranges[i]->GetInstructionList().Clear();
78 }
Jim Ingham564d8bc22012-03-09 04:10:47 +000079}
80
81void
82ThreadPlanStepRange::DidPush ()
83{
84 // See if we can find a "next range" breakpoint:
85 SetNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086}
87
88bool
89ThreadPlanStepRange::ValidatePlan (Stream *error)
90{
91 return true;
92}
93
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094Vote
95ThreadPlanStepRange::ShouldReportStop (Event *event_ptr)
96{
Greg Clayton5160ce52013-03-27 23:08:40 +000097 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton2cad65a2010-09-03 17:10:42 +000098
99 const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
100 if (log)
Greg Clayton411c0ce2011-01-18 21:44:45 +0000101 log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000102 return vote;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103}
104
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000105void
106ThreadPlanStepRange::AddRange(const AddressRange &new_range)
107{
108 // For now I'm just adding the ranges. At some point we may want to
109 // condense the ranges if they overlap, though I don't think it is likely
110 // to be very important.
111 m_address_ranges.push_back (new_range);
Jim Ingham56d40422013-07-31 02:19:15 +0000112
113 // Fill the slot for this address range with an empty DisassemblerSP in the instruction ranges. I want the
114 // 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 +0000115 m_instruction_ranges.push_back (DisassemblerSP());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000116}
117
118void
119ThreadPlanStepRange::DumpRanges(Stream *s)
120{
121 size_t num_ranges = m_address_ranges.size();
122 if (num_ranges == 1)
123 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000124 m_address_ranges[0].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000125 }
126 else
127 {
128 for (size_t i = 0; i < num_ranges; i++)
129 {
130 s->PutCString("%d: ");
Greg Clayton1ac04c32012-02-21 00:09:25 +0000131 m_address_ranges[i].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000132 }
133 }
134}
135
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136bool
137ThreadPlanStepRange::InRange ()
138{
Greg Clayton5160ce52013-03-27 23:08:40 +0000139 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140 bool ret_value = false;
141
142 lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
143
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000144 size_t num_ranges = m_address_ranges.size();
145 for (size_t i = 0; i < num_ranges; i++)
146 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000147 ret_value = m_address_ranges[i].ContainsLoadAddress(pc_load_addr, m_thread.CalculateTarget().get());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000148 if (ret_value)
149 break;
150 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000152 if (!ret_value && !m_given_ranges_only)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153 {
154 // See if we've just stepped to another part of the same line number...
Jason Molendab57e4a12013-11-04 09:33:30 +0000155 StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156
157 SymbolContext new_context(frame->GetSymbolContext(eSymbolContextEverything));
158 if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid())
159 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000160 if (m_addr_context.line_entry.file == new_context.line_entry.file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000162 if (m_addr_context.line_entry.line == new_context.line_entry.line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000164 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000165 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000166 ret_value = true;
167 if (log)
168 {
169 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000170 m_addr_context.line_entry.Dump (&s,
171 m_thread.CalculateTarget().get(),
172 true,
173 Address::DumpStyleLoadAddress,
174 Address::DumpStyleLoadAddress,
175 true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176
Jim Ingham843bfb22011-09-23 21:08:11 +0000177 log->Printf ("Step range plan stepped to another range of same line: %s", s.GetData());
178 }
179 }
Jim Ingham2b89a532013-09-27 01:15:46 +0000180 else if (new_context.line_entry.line == 0)
181 {
182 new_context.line_entry.line = m_addr_context.line_entry.line;
183 m_addr_context = new_context;
184 AddRange(m_addr_context.line_entry.range);
185 ret_value = true;
186 if (log)
187 {
188 StreamString s;
189 m_addr_context.line_entry.Dump (&s,
190 m_thread.CalculateTarget().get(),
191 true,
192 Address::DumpStyleLoadAddress,
193 Address::DumpStyleLoadAddress,
194 true);
195
196 log->Printf ("Step range plan stepped to a range at linenumber 0 stepping through that range: %s", s.GetData());
197 }
198 }
Greg Clayton1ac04c32012-02-21 00:09:25 +0000199 else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(m_thread.CalculateTarget().get())
Jim Ingham843bfb22011-09-23 21:08:11 +0000200 != pc_load_addr)
201 {
202 // Another thing that sometimes happens here is that we step out of one line into the MIDDLE of another
203 // line. So far I mostly see this due to bugs in the debug information.
204 // But we probably don't want to be in the middle of a line range, so in that case reset the stepping
205 // range to the line we've stepped into the middle of and continue.
206 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000207 m_address_ranges.clear();
208 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000209 ret_value = true;
210 if (log)
211 {
212 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000213 m_addr_context.line_entry.Dump (&s,
214 m_thread.CalculateTarget().get(),
215 true,
216 Address::DumpStyleLoadAddress,
217 Address::DumpStyleLoadAddress,
218 true);
Jim Ingham843bfb22011-09-23 21:08:11 +0000219
220 log->Printf ("Step range plan stepped to the middle of new line(%d): %s, continuing to clear this line.",
221 new_context.line_entry.line,
222 s.GetData());
223 }
224
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 }
226 }
Jim Ingham843bfb22011-09-23 21:08:11 +0000227
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 }
229
230 }
231
232 if (!ret_value && log)
Daniel Malead01b2952012-11-29 21:49:15 +0000233 log->Printf ("Step range plan out of range to 0x%" PRIx64, pc_load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234
235 return ret_value;
236}
237
238bool
239ThreadPlanStepRange::InSymbol()
240{
241 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242 if (m_addr_context.function != NULL)
243 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000244 return m_addr_context.function->GetAddressRange().ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 }
Greg Clayton358cf1e2015-06-25 21:46:34 +0000246 else if (m_addr_context.symbol && m_addr_context.symbol->ValueIsAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247 {
Greg Clayton358cf1e2015-06-25 21:46:34 +0000248 AddressRange range(m_addr_context.symbol->GetAddressRef(), m_addr_context.symbol->GetByteSize());
Greg Claytone7612132012-03-07 21:03:09 +0000249 return range.ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250 }
251 return false;
252}
253
254// FIXME: This should also handle inlining if we aren't going to do inlining in the
255// main stack.
256//
257// Ideally we should remember the whole stack frame list, and then compare that
258// to the current list.
259
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000260lldb::FrameComparison
261ThreadPlanStepRange::CompareCurrentFrameToStartFrame()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262{
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000263 FrameComparison frame_order;
Jim Ingham7ce490c2010-09-16 00:58:09 +0000264
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000265 StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham7ce490c2010-09-16 00:58:09 +0000266
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000267 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 = eFrameCompareEqual;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000271 else if (cur_frame_id < m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000273 frame_order = eFrameCompareYounger;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 }
275 else
276 {
Jim Ingham76447852014-08-11 23:57:43 +0000277 StackFrameSP cur_parent_frame = m_thread.GetStackFrameAtIndex(1);
278 StackID cur_parent_id;
279 if (cur_parent_frame)
280 cur_parent_id = cur_parent_frame->GetStackID();
Jim Ingham862d1bb2014-08-06 01:49:59 +0000281 if (m_parent_stack_id.IsValid()
282 && cur_parent_id.IsValid()
283 && m_parent_stack_id == cur_parent_id)
284 frame_order = eFrameCompareSameParent;
285 else
286 frame_order = eFrameCompareOlder;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000288 return frame_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289}
290
291bool
292ThreadPlanStepRange::StopOthers ()
293{
294 if (m_stop_others == lldb::eOnlyThisThread
295 || m_stop_others == lldb::eOnlyDuringStepping)
296 return true;
297 else
298 return false;
299}
300
Jim Ingham564d8bc22012-03-09 04:10:47 +0000301InstructionList *
302ThreadPlanStepRange::GetInstructionsForAddress(lldb::addr_t addr, size_t &range_index, size_t &insn_offset)
303{
304 size_t num_ranges = m_address_ranges.size();
305 for (size_t i = 0; i < num_ranges; i++)
306 {
307 if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget()))
308 {
309 // Some joker added a zero size range to the stepping range...
310 if (m_address_ranges[i].GetByteSize() == 0)
311 return NULL;
312
313 if (!m_instruction_ranges[i])
314 {
315 //Disassemble the address range given:
316 ExecutionContext exe_ctx (m_thread.GetProcess());
Jim Ingham0f063ba2013-03-02 00:26:47 +0000317 const char *plugin_name = NULL;
318 const char *flavor = NULL;
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000319 const bool prefer_file_cache = true;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000320 m_instruction_ranges[i] = Disassembler::DisassembleRange(GetTarget().GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000321 plugin_name,
322 flavor,
Jim Ingham564d8bc22012-03-09 04:10:47 +0000323 exe_ctx,
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000324 m_address_ranges[i],
325 prefer_file_cache);
Jim Ingham564d8bc22012-03-09 04:10:47 +0000326
327 }
328 if (!m_instruction_ranges[i])
329 return NULL;
330 else
331 {
332 // Find where we are in the instruction list as well. If we aren't at an instruction,
333 // return NULL. In this case, we're probably lost, and shouldn't try to do anything fancy.
334
335 insn_offset = m_instruction_ranges[i]->GetInstructionList().GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
336 if (insn_offset == UINT32_MAX)
337 return NULL;
338 else
339 {
340 range_index = i;
341 return &m_instruction_ranges[i]->GetInstructionList();
342 }
343 }
344 }
345 }
346 return NULL;
347}
348
349void
350ThreadPlanStepRange::ClearNextBranchBreakpoint()
351{
352 if (m_next_branch_bp_sp)
353 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000354 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham0c61dee2013-03-13 01:56:41 +0000355 if (log)
356 log->Printf ("Removing next branch breakpoint: %d.", m_next_branch_bp_sp->GetID());
Jim Ingham564d8bc22012-03-09 04:10:47 +0000357 GetTarget().RemoveBreakpointByID (m_next_branch_bp_sp->GetID());
358 m_next_branch_bp_sp.reset();
359 }
360}
361
362bool
363ThreadPlanStepRange::SetNextBranchBreakpoint ()
364{
Jim Ingham0c61dee2013-03-13 01:56:41 +0000365 if (m_next_branch_bp_sp)
366 return true;
367
Greg Clayton5160ce52013-03-27 23:08:40 +0000368 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000369 // Stepping through ranges using breakpoints doesn't work yet, but with this off we fall back to instruction
370 // single stepping.
Jim Ingham0c61dee2013-03-13 01:56:41 +0000371 if (!m_use_fast_step)
372 return false;
373
Jim Ingham564d8bc22012-03-09 04:10:47 +0000374 lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
375 // Find the current address in our address ranges, and fetch the disassembly if we haven't already:
376 size_t pc_index;
377 size_t range_index;
378 InstructionList *instructions = GetInstructionsForAddress (cur_addr, range_index, pc_index);
379 if (instructions == NULL)
380 return false;
381 else
382 {
Ted Woodwarde76e7e92015-05-11 21:12:33 +0000383 Target &target = GetThread().GetProcess()->GetTarget();
Jim Ingham564d8bc22012-03-09 04:10:47 +0000384 uint32_t branch_index;
Ted Woodwarde76e7e92015-05-11 21:12:33 +0000385 branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index, target);
Jim Ingham564d8bc22012-03-09 04:10:47 +0000386
387 Address run_to_address;
388
389 // If we didn't find a branch, run to the end of the range.
390 if (branch_index == UINT32_MAX)
391 {
Jim Ingham0c61dee2013-03-13 01:56:41 +0000392 branch_index = instructions->GetSize() - 1;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000393 }
Jim Ingham0c61dee2013-03-13 01:56:41 +0000394
Jim Ingham564d8bc22012-03-09 04:10:47 +0000395 if (branch_index - pc_index > 1)
396 {
397 const bool is_internal = true;
398 run_to_address = instructions->GetInstructionAtIndex(branch_index)->GetAddress();
Greg Claytoneb023e72013-10-11 19:48:25 +0000399 m_next_branch_bp_sp = GetTarget().CreateBreakpoint(run_to_address, is_internal, false);
Jim Ingham29950772013-01-26 02:19:28 +0000400 if (m_next_branch_bp_sp)
401 {
Jim Ingham0c61dee2013-03-13 01:56:41 +0000402 if (log)
403 {
404 lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
405 BreakpointLocationSP bp_loc = m_next_branch_bp_sp->GetLocationAtIndex(0);
406 if (bp_loc)
407 {
408 BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
409 if (bp_site)
410 {
411 bp_site_id = bp_site->GetID();
412 }
413 }
414 log->Printf ("ThreadPlanStepRange::SetNextBranchBreakpoint - Setting breakpoint %d (site %d) to run to address 0x%" PRIx64,
415 m_next_branch_bp_sp->GetID(),
416 bp_site_id,
417 run_to_address.GetLoadAddress(&m_thread.GetProcess()->GetTarget()));
418 }
Jim Ingham29950772013-01-26 02:19:28 +0000419 m_next_branch_bp_sp->SetThreadID(m_thread.GetID());
420 m_next_branch_bp_sp->SetBreakpointKind ("next-branch-location");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000421 return true;
Jim Ingham29950772013-01-26 02:19:28 +0000422 }
423 else
424 return false;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000425 }
426 }
427 return false;
428}
429
430bool
431ThreadPlanStepRange::NextRangeBreakpointExplainsStop (lldb::StopInfoSP stop_info_sp)
432{
Greg Clayton5160ce52013-03-27 23:08:40 +0000433 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000434 if (!m_next_branch_bp_sp)
435 return false;
436
437 break_id_t bp_site_id = stop_info_sp->GetValue();
438 BreakpointSiteSP bp_site_sp = m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id);
Jim Ingham0c61dee2013-03-13 01:56:41 +0000439 if (!bp_site_sp)
440 return false;
441 else if (!bp_site_sp->IsBreakpointAtThisSite (m_next_branch_bp_sp->GetID()))
Jim Ingham564d8bc22012-03-09 04:10:47 +0000442 return false;
443 else
Jim Ingham0c61dee2013-03-13 01:56:41 +0000444 {
445 // If we've hit the next branch breakpoint, then clear it.
446 size_t num_owners = bp_site_sp->GetNumberOfOwners();
447 bool explains_stop = true;
448 // If all the owners are internal, then we are probably just stepping over this range from multiple threads,
449 // or multiple frames, so we want to continue. If one is not internal, then we should not explain the stop,
450 // and let the user breakpoint handle the stop.
451 for (size_t i = 0; i < num_owners; i++)
452 {
453 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
454 {
455 explains_stop = false;
456 break;
457 }
458 }
459 if (log)
Deepak Panickal99fbc072014-03-03 15:39:47 +0000460 log->Printf ("ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit next range breakpoint which has %" PRIu64 " owners - explains stop: %u.",
461 (uint64_t)num_owners,
Jim Ingham0c61dee2013-03-13 01:56:41 +0000462 explains_stop);
463 ClearNextBranchBreakpoint();
464 return explains_stop;
465 }
Jim Ingham564d8bc22012-03-09 04:10:47 +0000466}
467
468bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469ThreadPlanStepRange::WillStop ()
470{
471 return true;
472}
473
474StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000475ThreadPlanStepRange::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476{
Jim Ingham564d8bc22012-03-09 04:10:47 +0000477 if (m_next_branch_bp_sp)
478 return eStateRunning;
479 else
480 return eStateStepping;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481}
482
483bool
484ThreadPlanStepRange::MischiefManaged ()
485{
Jim Ingham927bfa32012-09-10 23:42:44 +0000486 // If we have pushed some plans between ShouldStop & MischiefManaged, then we're not done...
487 // I do this check first because we might have stepped somewhere that will fool InRange into
488 // thinking it needs to step past the end of that line. This happens, for instance, when stepping
489 // over inlined code that is in the middle of the current line.
490
491 if (!m_no_more_plans)
492 return false;
493
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 bool done = true;
495 if (!IsPlanComplete())
496 {
497 if (InRange())
498 {
499 done = false;
500 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000501 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000503 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
504 if (frame_order != eFrameCompareOlder)
505 {
506 if (m_no_more_plans)
507 done = true;
508 else
509 done = false;
510 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 else
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000512 done = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 }
515
516 if (done)
517 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000518 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 if (log)
520 log->Printf("Completed step through range plan.");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000521 ClearNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 ThreadPlan::MischiefManaged ();
523 return true;
524 }
525 else
526 {
527 return false;
528 }
529
530}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000531
532bool
533ThreadPlanStepRange::IsPlanStale ()
534{
Greg Clayton5160ce52013-03-27 23:08:40 +0000535 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000536 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
537
538 if (frame_order == eFrameCompareOlder)
539 {
540 if (log)
541 {
542 log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've stepped out.");
543 }
544 return true;
545 }
546 else if (frame_order == eFrameCompareEqual && InSymbol())
547 {
548 // If we are not in a place we should step through, we've gotten stale.
549 // One tricky bit here is that some stubs don't push a frame, so we should.
550 // check that we are in the same symbol.
551 if (!InRange())
552 {
553 return true;
554 }
555 }
556 return false;
557}