Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- SBThreadPlan.cpp ----------------------------------------*- C++ -*-===// |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 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 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBThread.h" |
| 11 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBFileSpec.h" |
| 13 | #include "lldb/API/SBStream.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBSymbolContext.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 15 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 16 | #include "lldb/Core/Debugger.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 17 | #include "lldb/Core/StreamFile.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandInterpreter.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/CompileUnit.h" |
| 20 | #include "lldb/Symbol/SymbolContext.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Process.h" |
| 22 | #include "lldb/Target/Queue.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 23 | #include "lldb/Target/StopInfo.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | #include "lldb/Target/SystemRuntime.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Thread.h" |
| 27 | #include "lldb/Target/ThreadPlan.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 28 | #include "lldb/Target/ThreadPlanPython.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | #include "lldb/Target/ThreadPlanStepInRange.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 30 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 31 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 32 | #include "lldb/Target/ThreadPlanStepRange.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 33 | #include "lldb/Utility/State.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 34 | #include "lldb/Utility/Stream.h" |
Pavel Labath | f2a8bcc | 2017-06-27 10:45:31 +0000 | [diff] [blame] | 35 | #include "lldb/Utility/StructuredData.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 36 | |
| 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" |
| 44 | |
| 45 | using namespace lldb; |
| 46 | using namespace lldb_private; |
| 47 | |
| 48 | //---------------------------------------------------------------------- |
| 49 | // Constructors |
| 50 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | SBThreadPlan::SBThreadPlan() {} |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 52 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp) |
| 54 | : m_opaque_sp(lldb_object_sp) {} |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs) |
| 57 | : m_opaque_sp(rhs.m_opaque_sp) {} |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) { |
| 60 | Thread *thread = sb_thread.get(); |
| 61 | if (thread) |
| 62 | m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name)); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | //---------------------------------------------------------------------- |
| 66 | // Assignment operator |
| 67 | //---------------------------------------------------------------------- |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) { |
| 70 | if (this != &rhs) |
| 71 | m_opaque_sp = rhs.m_opaque_sp; |
| 72 | return *this; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 73 | } |
| 74 | //---------------------------------------------------------------------- |
| 75 | // Destructor |
| 76 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | SBThreadPlan::~SBThreadPlan() {} |
| 78 | |
| 79 | lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); } |
| 80 | |
| 81 | bool SBThreadPlan::IsValid() const { return m_opaque_sp.get() != NULL; } |
| 82 | |
| 83 | void SBThreadPlan::Clear() { m_opaque_sp.reset(); } |
| 84 | |
| 85 | lldb::StopReason SBThreadPlan::GetStopReason() { return eStopReasonNone; } |
| 86 | |
| 87 | size_t SBThreadPlan::GetStopReasonDataCount() { return 0; } |
| 88 | |
| 89 | uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) { return 0; } |
| 90 | |
| 91 | SBThread SBThreadPlan::GetThread() const { |
| 92 | if (m_opaque_sp) { |
| 93 | return SBThread(m_opaque_sp->GetThread().shared_from_this()); |
| 94 | } else |
| 95 | return SBThread(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | bool SBThreadPlan::GetDescription(lldb::SBStream &description) const { |
| 99 | if (m_opaque_sp) { |
| 100 | m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull); |
| 101 | } else { |
| 102 | description.Printf("Empty SBThreadPlan"); |
| 103 | } |
| 104 | return true; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) { |
| 108 | m_opaque_sp = lldb_object_sp; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | void SBThreadPlan::SetPlanComplete(bool success) { |
| 112 | if (m_opaque_sp) |
| 113 | m_opaque_sp->SetPlanComplete(success); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | bool SBThreadPlan::IsPlanComplete() { |
| 117 | if (m_opaque_sp) |
| 118 | return m_opaque_sp->IsPlanComplete(); |
| 119 | else |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 120 | return true; |
| 121 | } |
| 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | bool SBThreadPlan::IsPlanStale() { |
| 124 | if (m_opaque_sp) |
| 125 | return m_opaque_sp->IsPlanStale(); |
| 126 | else |
| 127 | return true; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | bool SBThreadPlan::IsValid() { |
| 131 | if (m_opaque_sp) |
| 132 | return m_opaque_sp->ValidatePlan(nullptr); |
| 133 | else |
| 134 | return false; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | // This section allows an SBThreadPlan to push another of the common types of |
| 138 | // plans... |
| 139 | // |
| 140 | // FIXME, you should only be able to queue thread plans from inside the methods |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 141 | // of a Scripted Thread Plan. Need a way to enforce that. |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 142 | |
| 143 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address, |
| 145 | lldb::addr_t size) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 146 | SBError error; |
| 147 | return QueueThreadPlanForStepOverRange(sb_start_address, size, error); |
| 148 | } |
| 149 | |
| 150 | SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOverRange( |
| 151 | SBAddress &sb_start_address, lldb::addr_t size, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | if (m_opaque_sp) { |
| 153 | Address *start_address = sb_start_address.get(); |
| 154 | if (!start_address) { |
| 155 | return SBThreadPlan(); |
| 156 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | AddressRange range(*start_address, size); |
| 159 | SymbolContext sc; |
| 160 | start_address->CalculateSymbolContext(&sc); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 161 | Status plan_status; |
| 162 | |
| 163 | SBThreadPlan plan = |
| 164 | SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange( |
| 165 | false, range, sc, eAllThreads, plan_status)); |
| 166 | |
| 167 | if (plan_status.Fail()) |
| 168 | error.SetErrorString(plan_status.AsCString()); |
| 169 | |
| 170 | return plan; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | } else { |
| 172 | return SBThreadPlan(); |
| 173 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 177 | SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address, |
| 178 | lldb::addr_t size) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 179 | SBError error; |
| 180 | return QueueThreadPlanForStepInRange(sb_start_address, size, error); |
| 181 | } |
| 182 | |
| 183 | SBThreadPlan |
| 184 | SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address, |
| 185 | lldb::addr_t size, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | if (m_opaque_sp) { |
| 187 | Address *start_address = sb_start_address.get(); |
| 188 | if (!start_address) { |
| 189 | return SBThreadPlan(); |
| 190 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | AddressRange range(*start_address, size); |
| 193 | SymbolContext sc; |
| 194 | start_address->CalculateSymbolContext(&sc); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 195 | |
| 196 | Status plan_status; |
| 197 | SBThreadPlan plan = |
| 198 | SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange( |
| 199 | false, range, sc, NULL, eAllThreads, plan_status)); |
| 200 | |
| 201 | if (plan_status.Fail()) |
| 202 | error.SetErrorString(plan_status.AsCString()); |
| 203 | |
| 204 | return plan; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 205 | } else { |
| 206 | return SBThreadPlan(); |
| 207 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 211 | SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, |
| 212 | bool first_insn) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 213 | SBError error; |
| 214 | return QueueThreadPlanForStepOut(frame_idx_to_step_to, first_insn, error); |
| 215 | } |
| 216 | |
| 217 | SBThreadPlan |
| 218 | SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, |
| 219 | bool first_insn, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | if (m_opaque_sp) { |
| 221 | SymbolContext sc; |
| 222 | sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext( |
| 223 | lldb::eSymbolContextEverything); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 224 | |
| 225 | Status plan_status; |
| 226 | SBThreadPlan plan = |
| 227 | SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut( |
| 228 | false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion, |
| 229 | frame_idx_to_step_to, plan_status)); |
| 230 | |
| 231 | if (plan_status.Fail()) |
| 232 | error.SetErrorString(plan_status.AsCString()); |
| 233 | |
| 234 | return plan; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 235 | } else { |
| 236 | return SBThreadPlan(); |
| 237 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 242 | SBError error; |
| 243 | return QueueThreadPlanForRunToAddress(sb_address, error); |
| 244 | } |
| 245 | |
| 246 | SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address, |
| 247 | SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | if (m_opaque_sp) { |
| 249 | Address *address = sb_address.get(); |
| 250 | if (!address) |
| 251 | return SBThreadPlan(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 252 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 253 | Status plan_status; |
| 254 | SBThreadPlan plan = |
| 255 | SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress( |
| 256 | false, *address, false, plan_status)); |
| 257 | |
| 258 | if (plan_status.Fail()) |
| 259 | error.SetErrorString(plan_status.AsCString()); |
| 260 | |
| 261 | return plan; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 262 | } else { |
| 263 | return SBThreadPlan(); |
| 264 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 265 | } |
Aleksandr Urakov | c1c0fac | 2018-10-25 08:27:42 +0000 | [diff] [blame] | 266 | |
| 267 | SBThreadPlan |
| 268 | SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 269 | SBError error; |
| 270 | return QueueThreadPlanForStepScripted(script_class_name, error); |
| 271 | } |
| 272 | |
| 273 | SBThreadPlan |
| 274 | SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name, |
| 275 | SBError &error) { |
Aleksandr Urakov | c1c0fac | 2018-10-25 08:27:42 +0000 | [diff] [blame] | 276 | if (m_opaque_sp) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 277 | Status plan_status; |
| 278 | SBThreadPlan plan = |
| 279 | SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepScripted( |
| 280 | false, script_class_name, false, plan_status)); |
| 281 | |
| 282 | if (plan_status.Fail()) |
| 283 | error.SetErrorString(plan_status.AsCString()); |
| 284 | |
| 285 | return plan; |
Aleksandr Urakov | c1c0fac | 2018-10-25 08:27:42 +0000 | [diff] [blame] | 286 | } else { |
| 287 | return SBThreadPlan(); |
| 288 | } |
| 289 | } |