blob: 02667f8236ea2a6f7ad2ebbe1c72181435503038 [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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000014#include "lldb/Target/ThreadPlanStepRange.h"
Jim Ingham0c61dee2013-03-13 01:56:41 +000015#include "lldb/Breakpoint/BreakpointLocation.h"
16#include "lldb/Breakpoint/BreakpointSite.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000017#include "lldb/Core/Disassembler.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/Log.h"
19#include "lldb/Core/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Symbol/Function.h"
21#include "lldb/Symbol/Symbol.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000022#include "lldb/Target/ExecutionContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000023#include "lldb/Target/Process.h"
24#include "lldb/Target/RegisterContext.h"
25#include "lldb/Target/StopInfo.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000026#include "lldb/Target/Target.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000027#include "lldb/Target/Thread.h"
Jim Ingham564d8bc22012-03-09 04:10:47 +000028#include "lldb/Target/ThreadPlanRunToAddress.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
30using namespace lldb;
31using namespace lldb_private;
32
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033//----------------------------------------------------------------------
34// ThreadPlanStepRange: Step through a stack range, either stepping over or into
35// based on the value of \a type.
36//----------------------------------------------------------------------
37
Jim Ingham242e0ad2011-02-08 04:27:50 +000038ThreadPlanStepRange::ThreadPlanStepRange (ThreadPlanKind kind,
39 const char *name,
40 Thread &thread,
41 const AddressRange &range,
42 const SymbolContext &addr_context,
Jim Ingham2bdbfd52014-09-29 23:17:18 +000043 lldb::RunMode stop_others,
44 bool given_ranges_only) :
Jim Ingham35b21fe2010-07-10 02:23:31 +000045 ThreadPlan (kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 m_addr_context (addr_context),
Jim Inghamc4c9fed2011-10-15 00:24:48 +000047 m_address_ranges (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 m_stop_others (stop_others),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049 m_stack_id (),
Jim Ingham862d1bb2014-08-06 01:49:59 +000050 m_parent_stack_id(),
Greg Claytonc982c762010-07-09 20:39:50 +000051 m_no_more_plans (false),
Jim Ingham0c61dee2013-03-13 01:56:41 +000052 m_first_run_event (true),
Jim Ingham2bdbfd52014-09-29 23:17:18 +000053 m_use_fast_step(false),
54 m_given_ranges_only (given_ranges_only)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055{
Jason Molenda975abff2013-08-01 21:50:20 +000056 m_use_fast_step = GetTarget().GetUseFastStepping();
Jim Inghamc4c9fed2011-10-15 00:24:48 +000057 AddRange(range);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058 m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham76447852014-08-11 23:57:43 +000059 StackFrameSP parent_stack = m_thread.GetStackFrameAtIndex(1);
60 if (parent_stack)
61 m_parent_stack_id = parent_stack->GetStackID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062}
63
64ThreadPlanStepRange::~ThreadPlanStepRange ()
65{
Jim Ingham564d8bc22012-03-09 04:10:47 +000066 ClearNextBranchBreakpoint();
Jim Ingham56d40422013-07-31 02:19:15 +000067
68 size_t num_instruction_ranges = m_instruction_ranges.size();
69
70 // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
71 // I'll fix that but for now, just clear the list and it will go away nicely.
72 for (size_t i = 0; i < num_instruction_ranges; i++)
73 {
74 if (m_instruction_ranges[i])
75 m_instruction_ranges[i]->GetInstructionList().Clear();
76 }
Jim Ingham564d8bc22012-03-09 04:10:47 +000077}
78
79void
80ThreadPlanStepRange::DidPush ()
81{
82 // See if we can find a "next range" breakpoint:
83 SetNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084}
85
86bool
87ThreadPlanStepRange::ValidatePlan (Stream *error)
88{
89 return true;
90}
91
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092Vote
93ThreadPlanStepRange::ShouldReportStop (Event *event_ptr)
94{
Greg Clayton5160ce52013-03-27 23:08:40 +000095 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton2cad65a2010-09-03 17:10:42 +000096
97 const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
98 if (log)
Greg Clayton411c0ce2011-01-18 21:44:45 +000099 log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000100 return vote;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101}
102
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000103void
104ThreadPlanStepRange::AddRange(const AddressRange &new_range)
105{
106 // For now I'm just adding the ranges. At some point we may want to
107 // condense the ranges if they overlap, though I don't think it is likely
108 // to be very important.
109 m_address_ranges.push_back (new_range);
Jim Ingham56d40422013-07-31 02:19:15 +0000110
111 // Fill the slot for this address range with an empty DisassemblerSP in the instruction ranges. I want the
112 // 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 +0000113 m_instruction_ranges.push_back (DisassemblerSP());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000114}
115
116void
117ThreadPlanStepRange::DumpRanges(Stream *s)
118{
119 size_t num_ranges = m_address_ranges.size();
120 if (num_ranges == 1)
121 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000122 m_address_ranges[0].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000123 }
124 else
125 {
126 for (size_t i = 0; i < num_ranges; i++)
127 {
Pavel Labath8c0970f2015-07-16 14:21:49 +0000128 s->Printf(" %" PRIu64 ": ", uint64_t(i));
Greg Clayton1ac04c32012-02-21 00:09:25 +0000129 m_address_ranges[i].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000130 }
131 }
132}
133
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134bool
135ThreadPlanStepRange::InRange ()
136{
Greg Clayton5160ce52013-03-27 23:08:40 +0000137 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 bool ret_value = false;
139
140 lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
141
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000142 size_t num_ranges = m_address_ranges.size();
143 for (size_t i = 0; i < num_ranges; i++)
144 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000145 ret_value = m_address_ranges[i].ContainsLoadAddress(pc_load_addr, m_thread.CalculateTarget().get());
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000146 if (ret_value)
147 break;
148 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000150 if (!ret_value && !m_given_ranges_only)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151 {
152 // See if we've just stepped to another part of the same line number...
Jason Molendab57e4a12013-11-04 09:33:30 +0000153 StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154
155 SymbolContext new_context(frame->GetSymbolContext(eSymbolContextEverything));
156 if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid())
157 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000158 if (m_addr_context.line_entry.file == new_context.line_entry.file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000160 if (m_addr_context.line_entry.line == new_context.line_entry.line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 {
Jim Ingham843bfb22011-09-23 21:08:11 +0000162 m_addr_context = new_context;
Jason Molenda25d5b102015-12-15 00:40:30 +0000163 AddRange(m_addr_context.line_entry.GetSameLineContiguousAddressRange());
Jim Ingham843bfb22011-09-23 21:08:11 +0000164 ret_value = true;
165 if (log)
166 {
167 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000168 m_addr_context.line_entry.Dump (&s,
169 m_thread.CalculateTarget().get(),
170 true,
171 Address::DumpStyleLoadAddress,
172 Address::DumpStyleLoadAddress,
173 true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174
Jim Ingham843bfb22011-09-23 21:08:11 +0000175 log->Printf ("Step range plan stepped to another range of same line: %s", s.GetData());
176 }
177 }
Jim Ingham2b89a532013-09-27 01:15:46 +0000178 else if (new_context.line_entry.line == 0)
179 {
180 new_context.line_entry.line = m_addr_context.line_entry.line;
181 m_addr_context = new_context;
Jason Molenda25d5b102015-12-15 00:40:30 +0000182 AddRange(m_addr_context.line_entry.GetSameLineContiguousAddressRange());
Jim Ingham2b89a532013-09-27 01:15:46 +0000183 ret_value = true;
184 if (log)
185 {
186 StreamString s;
187 m_addr_context.line_entry.Dump (&s,
188 m_thread.CalculateTarget().get(),
189 true,
190 Address::DumpStyleLoadAddress,
191 Address::DumpStyleLoadAddress,
192 true);
193
194 log->Printf ("Step range plan stepped to a range at linenumber 0 stepping through that range: %s", s.GetData());
195 }
196 }
Greg Clayton1ac04c32012-02-21 00:09:25 +0000197 else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(m_thread.CalculateTarget().get())
Jim Ingham843bfb22011-09-23 21:08:11 +0000198 != pc_load_addr)
199 {
200 // Another thing that sometimes happens here is that we step out of one line into the MIDDLE of another
201 // line. So far I mostly see this due to bugs in the debug information.
202 // But we probably don't want to be in the middle of a line range, so in that case reset the stepping
203 // range to the line we've stepped into the middle of and continue.
204 m_addr_context = new_context;
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000205 m_address_ranges.clear();
206 AddRange(m_addr_context.line_entry.range);
Jim Ingham843bfb22011-09-23 21:08:11 +0000207 ret_value = true;
208 if (log)
209 {
210 StreamString s;
Jim Ingham927bfa32012-09-10 23:42:44 +0000211 m_addr_context.line_entry.Dump (&s,
212 m_thread.CalculateTarget().get(),
213 true,
214 Address::DumpStyleLoadAddress,
215 Address::DumpStyleLoadAddress,
216 true);
Jim Ingham843bfb22011-09-23 21:08:11 +0000217
218 log->Printf ("Step range plan stepped to the middle of new line(%d): %s, continuing to clear this line.",
219 new_context.line_entry.line,
220 s.GetData());
221 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000222 }
223 }
224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 }
226
227 if (!ret_value && log)
Daniel Malead01b2952012-11-29 21:49:15 +0000228 log->Printf ("Step range plan out of range to 0x%" PRIx64, pc_load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229
230 return ret_value;
231}
232
233bool
234ThreadPlanStepRange::InSymbol()
235{
236 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000237 if (m_addr_context.function != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000239 return m_addr_context.function->GetAddressRange().ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 }
Greg Clayton358cf1e2015-06-25 21:46:34 +0000241 else if (m_addr_context.symbol && m_addr_context.symbol->ValueIsAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242 {
Greg Clayton358cf1e2015-06-25 21:46:34 +0000243 AddressRange range(m_addr_context.symbol->GetAddressRef(), m_addr_context.symbol->GetByteSize());
Greg Claytone7612132012-03-07 21:03:09 +0000244 return range.ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 }
246 return false;
247}
248
249// FIXME: This should also handle inlining if we aren't going to do inlining in the
250// main stack.
251//
252// Ideally we should remember the whole stack frame list, and then compare that
253// to the current list.
254
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000255lldb::FrameComparison
256ThreadPlanStepRange::CompareCurrentFrameToStartFrame()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257{
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000258 FrameComparison frame_order;
Jim Ingham7ce490c2010-09-16 00:58:09 +0000259
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000260 StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Jim Ingham7ce490c2010-09-16 00:58:09 +0000261
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000262 if (cur_frame_id == m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000264 frame_order = eFrameCompareEqual;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000266 else if (cur_frame_id < m_stack_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000268 frame_order = eFrameCompareYounger;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 }
270 else
271 {
Jim Ingham76447852014-08-11 23:57:43 +0000272 StackFrameSP cur_parent_frame = m_thread.GetStackFrameAtIndex(1);
273 StackID cur_parent_id;
274 if (cur_parent_frame)
275 cur_parent_id = cur_parent_frame->GetStackID();
Jim Ingham862d1bb2014-08-06 01:49:59 +0000276 if (m_parent_stack_id.IsValid()
277 && cur_parent_id.IsValid()
278 && m_parent_stack_id == cur_parent_id)
279 frame_order = eFrameCompareSameParent;
280 else
281 frame_order = eFrameCompareOlder;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 }
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000283 return frame_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284}
285
286bool
287ThreadPlanStepRange::StopOthers ()
288{
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000289 return (m_stop_others == lldb::eOnlyThisThread || m_stop_others == lldb::eOnlyDuringStepping);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290}
291
Jim Ingham564d8bc22012-03-09 04:10:47 +0000292InstructionList *
293ThreadPlanStepRange::GetInstructionsForAddress(lldb::addr_t addr, size_t &range_index, size_t &insn_offset)
294{
295 size_t num_ranges = m_address_ranges.size();
296 for (size_t i = 0; i < num_ranges; i++)
297 {
298 if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget()))
299 {
300 // Some joker added a zero size range to the stepping range...
301 if (m_address_ranges[i].GetByteSize() == 0)
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000302 return nullptr;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000303
304 if (!m_instruction_ranges[i])
305 {
306 //Disassemble the address range given:
307 ExecutionContext exe_ctx (m_thread.GetProcess());
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000308 const char *plugin_name = nullptr;
309 const char *flavor = nullptr;
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000310 const bool prefer_file_cache = true;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000311 m_instruction_ranges[i] = Disassembler::DisassembleRange(GetTarget().GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000312 plugin_name,
313 flavor,
Jim Ingham564d8bc22012-03-09 04:10:47 +0000314 exe_ctx,
Jason Molenda6b3e6d52013-09-12 23:23:35 +0000315 m_address_ranges[i],
316 prefer_file_cache);
Jim Ingham564d8bc22012-03-09 04:10:47 +0000317 }
318 if (!m_instruction_ranges[i])
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000319 return nullptr;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000320 else
321 {
322 // Find where we are in the instruction list as well. If we aren't at an instruction,
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000323 // return nullptr. In this case, we're probably lost, and shouldn't try to do anything fancy.
Jim Ingham564d8bc22012-03-09 04:10:47 +0000324
325 insn_offset = m_instruction_ranges[i]->GetInstructionList().GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
326 if (insn_offset == UINT32_MAX)
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000327 return nullptr;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000328 else
329 {
330 range_index = i;
331 return &m_instruction_ranges[i]->GetInstructionList();
332 }
333 }
334 }
335 }
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000336 return nullptr;
Jim Ingham564d8bc22012-03-09 04:10:47 +0000337}
338
339void
340ThreadPlanStepRange::ClearNextBranchBreakpoint()
341{
342 if (m_next_branch_bp_sp)
343 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000344 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham0c61dee2013-03-13 01:56:41 +0000345 if (log)
346 log->Printf ("Removing next branch breakpoint: %d.", m_next_branch_bp_sp->GetID());
Jim Ingham564d8bc22012-03-09 04:10:47 +0000347 GetTarget().RemoveBreakpointByID (m_next_branch_bp_sp->GetID());
348 m_next_branch_bp_sp.reset();
349 }
350}
351
352bool
353ThreadPlanStepRange::SetNextBranchBreakpoint ()
354{
Jim Ingham0c61dee2013-03-13 01:56:41 +0000355 if (m_next_branch_bp_sp)
356 return true;
357
Greg Clayton5160ce52013-03-27 23:08:40 +0000358 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham564d8bc22012-03-09 04:10:47 +0000359 // Stepping through ranges using breakpoints doesn't work yet, but with this off we fall back to instruction
360 // single stepping.
Jim Ingham0c61dee2013-03-13 01:56:41 +0000361 if (!m_use_fast_step)
362 return false;
363
Jim Ingham564d8bc22012-03-09 04:10:47 +0000364 lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
365 // Find the current address in our address ranges, and fetch the disassembly if we haven't already:
366 size_t pc_index;
367 size_t range_index;
368 InstructionList *instructions = GetInstructionsForAddress (cur_addr, range_index, pc_index);
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000369 if (instructions == nullptr)
Jim Ingham564d8bc22012-03-09 04:10:47 +0000370 return false;
371 else
372 {
Ted Woodwarde76e7e92015-05-11 21:12:33 +0000373 Target &target = GetThread().GetProcess()->GetTarget();
Jim Ingham564d8bc22012-03-09 04:10:47 +0000374 uint32_t branch_index;
Ted Woodwarde76e7e92015-05-11 21:12:33 +0000375 branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index, target);
Jim Ingham564d8bc22012-03-09 04:10:47 +0000376
377 Address run_to_address;
378
379 // If we didn't find a branch, run to the end of the range.
380 if (branch_index == UINT32_MAX)
381 {
Jim Inghama3f466b2015-11-13 03:37:48 +0000382 uint32_t last_index = instructions->GetSize() - 1;
383 if (last_index - pc_index > 1)
384 {
385 InstructionSP last_inst = instructions->GetInstructionAtIndex(last_index);
386 size_t last_inst_size = last_inst->GetOpcode().GetByteSize();
387 run_to_address = last_inst->GetAddress();
388 run_to_address.Slide(last_inst_size);
389 }
390 }
391 else if (branch_index - pc_index > 1)
392 {
393 run_to_address = instructions->GetInstructionAtIndex(branch_index)->GetAddress();
Jim Ingham564d8bc22012-03-09 04:10:47 +0000394 }
Jim Ingham0c61dee2013-03-13 01:56:41 +0000395
Jim Inghama3f466b2015-11-13 03:37:48 +0000396 if (run_to_address.IsValid())
Jim Ingham564d8bc22012-03-09 04:10:47 +0000397 {
398 const bool is_internal = true;
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();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000504 done = (frame_order != eFrameCompareOlder) ? m_no_more_plans : true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 }
507
508 if (done)
509 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000510 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 if (log)
512 log->Printf("Completed step through range plan.");
Jim Ingham0c61dee2013-03-13 01:56:41 +0000513 ClearNextBranchBreakpoint();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 ThreadPlan::MischiefManaged ();
515 return true;
516 }
517 else
518 {
519 return false;
520 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000522
523bool
524ThreadPlanStepRange::IsPlanStale ()
525{
Greg Clayton5160ce52013-03-27 23:08:40 +0000526 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000527 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
528
529 if (frame_order == eFrameCompareOlder)
530 {
531 if (log)
532 {
533 log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've stepped out.");
534 }
535 return true;
536 }
537 else if (frame_order == eFrameCompareEqual && InSymbol())
538 {
539 // If we are not in a place we should step through, we've gotten stale.
540 // One tricky bit here is that some stubs don't push a frame, so we should.
541 // check that we are in the same symbol.
542 if (!InRange())
543 {
544 return true;
545 }
546 }
547 return false;
548}