2010-06-09 00:52:24 +08:00
|
|
|
//===-- ThreadPlanStepInstruction.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/ThreadPlanStepInstruction.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/StopInfo.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ThreadPlanStepInstruction: Step over the current instruction
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
ThreadPlanStepInstruction::ThreadPlanStepInstruction
|
|
|
|
(
|
|
|
|
Thread &thread,
|
|
|
|
bool step_over,
|
|
|
|
bool stop_other_threads,
|
|
|
|
Vote stop_vote,
|
|
|
|
Vote run_vote
|
|
|
|
) :
|
2010-06-19 12:45:32 +08:00
|
|
|
ThreadPlan (ThreadPlan::eKindStepInstruction, "Step over single instruction", thread, stop_vote, run_vote),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_instruction_addr (0),
|
2010-07-16 20:32:33 +08:00
|
|
|
m_stop_other_threads (stop_other_threads),
|
2012-03-02 04:01:22 +08:00
|
|
|
m_step_over (step_over)
|
2014-07-09 03:28:57 +08:00
|
|
|
{
|
|
|
|
m_takes_iteration_count = true;
|
|
|
|
SetUpState();
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanStepInstruction::~ThreadPlanStepInstruction ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlanStepInstruction::SetUpState()
|
2010-07-16 20:32:33 +08:00
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
m_instruction_addr = m_thread.GetRegisterContext()->GetPC(0);
|
2014-07-09 03:28:57 +08:00
|
|
|
StackFrameSP start_frame_sp(m_thread.GetStackFrameAtIndex(0));
|
|
|
|
m_stack_id = start_frame_sp->GetStackID();
|
2013-07-26 08:27:57 +08:00
|
|
|
|
2014-07-09 03:28:57 +08:00
|
|
|
m_start_has_symbol = start_frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol != NULL;
|
2013-07-26 08:27:57 +08:00
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP parent_frame_sp = m_thread.GetStackFrameAtIndex(1);
|
2013-07-25 08:59:01 +08:00
|
|
|
if (parent_frame_sp)
|
|
|
|
m_parent_frame_id = parent_frame_sp->GetStackID();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlanStepInstruction::GetDescription (Stream *s, lldb::DescriptionLevel level)
|
|
|
|
{
|
|
|
|
if (level == lldb::eDescriptionLevelBrief)
|
|
|
|
{
|
|
|
|
if (m_step_over)
|
|
|
|
s->Printf ("instruction step over");
|
|
|
|
else
|
|
|
|
s->Printf ("instruction step into");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s->Printf ("Stepping one instruction past ");
|
|
|
|
s->Address(m_instruction_addr, sizeof (addr_t));
|
2013-07-26 08:27:57 +08:00
|
|
|
if (!m_start_has_symbol)
|
|
|
|
s->Printf(" which has no symbol");
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_step_over)
|
|
|
|
s->Printf(" stepping over calls");
|
|
|
|
else
|
|
|
|
s->Printf(" stepping into calls");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::ValidatePlan (Stream *error)
|
|
|
|
{
|
|
|
|
// Since we read the instruction we're stepping over from the thread,
|
|
|
|
// this plan will always work.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 08:35:16 +08:00
|
|
|
ThreadPlanStepInstruction::DoPlanExplainsStop (Event *event_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-06-04 09:40:51 +08:00
|
|
|
StopInfoSP stop_info_sp = GetPrivateStopInfo ();
|
2010-10-20 08:39:53 +08:00
|
|
|
if (stop_info_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-20 08:39:53 +08:00
|
|
|
StopReason reason = stop_info_sp->GetStopReason();
|
2010-08-04 09:40:35 +08:00
|
|
|
if (reason == eStopReasonTrace || reason == eStopReasonNone)
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-09 03:28:57 +08:00
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::IsPlanStale ()
|
|
|
|
{
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
|
|
|
StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
|
|
|
|
if (cur_frame_id == m_stack_id)
|
|
|
|
{
|
|
|
|
if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (cur_frame_id < m_stack_id)
|
|
|
|
{
|
|
|
|
// If the current frame is younger than the start frame and we are stepping over, then we need to continue,
|
|
|
|
// but if we are doing just one step, we're done.
|
|
|
|
if (m_step_over)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("ThreadPlanStepInstruction::IsPlanStale - Current frame is older than start frame, plan is stale.");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::ShouldStop (Event *event_ptr)
|
|
|
|
{
|
|
|
|
if (m_step_over)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2012-03-02 04:01:22 +08:00
|
|
|
|
2014-11-21 06:04:45 +08:00
|
|
|
StackFrameSP cur_frame_sp = m_thread.GetStackFrameAtIndex(0);
|
|
|
|
if (!cur_frame_sp)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("ThreadPlanStepInstruction couldn't get the 0th frame, stopping.");
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StackID cur_frame_zero_id = cur_frame_sp->GetStackID();
|
2012-03-02 04:01:22 +08:00
|
|
|
|
|
|
|
if (cur_frame_zero_id == m_stack_id || m_stack_id < cur_frame_zero_id)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
|
|
|
|
{
|
2014-07-09 03:28:57 +08:00
|
|
|
if (--m_iteration_count <= 0)
|
|
|
|
{
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We are still stepping, reset the start pc, and in case we've stepped out,
|
|
|
|
// reset the current stack id.
|
|
|
|
SetUpState();
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We've stepped in, step back out again:
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrame *return_frame = m_thread.GetStackFrameAtIndex(1).get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (return_frame)
|
|
|
|
{
|
2013-07-26 08:27:57 +08:00
|
|
|
if (return_frame->GetStackID() != m_parent_frame_id || m_start_has_symbol)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2014-11-21 06:04:45 +08:00
|
|
|
// next-instruction shouldn't step out of inlined functions. But we may have stepped into a
|
|
|
|
// real function that starts with an inlined function, and we do want to step out of that...
|
|
|
|
|
|
|
|
if (cur_frame_sp->IsInlined())
|
|
|
|
{
|
|
|
|
StackFrameSP parent_frame_sp = m_thread.GetFrameWithStackID(m_stack_id);
|
|
|
|
|
|
|
|
if(parent_frame_sp && parent_frame_sp->GetConcreteFrameIndex() == cur_frame_sp->GetConcreteFrameIndex())
|
|
|
|
{
|
|
|
|
SetPlanComplete();
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf("Frame we stepped into is inlined into the frame we were stepping from, stopping.");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 08:59:01 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
|
|
|
s.PutCString ("Stepped in to: ");
|
|
|
|
addr_t stop_addr = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
|
|
|
|
s.Address (stop_addr, m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
|
|
|
|
s.PutCString (" stepping out to: ");
|
|
|
|
addr_t return_addr = return_frame->GetRegisterContext()->GetPC();
|
|
|
|
s.Address (return_addr, m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
|
|
|
|
log->Printf("%s.", s.GetData());
|
|
|
|
}
|
|
|
|
|
|
|
|
// StepInstruction should probably have the tri-state RunMode, but for now it is safer to
|
|
|
|
// run others.
|
|
|
|
const bool stop_others = false;
|
2014-03-13 10:47:14 +08:00
|
|
|
m_thread.QueueThreadPlanForStepOutNoShouldStop(false,
|
|
|
|
NULL,
|
|
|
|
true,
|
|
|
|
stop_others,
|
|
|
|
eVoteNo,
|
|
|
|
eVoteNoOpinion,
|
|
|
|
0);
|
2013-07-25 08:59:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
2013-07-26 08:27:57 +08:00
|
|
|
log->PutCString("The stack id we are stepping in changed, but our parent frame did not when stepping from code with no symbols. "
|
2013-07-25 08:59:01 +08:00
|
|
|
"We are probably just confused about where we are, stopping.");
|
|
|
|
}
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Could not find previous frame, stopping.");
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
|
|
|
|
{
|
2014-07-09 03:28:57 +08:00
|
|
|
if (--m_iteration_count <= 0)
|
|
|
|
{
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We are still stepping, reset the start pc, and in case we've stepped in or out,
|
|
|
|
// reset the current stack id.
|
|
|
|
SetUpState();
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::StopOthers ()
|
|
|
|
{
|
|
|
|
return m_stop_other_threads;
|
|
|
|
}
|
|
|
|
|
|
|
|
StateType
|
2010-11-12 03:26:09 +08:00
|
|
|
ThreadPlanStepInstruction::GetPlanRunState ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return eStateStepping;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::WillStop ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::MischiefManaged ()
|
|
|
|
{
|
|
|
|
if (IsPlanComplete())
|
|
|
|
{
|
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 single instruction step plan.");
|
|
|
|
ThreadPlan::MischiefManaged ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|