2010-06-09 00:52:24 +08:00
|
|
|
//===-- ThreadPlanStepRange.cpp ---------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/ThreadPlanStepRange.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2013-03-13 09:56:41 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointSite.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Core/Disassembler.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
|
|
|
#include "lldb/Target/StopInfo.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Target/ThreadPlanRunToAddress.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ThreadPlanStepRange: Step through a stack range, either stepping over or into
|
|
|
|
// based on the value of \a type.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2011-02-08 12:27:50 +08:00
|
|
|
ThreadPlanStepRange::ThreadPlanStepRange (ThreadPlanKind kind,
|
|
|
|
const char *name,
|
|
|
|
Thread &thread,
|
|
|
|
const AddressRange &range,
|
|
|
|
const SymbolContext &addr_context,
|
2014-09-30 07:17:18 +08:00
|
|
|
lldb::RunMode stop_others,
|
|
|
|
bool given_ranges_only) :
|
2010-07-10 10:23:31 +08:00
|
|
|
ThreadPlan (kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_addr_context (addr_context),
|
2011-10-15 08:24:48 +08:00
|
|
|
m_address_ranges (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_stop_others (stop_others),
|
|
|
|
m_stack_id (),
|
2014-08-06 09:49:59 +08:00
|
|
|
m_parent_stack_id(),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_no_more_plans (false),
|
2013-03-13 09:56:41 +08:00
|
|
|
m_first_run_event (true),
|
2014-09-30 07:17:18 +08:00
|
|
|
m_use_fast_step(false),
|
|
|
|
m_given_ranges_only (given_ranges_only)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-08-02 05:50:20 +08:00
|
|
|
m_use_fast_step = GetTarget().GetUseFastStepping();
|
2011-10-15 08:24:48 +08:00
|
|
|
AddRange(range);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
|
2014-08-12 07:57:43 +08:00
|
|
|
StackFrameSP parent_stack = m_thread.GetStackFrameAtIndex(1);
|
|
|
|
if (parent_stack)
|
|
|
|
m_parent_stack_id = parent_stack->GetStackID();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanStepRange::~ThreadPlanStepRange ()
|
|
|
|
{
|
2012-03-09 12:10:47 +08:00
|
|
|
ClearNextBranchBreakpoint();
|
2013-07-31 10:19:15 +08:00
|
|
|
|
|
|
|
size_t num_instruction_ranges = m_instruction_ranges.size();
|
|
|
|
|
|
|
|
// FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
|
|
|
|
// I'll fix that but for now, just clear the list and it will go away nicely.
|
|
|
|
for (size_t i = 0; i < num_instruction_ranges; i++)
|
|
|
|
{
|
|
|
|
if (m_instruction_ranges[i])
|
|
|
|
m_instruction_ranges[i]->GetInstructionList().Clear();
|
|
|
|
}
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlanStepRange::DidPush ()
|
|
|
|
{
|
|
|
|
// See if we can find a "next range" breakpoint:
|
|
|
|
SetNextBranchBreakpoint();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::ValidatePlan (Stream *error)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vote
|
|
|
|
ThreadPlanStepRange::ShouldReportStop (Event *event_ptr)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-09-04 01:10:42 +08:00
|
|
|
|
|
|
|
const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
|
|
|
|
if (log)
|
2011-01-19 05:44:45 +08:00
|
|
|
log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote);
|
2010-09-04 01:10:42 +08:00
|
|
|
return vote;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-10-15 08:24:48 +08:00
|
|
|
void
|
|
|
|
ThreadPlanStepRange::AddRange(const AddressRange &new_range)
|
|
|
|
{
|
|
|
|
// For now I'm just adding the ranges. At some point we may want to
|
|
|
|
// condense the ranges if they overlap, though I don't think it is likely
|
|
|
|
// to be very important.
|
|
|
|
m_address_ranges.push_back (new_range);
|
2013-07-31 10:19:15 +08:00
|
|
|
|
|
|
|
// Fill the slot for this address range with an empty DisassemblerSP in the instruction ranges. I want the
|
|
|
|
// indices to match, but I don't want to do the work to disassemble this range if I don't step into it.
|
2012-03-09 12:10:47 +08:00
|
|
|
m_instruction_ranges.push_back (DisassemblerSP());
|
2011-10-15 08:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlanStepRange::DumpRanges(Stream *s)
|
|
|
|
{
|
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
if (num_ranges == 1)
|
|
|
|
{
|
2012-02-21 08:09:25 +08:00
|
|
|
m_address_ranges[0].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
|
2011-10-15 08:24:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < num_ranges; i++)
|
|
|
|
{
|
2015-07-16 22:21:49 +08:00
|
|
|
s->Printf(" %" PRIu64 ": ", uint64_t(i));
|
2012-02-21 08:09:25 +08:00
|
|
|
m_address_ranges[i].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress);
|
2011-10-15 08:24:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::InRange ()
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-06-09 00:52:24 +08:00
|
|
|
bool ret_value = false;
|
|
|
|
|
|
|
|
lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
|
|
|
|
|
2011-10-15 08:24:48 +08:00
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
for (size_t i = 0; i < num_ranges; i++)
|
|
|
|
{
|
2012-02-21 08:09:25 +08:00
|
|
|
ret_value = m_address_ranges[i].ContainsLoadAddress(pc_load_addr, m_thread.CalculateTarget().get());
|
2011-10-15 08:24:48 +08:00
|
|
|
if (ret_value)
|
|
|
|
break;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
if (!ret_value && !m_given_ranges_only)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// See if we've just stepped to another part of the same line number...
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SymbolContext new_context(frame->GetSymbolContext(eSymbolContextEverything));
|
|
|
|
if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid())
|
|
|
|
{
|
2011-09-24 05:08:11 +08:00
|
|
|
if (m_addr_context.line_entry.file == new_context.line_entry.file)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-09-24 05:08:11 +08:00
|
|
|
if (m_addr_context.line_entry.line == new_context.line_entry.line)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-09-24 05:08:11 +08:00
|
|
|
m_addr_context = new_context;
|
2011-10-15 08:24:48 +08:00
|
|
|
AddRange(m_addr_context.line_entry.range);
|
2011-09-24 05:08:11 +08:00
|
|
|
ret_value = true;
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
2012-09-11 07:42:44 +08:00
|
|
|
m_addr_context.line_entry.Dump (&s,
|
|
|
|
m_thread.CalculateTarget().get(),
|
|
|
|
true,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
true);
|
2011-09-24 05:08:11 +08:00
|
|
|
|
|
|
|
log->Printf ("Step range plan stepped to another range of same line: %s", s.GetData());
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 09:15:46 +08:00
|
|
|
else if (new_context.line_entry.line == 0)
|
|
|
|
{
|
|
|
|
new_context.line_entry.line = m_addr_context.line_entry.line;
|
|
|
|
m_addr_context = new_context;
|
|
|
|
AddRange(m_addr_context.line_entry.range);
|
|
|
|
ret_value = true;
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
|
|
|
m_addr_context.line_entry.Dump (&s,
|
|
|
|
m_thread.CalculateTarget().get(),
|
|
|
|
true,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
true);
|
|
|
|
|
|
|
|
log->Printf ("Step range plan stepped to a range at linenumber 0 stepping through that range: %s", s.GetData());
|
|
|
|
}
|
|
|
|
}
|
2012-02-21 08:09:25 +08:00
|
|
|
else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(m_thread.CalculateTarget().get())
|
2011-09-24 05:08:11 +08:00
|
|
|
!= pc_load_addr)
|
|
|
|
{
|
|
|
|
// Another thing that sometimes happens here is that we step out of one line into the MIDDLE of another
|
|
|
|
// line. So far I mostly see this due to bugs in the debug information.
|
|
|
|
// But we probably don't want to be in the middle of a line range, so in that case reset the stepping
|
|
|
|
// range to the line we've stepped into the middle of and continue.
|
|
|
|
m_addr_context = new_context;
|
2011-10-15 08:24:48 +08:00
|
|
|
m_address_ranges.clear();
|
|
|
|
AddRange(m_addr_context.line_entry.range);
|
2011-09-24 05:08:11 +08:00
|
|
|
ret_value = true;
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
2012-09-11 07:42:44 +08:00
|
|
|
m_addr_context.line_entry.Dump (&s,
|
|
|
|
m_thread.CalculateTarget().get(),
|
|
|
|
true,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
true);
|
2011-09-24 05:08:11 +08:00
|
|
|
|
|
|
|
log->Printf ("Step range plan stepped to the middle of new line(%d): %s, continuing to clear this line.",
|
|
|
|
new_context.line_entry.line,
|
|
|
|
s.GetData());
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2011-09-24 05:08:11 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret_value && log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("Step range plan out of range to 0x%" PRIx64, pc_load_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::InSymbol()
|
|
|
|
{
|
|
|
|
lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
|
|
|
|
if (m_addr_context.function != NULL)
|
|
|
|
{
|
2012-02-21 08:09:25 +08:00
|
|
|
return m_addr_context.function->GetAddressRange().ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2015-06-26 05:46:34 +08:00
|
|
|
else if (m_addr_context.symbol && m_addr_context.symbol->ValueIsAddress())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
AddressRange range(m_addr_context.symbol->GetAddressRef(), m_addr_context.symbol->GetByteSize());
|
2012-03-08 05:03:09 +08:00
|
|
|
return range.ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This should also handle inlining if we aren't going to do inlining in the
|
|
|
|
// main stack.
|
|
|
|
//
|
|
|
|
// Ideally we should remember the whole stack frame list, and then compare that
|
|
|
|
// to the current list.
|
|
|
|
|
2012-03-01 08:50:50 +08:00
|
|
|
lldb::FrameComparison
|
|
|
|
ThreadPlanStepRange::CompareCurrentFrameToStartFrame()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-01 08:50:50 +08:00
|
|
|
FrameComparison frame_order;
|
2010-09-16 08:58:09 +08:00
|
|
|
|
2012-03-01 08:50:50 +08:00
|
|
|
StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
|
2010-09-16 08:58:09 +08:00
|
|
|
|
2012-03-01 08:50:50 +08:00
|
|
|
if (cur_frame_id == m_stack_id)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-01 08:50:50 +08:00
|
|
|
frame_order = eFrameCompareEqual;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-03-01 08:50:50 +08:00
|
|
|
else if (cur_frame_id < m_stack_id)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-01 08:50:50 +08:00
|
|
|
frame_order = eFrameCompareYounger;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-12 07:57:43 +08:00
|
|
|
StackFrameSP cur_parent_frame = m_thread.GetStackFrameAtIndex(1);
|
|
|
|
StackID cur_parent_id;
|
|
|
|
if (cur_parent_frame)
|
|
|
|
cur_parent_id = cur_parent_frame->GetStackID();
|
2014-08-06 09:49:59 +08:00
|
|
|
if (m_parent_stack_id.IsValid()
|
|
|
|
&& cur_parent_id.IsValid()
|
|
|
|
&& m_parent_stack_id == cur_parent_id)
|
|
|
|
frame_order = eFrameCompareSameParent;
|
|
|
|
else
|
|
|
|
frame_order = eFrameCompareOlder;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-03-01 08:50:50 +08:00
|
|
|
return frame_order;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::StopOthers ()
|
|
|
|
{
|
|
|
|
if (m_stop_others == lldb::eOnlyThisThread
|
|
|
|
|| m_stop_others == lldb::eOnlyDuringStepping)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
InstructionList *
|
|
|
|
ThreadPlanStepRange::GetInstructionsForAddress(lldb::addr_t addr, size_t &range_index, size_t &insn_offset)
|
|
|
|
{
|
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
for (size_t i = 0; i < num_ranges; i++)
|
|
|
|
{
|
|
|
|
if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget()))
|
|
|
|
{
|
|
|
|
// Some joker added a zero size range to the stepping range...
|
|
|
|
if (m_address_ranges[i].GetByteSize() == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!m_instruction_ranges[i])
|
|
|
|
{
|
|
|
|
//Disassemble the address range given:
|
|
|
|
ExecutionContext exe_ctx (m_thread.GetProcess());
|
2013-03-02 08:26:47 +08:00
|
|
|
const char *plugin_name = NULL;
|
|
|
|
const char *flavor = NULL;
|
2013-09-13 07:23:35 +08:00
|
|
|
const bool prefer_file_cache = true;
|
2012-03-09 12:10:47 +08:00
|
|
|
m_instruction_ranges[i] = Disassembler::DisassembleRange(GetTarget().GetArchitecture(),
|
2013-03-02 08:26:47 +08:00
|
|
|
plugin_name,
|
|
|
|
flavor,
|
2012-03-09 12:10:47 +08:00
|
|
|
exe_ctx,
|
2013-09-13 07:23:35 +08:00
|
|
|
m_address_ranges[i],
|
|
|
|
prefer_file_cache);
|
2012-03-09 12:10:47 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
if (!m_instruction_ranges[i])
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Find where we are in the instruction list as well. If we aren't at an instruction,
|
|
|
|
// return NULL. In this case, we're probably lost, and shouldn't try to do anything fancy.
|
|
|
|
|
|
|
|
insn_offset = m_instruction_ranges[i]->GetInstructionList().GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
|
|
|
|
if (insn_offset == UINT32_MAX)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
range_index = i;
|
|
|
|
return &m_instruction_ranges[i]->GetInstructionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlanStepRange::ClearNextBranchBreakpoint()
|
|
|
|
{
|
|
|
|
if (m_next_branch_bp_sp)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2013-03-13 09:56:41 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("Removing next branch breakpoint: %d.", m_next_branch_bp_sp->GetID());
|
2012-03-09 12:10:47 +08:00
|
|
|
GetTarget().RemoveBreakpointByID (m_next_branch_bp_sp->GetID());
|
|
|
|
m_next_branch_bp_sp.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::SetNextBranchBreakpoint ()
|
|
|
|
{
|
2013-03-13 09:56:41 +08:00
|
|
|
if (m_next_branch_bp_sp)
|
|
|
|
return true;
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2012-03-09 12:10:47 +08:00
|
|
|
// Stepping through ranges using breakpoints doesn't work yet, but with this off we fall back to instruction
|
|
|
|
// single stepping.
|
2013-03-13 09:56:41 +08:00
|
|
|
if (!m_use_fast_step)
|
|
|
|
return false;
|
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
|
|
|
|
// Find the current address in our address ranges, and fetch the disassembly if we haven't already:
|
|
|
|
size_t pc_index;
|
|
|
|
size_t range_index;
|
|
|
|
InstructionList *instructions = GetInstructionsForAddress (cur_addr, range_index, pc_index);
|
|
|
|
if (instructions == NULL)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
{
|
2015-05-12 05:12:33 +08:00
|
|
|
Target &target = GetThread().GetProcess()->GetTarget();
|
2012-03-09 12:10:47 +08:00
|
|
|
uint32_t branch_index;
|
2015-05-12 05:12:33 +08:00
|
|
|
branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index, target);
|
2012-03-09 12:10:47 +08:00
|
|
|
|
|
|
|
Address run_to_address;
|
|
|
|
|
|
|
|
// If we didn't find a branch, run to the end of the range.
|
|
|
|
if (branch_index == UINT32_MAX)
|
|
|
|
{
|
2013-03-13 09:56:41 +08:00
|
|
|
branch_index = instructions->GetSize() - 1;
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
2013-03-13 09:56:41 +08:00
|
|
|
|
2015-11-13 08:31:21 +08:00
|
|
|
if (branch_index - pc_index > 1)
|
2012-03-09 12:10:47 +08:00
|
|
|
{
|
|
|
|
const bool is_internal = true;
|
2015-11-13 08:31:21 +08:00
|
|
|
run_to_address = instructions->GetInstructionAtIndex(branch_index)->GetAddress();
|
2013-10-12 03:48:25 +08:00
|
|
|
m_next_branch_bp_sp = GetTarget().CreateBreakpoint(run_to_address, is_internal, false);
|
2013-01-26 10:19:28 +08:00
|
|
|
if (m_next_branch_bp_sp)
|
|
|
|
{
|
2013-03-13 09:56:41 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
|
|
|
|
BreakpointLocationSP bp_loc = m_next_branch_bp_sp->GetLocationAtIndex(0);
|
|
|
|
if (bp_loc)
|
|
|
|
{
|
|
|
|
BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
|
|
|
|
if (bp_site)
|
|
|
|
{
|
|
|
|
bp_site_id = bp_site->GetID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log->Printf ("ThreadPlanStepRange::SetNextBranchBreakpoint - Setting breakpoint %d (site %d) to run to address 0x%" PRIx64,
|
|
|
|
m_next_branch_bp_sp->GetID(),
|
|
|
|
bp_site_id,
|
|
|
|
run_to_address.GetLoadAddress(&m_thread.GetProcess()->GetTarget()));
|
|
|
|
}
|
2013-01-26 10:19:28 +08:00
|
|
|
m_next_branch_bp_sp->SetThreadID(m_thread.GetID());
|
|
|
|
m_next_branch_bp_sp->SetBreakpointKind ("next-branch-location");
|
2013-03-13 09:56:41 +08:00
|
|
|
return true;
|
2013-01-26 10:19:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::NextRangeBreakpointExplainsStop (lldb::StopInfoSP stop_info_sp)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2012-03-09 12:10:47 +08:00
|
|
|
if (!m_next_branch_bp_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break_id_t bp_site_id = stop_info_sp->GetValue();
|
|
|
|
BreakpointSiteSP bp_site_sp = m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id);
|
2013-03-13 09:56:41 +08:00
|
|
|
if (!bp_site_sp)
|
|
|
|
return false;
|
|
|
|
else if (!bp_site_sp->IsBreakpointAtThisSite (m_next_branch_bp_sp->GetID()))
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
|
|
|
else
|
2013-03-13 09:56:41 +08:00
|
|
|
{
|
|
|
|
// If we've hit the next branch breakpoint, then clear it.
|
|
|
|
size_t num_owners = bp_site_sp->GetNumberOfOwners();
|
|
|
|
bool explains_stop = true;
|
|
|
|
// If all the owners are internal, then we are probably just stepping over this range from multiple threads,
|
|
|
|
// or multiple frames, so we want to continue. If one is not internal, then we should not explain the stop,
|
|
|
|
// and let the user breakpoint handle the stop.
|
|
|
|
for (size_t i = 0; i < num_owners; i++)
|
|
|
|
{
|
|
|
|
if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
|
|
|
|
{
|
|
|
|
explains_stop = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (log)
|
2014-03-03 23:39:47 +08:00
|
|
|
log->Printf ("ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit next range breakpoint which has %" PRIu64 " owners - explains stop: %u.",
|
|
|
|
(uint64_t)num_owners,
|
2013-03-13 09:56:41 +08:00
|
|
|
explains_stop);
|
|
|
|
ClearNextBranchBreakpoint();
|
|
|
|
return explains_stop;
|
|
|
|
}
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::WillStop ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StateType
|
2010-11-12 03:26:09 +08:00
|
|
|
ThreadPlanStepRange::GetPlanRunState ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-09 12:10:47 +08:00
|
|
|
if (m_next_branch_bp_sp)
|
|
|
|
return eStateRunning;
|
|
|
|
else
|
|
|
|
return eStateStepping;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::MischiefManaged ()
|
|
|
|
{
|
2012-09-11 07:42:44 +08:00
|
|
|
// If we have pushed some plans between ShouldStop & MischiefManaged, then we're not done...
|
|
|
|
// I do this check first because we might have stepped somewhere that will fool InRange into
|
|
|
|
// thinking it needs to step past the end of that line. This happens, for instance, when stepping
|
|
|
|
// over inlined code that is in the middle of the current line.
|
|
|
|
|
|
|
|
if (!m_no_more_plans)
|
|
|
|
return false;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool done = true;
|
|
|
|
if (!IsPlanComplete())
|
|
|
|
{
|
|
|
|
if (InRange())
|
|
|
|
{
|
|
|
|
done = false;
|
|
|
|
}
|
2012-03-01 08:50:50 +08:00
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-01 08:50:50 +08:00
|
|
|
FrameComparison frame_order = CompareCurrentFrameToStartFrame();
|
|
|
|
if (frame_order != eFrameCompareOlder)
|
|
|
|
{
|
|
|
|
if (m_no_more_plans)
|
|
|
|
done = true;
|
|
|
|
else
|
|
|
|
done = false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2012-03-01 08:50:50 +08:00
|
|
|
done = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Completed step through range plan.");
|
2013-03-13 09:56:41 +08:00
|
|
|
ClearNextBranchBreakpoint();
|
2010-06-09 00:52:24 +08:00
|
|
|
ThreadPlan::MischiefManaged ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-05-04 05:19:36 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepRange::IsPlanStale ()
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2012-05-04 05:19:36 +08:00
|
|
|
FrameComparison frame_order = CompareCurrentFrameToStartFrame();
|
|
|
|
|
|
|
|
if (frame_order == eFrameCompareOlder)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've stepped out.");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (frame_order == eFrameCompareEqual && InSymbol())
|
|
|
|
{
|
|
|
|
// If we are not in a place we should step through, we've gotten stale.
|
|
|
|
// One tricky bit here is that some stubs don't push a frame, so we should.
|
|
|
|
// check that we are in the same symbol.
|
|
|
|
if (!InRange())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|