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/Stream.h"
19 #include "lldb/Core/StreamFile.h"
20 #include "lldb/Core/StructuredData.h"
21 #include "lldb/Interpreter/CommandInterpreter.h"
22 #include "lldb/Symbol/CompileUnit.h"
23 #include "lldb/Symbol/SymbolContext.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Target/Queue.h"
26 #include "lldb/Target/StopInfo.h"
27 #include "lldb/Target/SystemRuntime.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/Thread.h"
30 #include "lldb/Target/ThreadPlan.h"
31 #include "lldb/Target/ThreadPlan.h"
32 #include "lldb/Target/ThreadPlanPython.h"
33 #include "lldb/Target/ThreadPlanStepInRange.h"
34 #include "lldb/Target/ThreadPlanStepInstruction.h"
35 #include "lldb/Target/ThreadPlanStepOut.h"
36 #include "lldb/Target/ThreadPlanStepRange.h"
38 #include "lldb/API/SBAddress.h"
39 #include "lldb/API/SBDebugger.h"
40 #include "lldb/API/SBEvent.h"
41 #include "lldb/API/SBFrame.h"
42 #include "lldb/API/SBProcess.h"
43 #include "lldb/API/SBThreadPlan.h"
44 #include "lldb/API/SBValue.h"
47 using namespace lldb_private;
49 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
52 SBThreadPlan::SBThreadPlan() {}
54 SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp)
55 : m_opaque_sp(lldb_object_sp) {}
57 SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs)
58 : m_opaque_sp(rhs.m_opaque_sp) {}
60 SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
61 Thread *thread = sb_thread.get();
63 m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name));
66 //----------------------------------------------------------------------
67 // Assignment operator
68 //----------------------------------------------------------------------
70 const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) {
72 m_opaque_sp = rhs.m_opaque_sp;
75 //----------------------------------------------------------------------
77 //----------------------------------------------------------------------
78 SBThreadPlan::~SBThreadPlan() {}
80 lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); }
82 bool SBThreadPlan::IsValid() const { return m_opaque_sp.get() != NULL; }
84 void SBThreadPlan::Clear() { m_opaque_sp.reset(); }
86 lldb::StopReason SBThreadPlan::GetStopReason() { return eStopReasonNone; }
88 size_t SBThreadPlan::GetStopReasonDataCount() { return 0; }
90 uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) { return 0; }
92 SBThread SBThreadPlan::GetThread() const {
94 return SBThread(m_opaque_sp->GetThread().shared_from_this());
99 bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
101 m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull);
103 description.Printf("Empty SBThreadPlan");
108 void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) {
109 m_opaque_sp = lldb_object_sp;
112 void SBThreadPlan::SetPlanComplete(bool success) {
114 m_opaque_sp->SetPlanComplete(success);
117 bool SBThreadPlan::IsPlanComplete() {
119 return m_opaque_sp->IsPlanComplete();
124 bool SBThreadPlan::IsPlanStale() {
126 return m_opaque_sp->IsPlanStale();
131 bool SBThreadPlan::IsValid() {
133 return m_opaque_sp->ValidatePlan(nullptr);
138 // This section allows an SBThreadPlan to push another of the common types of
141 // FIXME, you should only be able to queue thread plans from inside the methods
143 // Scripted Thread Plan. Need a way to enforce that.
146 SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
149 Address *start_address = sb_start_address.get();
150 if (!start_address) {
151 return SBThreadPlan();
154 AddressRange range(*start_address, size);
156 start_address->CalculateSymbolContext(&sc);
158 m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange(
159 false, range, sc, eAllThreads));
161 return SBThreadPlan();
166 SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
169 Address *start_address = sb_start_address.get();
170 if (!start_address) {
171 return SBThreadPlan();
174 AddressRange range(*start_address, size);
176 start_address->CalculateSymbolContext(&sc);
177 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange(
178 false, range, sc, NULL, eAllThreads));
180 return SBThreadPlan();
185 SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
189 sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
190 lldb::eSymbolContextEverything);
191 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut(
192 false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
193 frame_idx_to_step_to));
195 return SBThreadPlan();
200 SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
202 Address *address = sb_address.get();
204 return SBThreadPlan();
206 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress(
207 false, *address, false));
209 return SBThreadPlan();