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/lldb-private-log.h"
|
|
|
|
#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),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_step_over (step_over),
|
2010-07-16 20:32:33 +08:00
|
|
|
m_stack_depth (0)
|
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
m_instruction_addr = m_thread.GetRegisterContext()->GetPC(0);
|
|
|
|
m_stack_depth = m_thread.GetStackFrameCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanStepInstruction::~ThreadPlanStepInstruction ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
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
|
|
|
|
ThreadPlanStepInstruction::PlanExplainsStop ()
|
|
|
|
{
|
2010-10-20 08:39:53 +08:00
|
|
|
StopInfoSP stop_info_sp = GetPrivateStopReason();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanStepInstruction::ShouldStop (Event *event_ptr)
|
|
|
|
{
|
|
|
|
if (m_step_over)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_thread.GetStackFrameCount() <= m_stack_depth)
|
|
|
|
{
|
|
|
|
if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
|
|
|
|
{
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We've stepped in, step back out again:
|
|
|
|
StackFrame *return_frame = m_thread.GetStackFrameAtIndex(1).get();
|
|
|
|
if (return_frame)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
|
|
|
s.PutCString ("Stepped in to: ");
|
2010-08-25 05:05:24 +08:00
|
|
|
addr_t stop_addr = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
|
2010-06-09 00:52:24 +08:00
|
|
|
s.Address (stop_addr, m_thread.GetProcess().GetAddressByteSize());
|
|
|
|
s.PutCString (" stepping out to: ");
|
2010-08-25 05:05:24 +08:00
|
|
|
addr_t return_addr = return_frame->GetRegisterContext()->GetPC();
|
2010-06-09 00:52:24 +08:00
|
|
|
s.Address (return_addr, m_thread.GetProcess().GetAddressByteSize());
|
|
|
|
log->Printf("%s.", s.GetData());
|
|
|
|
}
|
|
|
|
m_thread.QueueThreadPlanForStepOut(false, NULL, true, m_stop_other_threads, eVoteNo, eVoteNoOpinion);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Could not find previous frame, stopping.");
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
|
|
|
|
{
|
|
|
|
SetPlanComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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())
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|