1 //===-- SBThreadPlan.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 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBThread.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBSymbolContext.h"
15 #include "lldb/Breakpoint/BreakpointLocation.h"
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/State.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Interpreter/CommandInterpreter.h"
20 #include "lldb/Symbol/CompileUnit.h"
21 #include "lldb/Symbol/SymbolContext.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Target/Queue.h"
24 #include "lldb/Target/StopInfo.h"
25 #include "lldb/Target/SystemRuntime.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
28 #include "lldb/Target/ThreadPlan.h"
29 #include "lldb/Target/ThreadPlanPython.h"
30 #include "lldb/Target/ThreadPlanStepInRange.h"
31 #include "lldb/Target/ThreadPlanStepInstruction.h"
32 #include "lldb/Target/ThreadPlanStepOut.h"
33 #include "lldb/Target/ThreadPlanStepRange.h"
34 #include "lldb/Utility/Stream.h"
35 #include "lldb/Utility/StructuredData.h"
37 #include "lldb/API/SBAddress.h"
38 #include "lldb/API/SBDebugger.h"
39 #include "lldb/API/SBEvent.h"
40 #include "lldb/API/SBFrame.h"
41 #include "lldb/API/SBProcess.h"
42 #include "lldb/API/SBThreadPlan.h"
43 #include "lldb/API/SBValue.h"
46 using namespace lldb_private;
48 //----------------------------------------------------------------------
50 //----------------------------------------------------------------------
51 SBThreadPlan::SBThreadPlan() {}
53 SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp)
54 : m_opaque_sp(lldb_object_sp) {}
56 SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs)
57 : m_opaque_sp(rhs.m_opaque_sp) {}
59 SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
60 Thread *thread = sb_thread.get();
62 m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name));
65 //----------------------------------------------------------------------
66 // Assignment operator
67 //----------------------------------------------------------------------
69 const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) {
71 m_opaque_sp = rhs.m_opaque_sp;
74 //----------------------------------------------------------------------
76 //----------------------------------------------------------------------
77 SBThreadPlan::~SBThreadPlan() {}
79 lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); }
81 bool SBThreadPlan::IsValid() const { return m_opaque_sp.get() != NULL; }
83 void SBThreadPlan::Clear() { m_opaque_sp.reset(); }
85 lldb::StopReason SBThreadPlan::GetStopReason() { return eStopReasonNone; }
87 size_t SBThreadPlan::GetStopReasonDataCount() { return 0; }
89 uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) { return 0; }
91 SBThread SBThreadPlan::GetThread() const {
93 return SBThread(m_opaque_sp->GetThread().shared_from_this());
98 bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
100 m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull);
102 description.Printf("Empty SBThreadPlan");
107 void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) {
108 m_opaque_sp = lldb_object_sp;
111 void SBThreadPlan::SetPlanComplete(bool success) {
113 m_opaque_sp->SetPlanComplete(success);
116 bool SBThreadPlan::IsPlanComplete() {
118 return m_opaque_sp->IsPlanComplete();
123 bool SBThreadPlan::IsPlanStale() {
125 return m_opaque_sp->IsPlanStale();
130 bool SBThreadPlan::IsValid() {
132 return m_opaque_sp->ValidatePlan(nullptr);
137 // This section allows an SBThreadPlan to push another of the common types of
140 // FIXME, you should only be able to queue thread plans from inside the methods
142 // Scripted Thread Plan. Need a way to enforce that.
145 SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
148 Address *start_address = sb_start_address.get();
149 if (!start_address) {
150 return SBThreadPlan();
153 AddressRange range(*start_address, size);
155 start_address->CalculateSymbolContext(&sc);
157 m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange(
158 false, range, sc, eAllThreads));
160 return SBThreadPlan();
165 SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
168 Address *start_address = sb_start_address.get();
169 if (!start_address) {
170 return SBThreadPlan();
173 AddressRange range(*start_address, size);
175 start_address->CalculateSymbolContext(&sc);
176 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange(
177 false, range, sc, NULL, eAllThreads));
179 return SBThreadPlan();
184 SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
188 sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
189 lldb::eSymbolContextEverything);
190 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut(
191 false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
192 frame_idx_to_step_to));
194 return SBThreadPlan();
199 SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
201 Address *address = sb_address.get();
203 return SBThreadPlan();
205 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress(
206 false, *address, false));
208 return SBThreadPlan();