1 //===-- SBThreadPlan.cpp ----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/API/SBThread.h" 11 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/Core/StructuredData.h" 20 #include "lldb/Interpreter/CommandInterpreter.h" 21 #include "lldb/Symbol/CompileUnit.h" 22 #include "lldb/Symbol/SymbolContext.h" 23 #include "lldb/Target/Process.h" 24 #include "lldb/Target/Queue.h" 25 #include "lldb/Target/StopInfo.h" 26 #include "lldb/Target/SystemRuntime.h" 27 #include "lldb/Target/Target.h" 28 #include "lldb/Target/Thread.h" 29 #include "lldb/Target/ThreadPlan.h" 30 #include "lldb/Target/ThreadPlan.h" 31 #include "lldb/Target/ThreadPlanPython.h" 32 #include "lldb/Target/ThreadPlanStepInRange.h" 33 #include "lldb/Target/ThreadPlanStepInstruction.h" 34 #include "lldb/Target/ThreadPlanStepOut.h" 35 #include "lldb/Target/ThreadPlanStepRange.h" 36 #include "lldb/Utility/Stream.h" 37 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" 45 46 using namespace lldb; 47 using namespace lldb_private; 48 49 //---------------------------------------------------------------------- 50 // Constructors 51 //---------------------------------------------------------------------- 52 SBThreadPlan::SBThreadPlan() {} 53 54 SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp) 55 : m_opaque_sp(lldb_object_sp) {} 56 57 SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs) 58 : m_opaque_sp(rhs.m_opaque_sp) {} 59 60 SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) { 61 Thread *thread = sb_thread.get(); 62 if (thread) 63 m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name)); 64 } 65 66 //---------------------------------------------------------------------- 67 // Assignment operator 68 //---------------------------------------------------------------------- 69 70 const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) { 71 if (this != &rhs) 72 m_opaque_sp = rhs.m_opaque_sp; 73 return *this; 74 } 75 //---------------------------------------------------------------------- 76 // Destructor 77 //---------------------------------------------------------------------- 78 SBThreadPlan::~SBThreadPlan() {} 79 80 lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); } 81 82 bool SBThreadPlan::IsValid() const { return m_opaque_sp.get() != NULL; } 83 84 void SBThreadPlan::Clear() { m_opaque_sp.reset(); } 85 86 lldb::StopReason SBThreadPlan::GetStopReason() { return eStopReasonNone; } 87 88 size_t SBThreadPlan::GetStopReasonDataCount() { return 0; } 89 90 uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) { return 0; } 91 92 SBThread SBThreadPlan::GetThread() const { 93 if (m_opaque_sp) { 94 return SBThread(m_opaque_sp->GetThread().shared_from_this()); 95 } else 96 return SBThread(); 97 } 98 99 bool SBThreadPlan::GetDescription(lldb::SBStream &description) const { 100 if (m_opaque_sp) { 101 m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull); 102 } else { 103 description.Printf("Empty SBThreadPlan"); 104 } 105 return true; 106 } 107 108 void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) { 109 m_opaque_sp = lldb_object_sp; 110 } 111 112 void SBThreadPlan::SetPlanComplete(bool success) { 113 if (m_opaque_sp) 114 m_opaque_sp->SetPlanComplete(success); 115 } 116 117 bool SBThreadPlan::IsPlanComplete() { 118 if (m_opaque_sp) 119 return m_opaque_sp->IsPlanComplete(); 120 else 121 return true; 122 } 123 124 bool SBThreadPlan::IsPlanStale() { 125 if (m_opaque_sp) 126 return m_opaque_sp->IsPlanStale(); 127 else 128 return true; 129 } 130 131 bool SBThreadPlan::IsValid() { 132 if (m_opaque_sp) 133 return m_opaque_sp->ValidatePlan(nullptr); 134 else 135 return false; 136 } 137 138 // This section allows an SBThreadPlan to push another of the common types of 139 // plans... 140 // 141 // FIXME, you should only be able to queue thread plans from inside the methods 142 // of a 143 // Scripted Thread Plan. Need a way to enforce that. 144 145 SBThreadPlan 146 SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address, 147 lldb::addr_t size) { 148 if (m_opaque_sp) { 149 Address *start_address = sb_start_address.get(); 150 if (!start_address) { 151 return SBThreadPlan(); 152 } 153 154 AddressRange range(*start_address, size); 155 SymbolContext sc; 156 start_address->CalculateSymbolContext(&sc); 157 return SBThreadPlan( 158 m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange( 159 false, range, sc, eAllThreads)); 160 } else { 161 return SBThreadPlan(); 162 } 163 } 164 165 SBThreadPlan 166 SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address, 167 lldb::addr_t size) { 168 if (m_opaque_sp) { 169 Address *start_address = sb_start_address.get(); 170 if (!start_address) { 171 return SBThreadPlan(); 172 } 173 174 AddressRange range(*start_address, size); 175 SymbolContext sc; 176 start_address->CalculateSymbolContext(&sc); 177 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange( 178 false, range, sc, NULL, eAllThreads)); 179 } else { 180 return SBThreadPlan(); 181 } 182 } 183 184 SBThreadPlan 185 SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, 186 bool first_insn) { 187 if (m_opaque_sp) { 188 SymbolContext sc; 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)); 194 } else { 195 return SBThreadPlan(); 196 } 197 } 198 199 SBThreadPlan 200 SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) { 201 if (m_opaque_sp) { 202 Address *address = sb_address.get(); 203 if (!address) 204 return SBThreadPlan(); 205 206 return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress( 207 false, *address, false)); 208 } else { 209 return SBThreadPlan(); 210 } 211 } 212