blob: 9af673b0f3a9937f2bff8a0864cc0df9f5ac23ae [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- SBThreadPlan.cpp --------------------------------------------------===//
Jim Ingham2bdbfd52014-09-29 23:17:18 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Ingham2bdbfd52014-09-29 23:17:18 +00006//
7//===----------------------------------------------------------------------===//
8
Jonas Devliegherebaf56642019-03-06 00:06:00 +00009#include "SBReproducerPrivate.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000010#include "lldb/API/SBThread.h"
11
Jim Ingham2bdbfd52014-09-29 23:17:18 +000012#include "lldb/API/SBFileSpec.h"
13#include "lldb/API/SBStream.h"
Jim Ingham27a14f12019-10-03 22:50:18 +000014#include "lldb/API/SBStructuredData.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000015#include "lldb/API/SBSymbolContext.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000016#include "lldb/Breakpoint/BreakpointLocation.h"
17#include "lldb/Core/Debugger.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000018#include "lldb/Core/StreamFile.h"
Jim Ingham27a14f12019-10-03 22:50:18 +000019#include "lldb/Core/StructuredDataImpl.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000020#include "lldb/Interpreter/CommandInterpreter.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000021#include "lldb/Symbol/CompileUnit.h"
22#include "lldb/Symbol/SymbolContext.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000023#include "lldb/Target/Process.h"
24#include "lldb/Target/Queue.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000025#include "lldb/Target/StopInfo.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000026#include "lldb/Target/SystemRuntime.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000027#include "lldb/Target/Target.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000028#include "lldb/Target/Thread.h"
29#include "lldb/Target/ThreadPlan.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000030#include "lldb/Target/ThreadPlanPython.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000031#include "lldb/Target/ThreadPlanStepInRange.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000032#include "lldb/Target/ThreadPlanStepInstruction.h"
33#include "lldb/Target/ThreadPlanStepOut.h"
34#include "lldb/Target/ThreadPlanStepRange.h"
Pavel Labathd821c992018-08-07 11:07:21 +000035#include "lldb/Utility/State.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000036#include "lldb/Utility/Stream.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000037#include "lldb/Utility/StructuredData.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000038
39#include "lldb/API/SBAddress.h"
40#include "lldb/API/SBDebugger.h"
41#include "lldb/API/SBEvent.h"
42#include "lldb/API/SBFrame.h"
43#include "lldb/API/SBProcess.h"
44#include "lldb/API/SBThreadPlan.h"
45#include "lldb/API/SBValue.h"
46
Jonas Devlieghere796ac802019-02-11 23:13:08 +000047#include <memory>
48
Jim Ingham2bdbfd52014-09-29 23:17:18 +000049using namespace lldb;
50using namespace lldb_private;
51
Jim Ingham2bdbfd52014-09-29 23:17:18 +000052// Constructors
Jonas Devliegherebaf56642019-03-06 00:06:00 +000053SBThreadPlan::SBThreadPlan() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadPlan); }
Jim Ingham2bdbfd52014-09-29 23:17:18 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp)
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -070056 : m_opaque_wp(lldb_object_sp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000057 LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (const lldb::ThreadPlanSP &),
58 lldb_object_sp);
59}
Jim Ingham2bdbfd52014-09-29 23:17:18 +000060
Kate Stoneb9c1b512016-09-06 20:57:50 +000061SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs)
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -070062 : m_opaque_wp(rhs.m_opaque_wp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000063 LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (const lldb::SBThreadPlan &), rhs);
64}
Jim Ingham2bdbfd52014-09-29 23:17:18 +000065
Kate Stoneb9c1b512016-09-06 20:57:50 +000066SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000067 LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *),
68 sb_thread, class_name);
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 Thread *thread = sb_thread.get();
71 if (thread)
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -070072 m_opaque_wp =
73 std::make_shared<ThreadPlanPython>(*thread, class_name, nullptr);
Jim Ingham27a14f12019-10-03 22:50:18 +000074}
75
76SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name,
77 lldb::SBStructuredData &args_data) {
78 LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *,
79 SBStructuredData &),
80 sb_thread, class_name, args_data);
81
82 Thread *thread = sb_thread.get();
83 if (thread)
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -070084 m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
Jim Ingham27a14f12019-10-03 22:50:18 +000085 args_data.m_impl_up.get());
Jim Ingham2bdbfd52014-09-29 23:17:18 +000086}
87
Jim Ingham2bdbfd52014-09-29 23:17:18 +000088// Assignment operator
Jim Ingham2bdbfd52014-09-29 23:17:18 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000091 LLDB_RECORD_METHOD(const lldb::SBThreadPlan &,
92 SBThreadPlan, operator=,(const lldb::SBThreadPlan &), rhs);
93
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 if (this != &rhs)
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -070095 m_opaque_wp = rhs.m_opaque_wp;
Jonas Devlieghere306809f2019-04-03 21:31:22 +000096 return LLDB_RECORD_RESULT(*this);
Jim Ingham2bdbfd52014-09-29 23:17:18 +000097}
Jim Ingham2bdbfd52014-09-29 23:17:18 +000098// Destructor
Jonas Devlieghere866b7a62020-02-17 22:57:06 -080099SBThreadPlan::~SBThreadPlan() = default;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000101bool SBThreadPlan::IsValid() const {
102 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +0000103 return this->operator bool();
104}
105SBThreadPlan::operator bool() const {
106 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, operator bool);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700108 return static_cast<bool>(GetSP());
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000109}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000111void SBThreadPlan::Clear() {
112 LLDB_RECORD_METHOD_NO_ARGS(void, SBThreadPlan, Clear);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700114 m_opaque_wp.reset();
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000115}
116
117lldb::StopReason SBThreadPlan::GetStopReason() {
118 LLDB_RECORD_METHOD_NO_ARGS(lldb::StopReason, SBThreadPlan, GetStopReason);
119
120 return eStopReasonNone;
121}
122
123size_t SBThreadPlan::GetStopReasonDataCount() {
124 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadPlan, GetStopReasonDataCount);
125
126 return 0;
127}
128
129uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) {
130 LLDB_RECORD_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
131 (uint32_t), idx);
132
133 return 0;
134}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135
136SBThread SBThreadPlan::GetThread() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000137 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBThreadPlan, GetThread);
138
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700139 ThreadPlanSP thread_plan_sp(GetSP());
140 if (thread_plan_sp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000141 return LLDB_RECORD_RESULT(
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700142 SBThread(thread_plan_sp->GetThread().shared_from_this()));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000143 } else
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000144 return LLDB_RECORD_RESULT(SBThread());
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000145}
146
Kate Stoneb9c1b512016-09-06 20:57:50 +0000147bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000148 LLDB_RECORD_METHOD_CONST(bool, SBThreadPlan, GetDescription,
149 (lldb::SBStream &), description);
150
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700151 ThreadPlanSP thread_plan_sp(GetSP());
152 if (thread_plan_sp) {
153 thread_plan_sp->GetDescription(description.get(), eDescriptionLevelFull);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 } else {
155 description.Printf("Empty SBThreadPlan");
156 }
157 return true;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000158}
159
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700160void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_wp) {
161 m_opaque_wp = lldb_object_wp;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000162}
163
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164void SBThreadPlan::SetPlanComplete(bool success) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000165 LLDB_RECORD_METHOD(void, SBThreadPlan, SetPlanComplete, (bool), success);
166
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700167 ThreadPlanSP thread_plan_sp(GetSP());
168 if (thread_plan_sp)
169 thread_plan_sp->SetPlanComplete(success);
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000170}
171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172bool SBThreadPlan::IsPlanComplete() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000173 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanComplete);
174
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700175 ThreadPlanSP thread_plan_sp(GetSP());
176 if (thread_plan_sp)
177 return thread_plan_sp->IsPlanComplete();
178 return true;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000179}
180
Kate Stoneb9c1b512016-09-06 20:57:50 +0000181bool SBThreadPlan::IsPlanStale() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000182 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanStale);
183
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700184 ThreadPlanSP thread_plan_sp(GetSP());
185 if (thread_plan_sp)
186 return thread_plan_sp->IsPlanStale();
187 return true;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000188}
189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190bool SBThreadPlan::IsValid() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000191 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsValid);
192
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700193 ThreadPlanSP thread_plan_sp(GetSP());
194 if (thread_plan_sp)
195 return thread_plan_sp->ValidatePlan(nullptr);
196 return false;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000197}
198
Jim Inghamd3dfd8c2020-08-07 14:44:01 -0700199bool SBThreadPlan::GetStopOthers() {
200 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, GetStopOthers);
201
202 ThreadPlanSP thread_plan_sp(GetSP());
203 if (thread_plan_sp)
204 return thread_plan_sp->StopOthers();
205 return false;
206}
207
208void SBThreadPlan::SetStopOthers(bool stop_others) {
209 LLDB_RECORD_METHOD(void, SBThreadPlan, SetStopOthers, (bool), stop_others);
210
211 ThreadPlanSP thread_plan_sp(GetSP());
212 if (thread_plan_sp)
213 thread_plan_sp->SetStopOthers(stop_others);
214}
215
Kate Stoneb9c1b512016-09-06 20:57:50 +0000216// This section allows an SBThreadPlan to push another of the common types of
217// plans...
218//
219// FIXME, you should only be able to queue thread plans from inside the methods
Adrian Prantl05097242018-04-30 16:49:04 +0000220// of a Scripted Thread Plan. Need a way to enforce that.
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000221
222SBThreadPlan
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
224 lldb::addr_t size) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000225 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
226 QueueThreadPlanForStepOverRange,
227 (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
228
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000229 SBError error;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000230 return LLDB_RECORD_RESULT(
231 QueueThreadPlanForStepOverRange(sb_start_address, size, error));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000232}
233
234SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOverRange(
235 SBAddress &sb_start_address, lldb::addr_t size, SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000236 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
237 QueueThreadPlanForStepOverRange,
238 (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
239 sb_start_address, size, error);
240
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700241 ThreadPlanSP thread_plan_sp(GetSP());
242 if (thread_plan_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000243 Address *start_address = sb_start_address.get();
244 if (!start_address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000245 return LLDB_RECORD_RESULT(SBThreadPlan());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000246 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000247
Kate Stoneb9c1b512016-09-06 20:57:50 +0000248 AddressRange range(*start_address, size);
249 SymbolContext sc;
250 start_address->CalculateSymbolContext(&sc);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000251 Status plan_status;
252
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700253 SBThreadPlan plan = SBThreadPlan(
254 thread_plan_sp->GetThread().QueueThreadPlanForStepOverRange(
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000255 false, range, sc, eAllThreads, plan_status));
256
257 if (plan_status.Fail())
258 error.SetErrorString(plan_status.AsCString());
Jim Inghamf7de4b52020-04-10 15:37:05 -0700259 else
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700260 plan.GetSP()->SetPrivate(true);
261
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000262 return LLDB_RECORD_RESULT(plan);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 }
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700264 return LLDB_RECORD_RESULT(SBThreadPlan());
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000265}
266
267SBThreadPlan
Kate Stoneb9c1b512016-09-06 20:57:50 +0000268SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
269 lldb::addr_t size) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000270 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
271 QueueThreadPlanForStepInRange,
272 (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
273
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000274 SBError error;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000275 return LLDB_RECORD_RESULT(
276 QueueThreadPlanForStepInRange(sb_start_address, size, error));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000277}
278
279SBThreadPlan
280SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
281 lldb::addr_t size, SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000282 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
283 QueueThreadPlanForStepInRange,
284 (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
285 sb_start_address, size, error);
286
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700287 ThreadPlanSP thread_plan_sp(GetSP());
288 if (thread_plan_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000289 Address *start_address = sb_start_address.get();
290 if (!start_address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000291 return LLDB_RECORD_RESULT(SBThreadPlan());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000292 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000293
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294 AddressRange range(*start_address, size);
295 SymbolContext sc;
296 start_address->CalculateSymbolContext(&sc);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000297
298 Status plan_status;
299 SBThreadPlan plan =
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700300 SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepInRange(
Konrad Kleine248a1302019-05-23 11:14:47 +0000301 false, range, sc, nullptr, eAllThreads, plan_status));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000302
303 if (plan_status.Fail())
304 error.SetErrorString(plan_status.AsCString());
Jim Inghamf7de4b52020-04-10 15:37:05 -0700305 else
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700306 plan.GetSP()->SetPrivate(true);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000307
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000308 return LLDB_RECORD_RESULT(plan);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000309 }
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700310 return LLDB_RECORD_RESULT(SBThreadPlan());
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000311}
312
313SBThreadPlan
Kate Stoneb9c1b512016-09-06 20:57:50 +0000314SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
315 bool first_insn) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000316 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
317 QueueThreadPlanForStepOut, (uint32_t, bool),
318 frame_idx_to_step_to, first_insn);
319
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000320 SBError error;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000321 return LLDB_RECORD_RESULT(
322 QueueThreadPlanForStepOut(frame_idx_to_step_to, first_insn, error));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000323}
324
325SBThreadPlan
326SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
327 bool first_insn, SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000328 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
329 QueueThreadPlanForStepOut,
330 (uint32_t, bool, lldb::SBError &), frame_idx_to_step_to,
331 first_insn, error);
332
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700333 ThreadPlanSP thread_plan_sp(GetSP());
334 if (thread_plan_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000335 SymbolContext sc;
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700336 sc = thread_plan_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 lldb::eSymbolContextEverything);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000338
339 Status plan_status;
340 SBThreadPlan plan =
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700341 SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepOut(
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000342 false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
343 frame_idx_to_step_to, plan_status));
344
345 if (plan_status.Fail())
346 error.SetErrorString(plan_status.AsCString());
Jim Inghamf7de4b52020-04-10 15:37:05 -0700347 else
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700348 plan.GetSP()->SetPrivate(true);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000349
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000350 return LLDB_RECORD_RESULT(plan);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 }
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700352 return LLDB_RECORD_RESULT(SBThreadPlan());
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000353}
354
355SBThreadPlan
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000357 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
358 QueueThreadPlanForRunToAddress, (lldb::SBAddress),
359 sb_address);
360
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000361 SBError error;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000362 return LLDB_RECORD_RESULT(QueueThreadPlanForRunToAddress(sb_address, error));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000363}
364
365SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address,
366 SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000367 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
368 QueueThreadPlanForRunToAddress,
369 (lldb::SBAddress, lldb::SBError &), sb_address, error);
370
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700371 ThreadPlanSP thread_plan_sp(GetSP());
372 if (thread_plan_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 Address *address = sb_address.get();
374 if (!address)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000375 return LLDB_RECORD_RESULT(SBThreadPlan());
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000376
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000377 Status plan_status;
378 SBThreadPlan plan =
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700379 SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForRunToAddress(
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000380 false, *address, false, plan_status));
381
382 if (plan_status.Fail())
383 error.SetErrorString(plan_status.AsCString());
Jim Inghamf7de4b52020-04-10 15:37:05 -0700384 else
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700385 plan.GetSP()->SetPrivate(true);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000386
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000387 return LLDB_RECORD_RESULT(plan);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000388 }
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700389 return LLDB_RECORD_RESULT(SBThreadPlan());
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000390}
Aleksandr Urakovc1c0fac2018-10-25 08:27:42 +0000391
392SBThreadPlan
393SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000394 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
395 QueueThreadPlanForStepScripted, (const char *),
396 script_class_name);
397
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000398 SBError error;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000399 return LLDB_RECORD_RESULT(
400 QueueThreadPlanForStepScripted(script_class_name, error));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000401}
402
403SBThreadPlan
404SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
405 SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000406 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
407 QueueThreadPlanForStepScripted,
408 (const char *, lldb::SBError &), script_class_name, error);
409
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700410 ThreadPlanSP thread_plan_sp(GetSP());
411 if (thread_plan_sp) {
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000412 Status plan_status;
Jim Ingham27a14f12019-10-03 22:50:18 +0000413 StructuredData::ObjectSP empty_args;
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000414 SBThreadPlan plan =
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700415 SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepScripted(
Jim Ingham27a14f12019-10-03 22:50:18 +0000416 false, script_class_name, empty_args, false, plan_status));
417
418 if (plan_status.Fail())
419 error.SetErrorString(plan_status.AsCString());
Jim Inghamf7de4b52020-04-10 15:37:05 -0700420 else
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700421 plan.GetSP()->SetPrivate(true);
Jim Ingham27a14f12019-10-03 22:50:18 +0000422
423 return LLDB_RECORD_RESULT(plan);
Jim Ingham27a14f12019-10-03 22:50:18 +0000424 }
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700425 return LLDB_RECORD_RESULT(SBThreadPlan());
Jim Ingham27a14f12019-10-03 22:50:18 +0000426}
427
428SBThreadPlan
429SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
430 lldb::SBStructuredData &args_data,
431 SBError &error) {
432 LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
433 QueueThreadPlanForStepScripted,
434 (const char *, lldb::SBStructuredData &, lldb::SBError &),
435 script_class_name, args_data, error);
436
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700437 ThreadPlanSP thread_plan_sp(GetSP());
438 if (thread_plan_sp) {
Jim Ingham27a14f12019-10-03 22:50:18 +0000439 Status plan_status;
440 StructuredData::ObjectSP args_obj = args_data.m_impl_up->GetObjectSP();
441 SBThreadPlan plan =
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700442 SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepScripted(
Jim Ingham27a14f12019-10-03 22:50:18 +0000443 false, script_class_name, args_obj, false, plan_status));
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000444
445 if (plan_status.Fail())
446 error.SetErrorString(plan_status.AsCString());
Jim Inghamf7de4b52020-04-10 15:37:05 -0700447 else
Jonas Devlieghere2ba7ce401e2020-07-20 16:50:59 -0700448 plan.GetSP()->SetPrivate(true);
Jonas Devliegheree103ae92018-11-15 01:18:15 +0000449
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000450 return LLDB_RECORD_RESULT(plan);
Aleksandr Urakovc1c0fac2018-10-25 08:27:42 +0000451 } else {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000452 return LLDB_RECORD_RESULT(SBThreadPlan());
Aleksandr Urakovc1c0fac2018-10-25 08:27:42 +0000453 }
454}
Michal Gornyae211ec2019-03-19 17:13:13 +0000455
456namespace lldb_private {
457namespace repro {
458
459template <>
460void RegisterMethods<SBThreadPlan>(Registry &R) {
461 LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, ());
462 LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::ThreadPlanSP &));
463 LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::SBThreadPlan &));
464 LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *));
Jim Ingham27a14f12019-10-03 22:50:18 +0000465 LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *,
466 lldb::SBStructuredData &));
Michal Gornyae211ec2019-03-19 17:13:13 +0000467 LLDB_REGISTER_METHOD(const lldb::SBThreadPlan &,
468 SBThreadPlan, operator=,(const lldb::SBThreadPlan &));
Michal Gornyae211ec2019-03-19 17:13:13 +0000469 LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, IsValid, ());
470 LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, operator bool, ());
471 LLDB_REGISTER_METHOD(void, SBThreadPlan, Clear, ());
472 LLDB_REGISTER_METHOD(lldb::StopReason, SBThreadPlan, GetStopReason, ());
473 LLDB_REGISTER_METHOD(size_t, SBThreadPlan, GetStopReasonDataCount, ());
474 LLDB_REGISTER_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
475 (uint32_t));
476 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBThreadPlan, GetThread, ());
477 LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, GetDescription,
478 (lldb::SBStream &));
479 LLDB_REGISTER_METHOD(void, SBThreadPlan, SetPlanComplete, (bool));
480 LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanComplete, ());
481 LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanStale, ());
482 LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsValid, ());
Jim Inghamd3dfd8c2020-08-07 14:44:01 -0700483 LLDB_REGISTER_METHOD(void, SBThreadPlan, SetStopOthers, (bool));
484 LLDB_REGISTER_METHOD(bool, SBThreadPlan, GetStopOthers, ());
Michal Gornyae211ec2019-03-19 17:13:13 +0000485 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
486 QueueThreadPlanForStepOverRange,
487 (lldb::SBAddress &, lldb::addr_t));
488 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
489 QueueThreadPlanForStepOverRange,
490 (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
491 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
492 QueueThreadPlanForStepInRange,
493 (lldb::SBAddress &, lldb::addr_t));
494 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
495 QueueThreadPlanForStepInRange,
496 (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
497 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
498 QueueThreadPlanForStepOut, (uint32_t, bool));
499 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
500 QueueThreadPlanForStepOut,
501 (uint32_t, bool, lldb::SBError &));
502 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
503 QueueThreadPlanForRunToAddress, (lldb::SBAddress));
504 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
505 QueueThreadPlanForRunToAddress,
506 (lldb::SBAddress, lldb::SBError &));
507 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
508 QueueThreadPlanForStepScripted, (const char *));
509 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
510 QueueThreadPlanForStepScripted,
511 (const char *, lldb::SBError &));
Jim Ingham27a14f12019-10-03 22:50:18 +0000512 LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
513 QueueThreadPlanForStepScripted,
514 (const char *, lldb::SBStructuredData &,
515 lldb::SBError &));
Michal Gornyae211ec2019-03-19 17:13:13 +0000516}
517
518}
519}