1 //===-- ThreadPlanStepInstruction.cpp ---------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "lldb/Target/ThreadPlanStepInstruction.h"
15 // Other libraries and framework includes
17 #include "lldb/lldb-private-log.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Core/Stream.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Target/RegisterContext.h"
22 #include "lldb/Target/RegisterContext.h"
23 #include "lldb/Target/StopInfo.h"
24 #include "lldb/Target/Target.h"
27 using namespace lldb_private;
29 //----------------------------------------------------------------------
30 // ThreadPlanStepInstruction: Step over the current instruction
31 //----------------------------------------------------------------------
33 ThreadPlanStepInstruction::ThreadPlanStepInstruction
37 bool stop_other_threads,
41 ThreadPlan (ThreadPlan::eKindStepInstruction, "Step over single instruction", thread, stop_vote, run_vote),
42 m_instruction_addr (0),
43 m_stop_other_threads (stop_other_threads),
44 m_step_over (step_over)
46 m_instruction_addr = m_thread.GetRegisterContext()->GetPC(0);
47 StackFrameSP m_start_frame_sp(m_thread.GetStackFrameAtIndex(0));
48 m_stack_id = m_start_frame_sp->GetStackID();
50 m_start_has_symbol = m_start_frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol != NULL;
52 StackFrameSP parent_frame_sp = m_thread.GetStackFrameAtIndex(1);
54 m_parent_frame_id = parent_frame_sp->GetStackID();
57 ThreadPlanStepInstruction::~ThreadPlanStepInstruction ()
62 ThreadPlanStepInstruction::GetDescription (Stream *s, lldb::DescriptionLevel level)
64 if (level == lldb::eDescriptionLevelBrief)
67 s->Printf ("instruction step over");
69 s->Printf ("instruction step into");
73 s->Printf ("Stepping one instruction past ");
74 s->Address(m_instruction_addr, sizeof (addr_t));
75 if (!m_start_has_symbol)
76 s->Printf(" which has no symbol");
79 s->Printf(" stepping over calls");
81 s->Printf(" stepping into calls");
86 ThreadPlanStepInstruction::ValidatePlan (Stream *error)
88 // Since we read the instruction we're stepping over from the thread,
89 // this plan will always work.
94 ThreadPlanStepInstruction::DoPlanExplainsStop (Event *event_ptr)
96 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
99 StopReason reason = stop_info_sp->GetStopReason();
100 if (reason == eStopReasonTrace || reason == eStopReasonNone)
109 ThreadPlanStepInstruction::ShouldStop (Event *event_ptr)
113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
115 StackID cur_frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
117 if (cur_frame_zero_id == m_stack_id || m_stack_id < cur_frame_zero_id)
119 if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
129 // We've stepped in, step back out again:
130 StackFrame *return_frame = m_thread.GetStackFrameAtIndex(1).get();
133 if (return_frame->GetStackID() != m_parent_frame_id || m_start_has_symbol)
138 s.PutCString ("Stepped in to: ");
139 addr_t stop_addr = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
140 s.Address (stop_addr, m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
141 s.PutCString (" stepping out to: ");
142 addr_t return_addr = return_frame->GetRegisterContext()->GetPC();
143 s.Address (return_addr, m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
144 log->Printf("%s.", s.GetData());
147 // StepInstruction should probably have the tri-state RunMode, but for now it is safer to
149 const bool stop_others = false;
150 m_thread.QueueThreadPlanForStepOut(false,
163 log->PutCString("The stack id we are stepping in changed, but our parent frame did not when stepping from code with no symbols. "
164 "We are probably just confused about where we are, stopping.");
173 log->Printf("Could not find previous frame, stopping.");
183 if (m_thread.GetRegisterContext()->GetPC(0) != m_instruction_addr)
194 ThreadPlanStepInstruction::StopOthers ()
196 return m_stop_other_threads;
200 ThreadPlanStepInstruction::GetPlanRunState ()
202 return eStateStepping;
206 ThreadPlanStepInstruction::WillStop ()
212 ThreadPlanStepInstruction::MischiefManaged ()
214 if (IsPlanComplete())
216 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
218 log->Printf("Completed single instruction step plan.");
219 ThreadPlan::MischiefManaged ();