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