1696bd635SAlexander Shaposhnikov //===-- SBThreadPlan.cpp ----------------------------------------*- C++ -*-===//
22bdbfd50SJim Ingham //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62bdbfd50SJim Ingham //
72bdbfd50SJim Ingham //===----------------------------------------------------------------------===//
82bdbfd50SJim Ingham 
9baf5664fSJonas Devlieghere #include "SBReproducerPrivate.h"
102bdbfd50SJim Ingham #include "lldb/API/SBThread.h"
112bdbfd50SJim Ingham 
122bdbfd50SJim Ingham #include "lldb/API/SBFileSpec.h"
132bdbfd50SJim Ingham #include "lldb/API/SBStream.h"
14b9c1b51eSKate Stone #include "lldb/API/SBSymbolContext.h"
152bdbfd50SJim Ingham #include "lldb/Breakpoint/BreakpointLocation.h"
162bdbfd50SJim Ingham #include "lldb/Core/Debugger.h"
172bdbfd50SJim Ingham #include "lldb/Core/StreamFile.h"
182bdbfd50SJim Ingham #include "lldb/Interpreter/CommandInterpreter.h"
19b9c1b51eSKate Stone #include "lldb/Symbol/CompileUnit.h"
20b9c1b51eSKate Stone #include "lldb/Symbol/SymbolContext.h"
212bdbfd50SJim Ingham #include "lldb/Target/Process.h"
222bdbfd50SJim Ingham #include "lldb/Target/Queue.h"
232bdbfd50SJim Ingham #include "lldb/Target/StopInfo.h"
24b9c1b51eSKate Stone #include "lldb/Target/SystemRuntime.h"
252bdbfd50SJim Ingham #include "lldb/Target/Target.h"
26b9c1b51eSKate Stone #include "lldb/Target/Thread.h"
27b9c1b51eSKate Stone #include "lldb/Target/ThreadPlan.h"
282bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanPython.h"
29b9c1b51eSKate Stone #include "lldb/Target/ThreadPlanStepInRange.h"
302bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanStepInstruction.h"
312bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanStepOut.h"
322bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanStepRange.h"
33d821c997SPavel Labath #include "lldb/Utility/State.h"
34bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
35f2a8bccfSPavel Labath #include "lldb/Utility/StructuredData.h"
362bdbfd50SJim Ingham 
372bdbfd50SJim Ingham #include "lldb/API/SBAddress.h"
382bdbfd50SJim Ingham #include "lldb/API/SBDebugger.h"
392bdbfd50SJim Ingham #include "lldb/API/SBEvent.h"
402bdbfd50SJim Ingham #include "lldb/API/SBFrame.h"
412bdbfd50SJim Ingham #include "lldb/API/SBProcess.h"
422bdbfd50SJim Ingham #include "lldb/API/SBThreadPlan.h"
432bdbfd50SJim Ingham #include "lldb/API/SBValue.h"
442bdbfd50SJim Ingham 
45796ac80bSJonas Devlieghere #include <memory>
46796ac80bSJonas Devlieghere 
472bdbfd50SJim Ingham using namespace lldb;
482bdbfd50SJim Ingham using namespace lldb_private;
492bdbfd50SJim Ingham 
502bdbfd50SJim Ingham //----------------------------------------------------------------------
512bdbfd50SJim Ingham // Constructors
522bdbfd50SJim Ingham //----------------------------------------------------------------------
53baf5664fSJonas Devlieghere SBThreadPlan::SBThreadPlan() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadPlan); }
542bdbfd50SJim Ingham 
55b9c1b51eSKate Stone SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp)
56baf5664fSJonas Devlieghere     : m_opaque_sp(lldb_object_sp) {
57baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (const lldb::ThreadPlanSP &),
58baf5664fSJonas Devlieghere                           lldb_object_sp);
59baf5664fSJonas Devlieghere }
602bdbfd50SJim Ingham 
61b9c1b51eSKate Stone SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs)
62baf5664fSJonas Devlieghere     : m_opaque_sp(rhs.m_opaque_sp) {
63baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (const lldb::SBThreadPlan &), rhs);
64baf5664fSJonas Devlieghere }
652bdbfd50SJim Ingham 
66b9c1b51eSKate Stone SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
67baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *),
68baf5664fSJonas Devlieghere                           sb_thread, class_name);
69baf5664fSJonas Devlieghere 
702bdbfd50SJim Ingham   Thread *thread = sb_thread.get();
712bdbfd50SJim Ingham   if (thread)
72796ac80bSJonas Devlieghere     m_opaque_sp = std::make_shared<ThreadPlanPython>(*thread, class_name);
732bdbfd50SJim Ingham }
742bdbfd50SJim Ingham 
752bdbfd50SJim Ingham //----------------------------------------------------------------------
762bdbfd50SJim Ingham // Assignment operator
772bdbfd50SJim Ingham //----------------------------------------------------------------------
782bdbfd50SJim Ingham 
79b9c1b51eSKate Stone const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) {
80baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(const lldb::SBThreadPlan &,
81baf5664fSJonas Devlieghere                      SBThreadPlan, operator=,(const lldb::SBThreadPlan &), rhs);
82baf5664fSJonas Devlieghere 
832bdbfd50SJim Ingham   if (this != &rhs)
842bdbfd50SJim Ingham     m_opaque_sp = rhs.m_opaque_sp;
85306809f2SJonas Devlieghere   return LLDB_RECORD_RESULT(*this);
862bdbfd50SJim Ingham }
872bdbfd50SJim Ingham //----------------------------------------------------------------------
882bdbfd50SJim Ingham // Destructor
892bdbfd50SJim Ingham //----------------------------------------------------------------------
90b9c1b51eSKate Stone SBThreadPlan::~SBThreadPlan() {}
912bdbfd50SJim Ingham 
92*26ca5a57SPavel Labath lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); }
932bdbfd50SJim Ingham 
94baf5664fSJonas Devlieghere bool SBThreadPlan::IsValid() const {
95baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, IsValid);
967f5237bcSPavel Labath   return this->operator bool();
977f5237bcSPavel Labath }
987f5237bcSPavel Labath SBThreadPlan::operator bool() const {
997f5237bcSPavel Labath   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, operator bool);
1002bdbfd50SJim Ingham 
101baf5664fSJonas Devlieghere   return m_opaque_sp.get() != NULL;
102baf5664fSJonas Devlieghere }
1032bdbfd50SJim Ingham 
104baf5664fSJonas Devlieghere void SBThreadPlan::Clear() {
105baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(void, SBThreadPlan, Clear);
1062bdbfd50SJim Ingham 
107baf5664fSJonas Devlieghere   m_opaque_sp.reset();
108baf5664fSJonas Devlieghere }
109baf5664fSJonas Devlieghere 
110baf5664fSJonas Devlieghere lldb::StopReason SBThreadPlan::GetStopReason() {
111baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(lldb::StopReason, SBThreadPlan, GetStopReason);
112baf5664fSJonas Devlieghere 
113baf5664fSJonas Devlieghere   return eStopReasonNone;
114baf5664fSJonas Devlieghere }
115baf5664fSJonas Devlieghere 
116baf5664fSJonas Devlieghere size_t SBThreadPlan::GetStopReasonDataCount() {
117baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadPlan, GetStopReasonDataCount);
118baf5664fSJonas Devlieghere 
119baf5664fSJonas Devlieghere   return 0;
120baf5664fSJonas Devlieghere }
121baf5664fSJonas Devlieghere 
122baf5664fSJonas Devlieghere uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) {
123baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
124baf5664fSJonas Devlieghere                      (uint32_t), idx);
125baf5664fSJonas Devlieghere 
126baf5664fSJonas Devlieghere   return 0;
127baf5664fSJonas Devlieghere }
1282bdbfd50SJim Ingham 
129b9c1b51eSKate Stone SBThread SBThreadPlan::GetThread() const {
130baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBThreadPlan, GetThread);
131baf5664fSJonas Devlieghere 
132b9c1b51eSKate Stone   if (m_opaque_sp) {
133baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(
134baf5664fSJonas Devlieghere         SBThread(m_opaque_sp->GetThread().shared_from_this()));
135b9c1b51eSKate Stone   } else
136baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThread());
1372bdbfd50SJim Ingham }
1382bdbfd50SJim Ingham 
139b9c1b51eSKate Stone bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
140baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST(bool, SBThreadPlan, GetDescription,
141baf5664fSJonas Devlieghere                            (lldb::SBStream &), description);
142baf5664fSJonas Devlieghere 
143b9c1b51eSKate Stone   if (m_opaque_sp) {
1442bdbfd50SJim Ingham     m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull);
145b9c1b51eSKate Stone   } else {
1462bdbfd50SJim Ingham     description.Printf("Empty SBThreadPlan");
1472bdbfd50SJim Ingham   }
1482bdbfd50SJim Ingham   return true;
1492bdbfd50SJim Ingham }
1502bdbfd50SJim Ingham 
151b9c1b51eSKate Stone void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) {
1522bdbfd50SJim Ingham   m_opaque_sp = lldb_object_sp;
1532bdbfd50SJim Ingham }
1542bdbfd50SJim Ingham 
155b9c1b51eSKate Stone void SBThreadPlan::SetPlanComplete(bool success) {
156baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBThreadPlan, SetPlanComplete, (bool), success);
157baf5664fSJonas Devlieghere 
1582bdbfd50SJim Ingham   if (m_opaque_sp)
1592bdbfd50SJim Ingham     m_opaque_sp->SetPlanComplete(success);
1602bdbfd50SJim Ingham }
1612bdbfd50SJim Ingham 
162b9c1b51eSKate Stone bool SBThreadPlan::IsPlanComplete() {
163baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanComplete);
164baf5664fSJonas Devlieghere 
1652bdbfd50SJim Ingham   if (m_opaque_sp)
1662bdbfd50SJim Ingham     return m_opaque_sp->IsPlanComplete();
1672bdbfd50SJim Ingham   else
1682bdbfd50SJim Ingham     return true;
1692bdbfd50SJim Ingham }
1702bdbfd50SJim Ingham 
171b9c1b51eSKate Stone bool SBThreadPlan::IsPlanStale() {
172baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanStale);
173baf5664fSJonas Devlieghere 
174c915a7d2SJim Ingham   if (m_opaque_sp)
175c915a7d2SJim Ingham     return m_opaque_sp->IsPlanStale();
176c915a7d2SJim Ingham   else
177c915a7d2SJim Ingham     return true;
178c915a7d2SJim Ingham }
179c915a7d2SJim Ingham 
180b9c1b51eSKate Stone bool SBThreadPlan::IsValid() {
181baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsValid);
182baf5664fSJonas Devlieghere 
1832bdbfd50SJim Ingham   if (m_opaque_sp)
1842bdbfd50SJim Ingham     return m_opaque_sp->ValidatePlan(nullptr);
1852bdbfd50SJim Ingham   else
1862bdbfd50SJim Ingham     return false;
1872bdbfd50SJim Ingham }
1882bdbfd50SJim Ingham 
189b9c1b51eSKate Stone // This section allows an SBThreadPlan to push another of the common types of
190b9c1b51eSKate Stone // plans...
1912bdbfd50SJim Ingham //
192b9c1b51eSKate Stone // FIXME, you should only be able to queue thread plans from inside the methods
19305097246SAdrian Prantl // of a Scripted Thread Plan.  Need a way to enforce that.
1942bdbfd50SJim Ingham 
1952bdbfd50SJim Ingham SBThreadPlan
1962bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
197b9c1b51eSKate Stone                                               lldb::addr_t size) {
198baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
199baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
200baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
201baf5664fSJonas Devlieghere 
202e103ae92SJonas Devlieghere   SBError error;
203baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
204baf5664fSJonas Devlieghere       QueueThreadPlanForStepOverRange(sb_start_address, size, error));
205e103ae92SJonas Devlieghere }
206e103ae92SJonas Devlieghere 
207e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOverRange(
208e103ae92SJonas Devlieghere     SBAddress &sb_start_address, lldb::addr_t size, SBError &error) {
209baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
210baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
211baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
212baf5664fSJonas Devlieghere                      sb_start_address, size, error);
213baf5664fSJonas Devlieghere 
214b9c1b51eSKate Stone   if (m_opaque_sp) {
2152bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
216b9c1b51eSKate Stone     if (!start_address) {
217baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
2182bdbfd50SJim Ingham     }
2192bdbfd50SJim Ingham 
2202bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2212bdbfd50SJim Ingham     SymbolContext sc;
2222bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
223e103ae92SJonas Devlieghere     Status plan_status;
224e103ae92SJonas Devlieghere 
225e103ae92SJonas Devlieghere     SBThreadPlan plan =
226e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange(
227e103ae92SJonas Devlieghere             false, range, sc, eAllThreads, plan_status));
228e103ae92SJonas Devlieghere 
229e103ae92SJonas Devlieghere     if (plan_status.Fail())
230e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
231e103ae92SJonas Devlieghere 
232baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
233b9c1b51eSKate Stone   } else {
234baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
2352bdbfd50SJim Ingham   }
2362bdbfd50SJim Ingham }
2372bdbfd50SJim Ingham 
2382bdbfd50SJim Ingham SBThreadPlan
2392bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
240b9c1b51eSKate Stone                                             lldb::addr_t size) {
241baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
242baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
243baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
244baf5664fSJonas Devlieghere 
245e103ae92SJonas Devlieghere   SBError error;
246baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
247baf5664fSJonas Devlieghere       QueueThreadPlanForStepInRange(sb_start_address, size, error));
248e103ae92SJonas Devlieghere }
249e103ae92SJonas Devlieghere 
250e103ae92SJonas Devlieghere SBThreadPlan
251e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
252e103ae92SJonas Devlieghere                                             lldb::addr_t size, SBError &error) {
253baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
254baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
255baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
256baf5664fSJonas Devlieghere                      sb_start_address, size, error);
257baf5664fSJonas Devlieghere 
258b9c1b51eSKate Stone   if (m_opaque_sp) {
2592bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
260b9c1b51eSKate Stone     if (!start_address) {
261baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
2622bdbfd50SJim Ingham     }
2632bdbfd50SJim Ingham 
2642bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2652bdbfd50SJim Ingham     SymbolContext sc;
2662bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
267e103ae92SJonas Devlieghere 
268e103ae92SJonas Devlieghere     Status plan_status;
269e103ae92SJonas Devlieghere     SBThreadPlan plan =
270e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange(
271e103ae92SJonas Devlieghere             false, range, sc, NULL, eAllThreads, plan_status));
272e103ae92SJonas Devlieghere 
273e103ae92SJonas Devlieghere     if (plan_status.Fail())
274e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
275e103ae92SJonas Devlieghere 
276baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
277b9c1b51eSKate Stone   } else {
278baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
2792bdbfd50SJim Ingham   }
2802bdbfd50SJim Ingham }
2812bdbfd50SJim Ingham 
2822bdbfd50SJim Ingham SBThreadPlan
283b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
284b9c1b51eSKate Stone                                         bool first_insn) {
285baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
286baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut, (uint32_t, bool),
287baf5664fSJonas Devlieghere                      frame_idx_to_step_to, first_insn);
288baf5664fSJonas Devlieghere 
289e103ae92SJonas Devlieghere   SBError error;
290baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
291baf5664fSJonas Devlieghere       QueueThreadPlanForStepOut(frame_idx_to_step_to, first_insn, error));
292e103ae92SJonas Devlieghere }
293e103ae92SJonas Devlieghere 
294e103ae92SJonas Devlieghere SBThreadPlan
295e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
296e103ae92SJonas Devlieghere                                         bool first_insn, SBError &error) {
297baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
298baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut,
299baf5664fSJonas Devlieghere                      (uint32_t, bool, lldb::SBError &), frame_idx_to_step_to,
300baf5664fSJonas Devlieghere                      first_insn, error);
301baf5664fSJonas Devlieghere 
302b9c1b51eSKate Stone   if (m_opaque_sp) {
3032bdbfd50SJim Ingham     SymbolContext sc;
304b9c1b51eSKate Stone     sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
305b9c1b51eSKate Stone         lldb::eSymbolContextEverything);
306e103ae92SJonas Devlieghere 
307e103ae92SJonas Devlieghere     Status plan_status;
308e103ae92SJonas Devlieghere     SBThreadPlan plan =
309e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut(
310b9c1b51eSKate Stone             false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
311e103ae92SJonas Devlieghere             frame_idx_to_step_to, plan_status));
312e103ae92SJonas Devlieghere 
313e103ae92SJonas Devlieghere     if (plan_status.Fail())
314e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
315e103ae92SJonas Devlieghere 
316baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
317b9c1b51eSKate Stone   } else {
318baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
3192bdbfd50SJim Ingham   }
3202bdbfd50SJim Ingham }
3212bdbfd50SJim Ingham 
3222bdbfd50SJim Ingham SBThreadPlan
323b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
324baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
325baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress, (lldb::SBAddress),
326baf5664fSJonas Devlieghere                      sb_address);
327baf5664fSJonas Devlieghere 
328e103ae92SJonas Devlieghere   SBError error;
329baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(QueueThreadPlanForRunToAddress(sb_address, error));
330e103ae92SJonas Devlieghere }
331e103ae92SJonas Devlieghere 
332e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address,
333e103ae92SJonas Devlieghere                                                           SBError &error) {
334baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
335baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress,
336baf5664fSJonas Devlieghere                      (lldb::SBAddress, lldb::SBError &), sb_address, error);
337baf5664fSJonas Devlieghere 
338b9c1b51eSKate Stone   if (m_opaque_sp) {
3392bdbfd50SJim Ingham     Address *address = sb_address.get();
3402bdbfd50SJim Ingham     if (!address)
341baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
3422bdbfd50SJim Ingham 
343e103ae92SJonas Devlieghere     Status plan_status;
344e103ae92SJonas Devlieghere     SBThreadPlan plan =
345e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress(
346e103ae92SJonas Devlieghere             false, *address, false, plan_status));
347e103ae92SJonas Devlieghere 
348e103ae92SJonas Devlieghere     if (plan_status.Fail())
349e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
350e103ae92SJonas Devlieghere 
351baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
352b9c1b51eSKate Stone   } else {
353baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
3542bdbfd50SJim Ingham   }
3552bdbfd50SJim Ingham }
356c1c0fac7SAleksandr Urakov 
357c1c0fac7SAleksandr Urakov SBThreadPlan
358c1c0fac7SAleksandr Urakov SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name) {
359baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
360baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted, (const char *),
361baf5664fSJonas Devlieghere                      script_class_name);
362baf5664fSJonas Devlieghere 
363e103ae92SJonas Devlieghere   SBError error;
364baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
365baf5664fSJonas Devlieghere       QueueThreadPlanForStepScripted(script_class_name, error));
366e103ae92SJonas Devlieghere }
367e103ae92SJonas Devlieghere 
368e103ae92SJonas Devlieghere SBThreadPlan
369e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
370e103ae92SJonas Devlieghere                                              SBError &error) {
371baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
372baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted,
373baf5664fSJonas Devlieghere                      (const char *, lldb::SBError &), script_class_name, error);
374baf5664fSJonas Devlieghere 
375c1c0fac7SAleksandr Urakov   if (m_opaque_sp) {
376e103ae92SJonas Devlieghere     Status plan_status;
377e103ae92SJonas Devlieghere     SBThreadPlan plan =
378e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepScripted(
379e103ae92SJonas Devlieghere             false, script_class_name, false, plan_status));
380e103ae92SJonas Devlieghere 
381e103ae92SJonas Devlieghere     if (plan_status.Fail())
382e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
383e103ae92SJonas Devlieghere 
384baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
385c1c0fac7SAleksandr Urakov   } else {
386baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
387c1c0fac7SAleksandr Urakov   }
388c1c0fac7SAleksandr Urakov }
389ae211eceSMichal Gorny 
390ae211eceSMichal Gorny namespace lldb_private {
391ae211eceSMichal Gorny namespace repro {
392ae211eceSMichal Gorny 
393ae211eceSMichal Gorny template <>
394ae211eceSMichal Gorny void RegisterMethods<SBThreadPlan>(Registry &R) {
395ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, ());
396ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::ThreadPlanSP &));
397ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::SBThreadPlan &));
398ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *));
399ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(const lldb::SBThreadPlan &,
400ae211eceSMichal Gorny                        SBThreadPlan, operator=,(const lldb::SBThreadPlan &));
401ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, IsValid, ());
402ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, operator bool, ());
403ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBThreadPlan, Clear, ());
404ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::StopReason, SBThreadPlan, GetStopReason, ());
405ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(size_t, SBThreadPlan, GetStopReasonDataCount, ());
406ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
407ae211eceSMichal Gorny                        (uint32_t));
408ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBThreadPlan, GetThread, ());
409ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, GetDescription,
410ae211eceSMichal Gorny                              (lldb::SBStream &));
411ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBThreadPlan, SetPlanComplete, (bool));
412ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanComplete, ());
413ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanStale, ());
414ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsValid, ());
415ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
416ae211eceSMichal Gorny                        QueueThreadPlanForStepOverRange,
417ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t));
418ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
419ae211eceSMichal Gorny                        QueueThreadPlanForStepOverRange,
420ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
421ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
422ae211eceSMichal Gorny                        QueueThreadPlanForStepInRange,
423ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t));
424ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
425ae211eceSMichal Gorny                        QueueThreadPlanForStepInRange,
426ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
427ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
428ae211eceSMichal Gorny                        QueueThreadPlanForStepOut, (uint32_t, bool));
429ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
430ae211eceSMichal Gorny                        QueueThreadPlanForStepOut,
431ae211eceSMichal Gorny                        (uint32_t, bool, lldb::SBError &));
432ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
433ae211eceSMichal Gorny                        QueueThreadPlanForRunToAddress, (lldb::SBAddress));
434ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
435ae211eceSMichal Gorny                        QueueThreadPlanForRunToAddress,
436ae211eceSMichal Gorny                        (lldb::SBAddress, lldb::SBError &));
437ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
438ae211eceSMichal Gorny                        QueueThreadPlanForStepScripted, (const char *));
439ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
440ae211eceSMichal Gorny                        QueueThreadPlanForStepScripted,
441ae211eceSMichal Gorny                        (const char *, lldb::SBError &));
442ae211eceSMichal Gorny }
443ae211eceSMichal Gorny 
444ae211eceSMichal Gorny }
445ae211eceSMichal Gorny }
446