180814287SRaphael Isemann //===-- SBThreadPlan.cpp --------------------------------------------------===//
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"
1427a14f19SJim Ingham #include "lldb/API/SBStructuredData.h"
15b9c1b51eSKate Stone #include "lldb/API/SBSymbolContext.h"
162bdbfd50SJim Ingham #include "lldb/Breakpoint/BreakpointLocation.h"
172bdbfd50SJim Ingham #include "lldb/Core/Debugger.h"
182bdbfd50SJim Ingham #include "lldb/Core/StreamFile.h"
1927a14f19SJim Ingham #include "lldb/Core/StructuredDataImpl.h"
202bdbfd50SJim Ingham #include "lldb/Interpreter/CommandInterpreter.h"
21b9c1b51eSKate Stone #include "lldb/Symbol/CompileUnit.h"
22b9c1b51eSKate Stone #include "lldb/Symbol/SymbolContext.h"
232bdbfd50SJim Ingham #include "lldb/Target/Process.h"
242bdbfd50SJim Ingham #include "lldb/Target/Queue.h"
252bdbfd50SJim Ingham #include "lldb/Target/StopInfo.h"
26b9c1b51eSKate Stone #include "lldb/Target/SystemRuntime.h"
272bdbfd50SJim Ingham #include "lldb/Target/Target.h"
28b9c1b51eSKate Stone #include "lldb/Target/Thread.h"
29b9c1b51eSKate Stone #include "lldb/Target/ThreadPlan.h"
302bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanPython.h"
31b9c1b51eSKate Stone #include "lldb/Target/ThreadPlanStepInRange.h"
322bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanStepInstruction.h"
332bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanStepOut.h"
342bdbfd50SJim Ingham #include "lldb/Target/ThreadPlanStepRange.h"
35d821c997SPavel Labath #include "lldb/Utility/State.h"
36bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
37f2a8bccfSPavel Labath #include "lldb/Utility/StructuredData.h"
382bdbfd50SJim Ingham 
392bdbfd50SJim Ingham #include "lldb/API/SBAddress.h"
402bdbfd50SJim Ingham #include "lldb/API/SBDebugger.h"
412bdbfd50SJim Ingham #include "lldb/API/SBEvent.h"
422bdbfd50SJim Ingham #include "lldb/API/SBFrame.h"
432bdbfd50SJim Ingham #include "lldb/API/SBProcess.h"
442bdbfd50SJim Ingham #include "lldb/API/SBThreadPlan.h"
452bdbfd50SJim Ingham #include "lldb/API/SBValue.h"
462bdbfd50SJim Ingham 
47796ac80bSJonas Devlieghere #include <memory>
48796ac80bSJonas Devlieghere 
492bdbfd50SJim Ingham using namespace lldb;
502bdbfd50SJim Ingham using namespace lldb_private;
512bdbfd50SJim Ingham 
522bdbfd50SJim Ingham // Constructors
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)
7227a14f19SJim Ingham     m_opaque_sp = std::make_shared<ThreadPlanPython>(*thread, class_name,
7327a14f19SJim Ingham                                                      nullptr);
7427a14f19SJim Ingham }
7527a14f19SJim Ingham 
7627a14f19SJim Ingham SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name,
7727a14f19SJim Ingham                            lldb::SBStructuredData &args_data) {
7827a14f19SJim Ingham   LLDB_RECORD_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *,
7927a14f19SJim Ingham                                          SBStructuredData &),
8027a14f19SJim Ingham                           sb_thread, class_name, args_data);
8127a14f19SJim Ingham 
8227a14f19SJim Ingham   Thread *thread = sb_thread.get();
8327a14f19SJim Ingham   if (thread)
8427a14f19SJim Ingham     m_opaque_sp = std::make_shared<ThreadPlanPython>(*thread, class_name,
8527a14f19SJim Ingham                                                      args_data.m_impl_up.get());
862bdbfd50SJim Ingham }
872bdbfd50SJim Ingham 
882bdbfd50SJim Ingham // Assignment operator
892bdbfd50SJim Ingham 
90b9c1b51eSKate Stone const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) {
91baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(const lldb::SBThreadPlan &,
92baf5664fSJonas Devlieghere                      SBThreadPlan, operator=,(const lldb::SBThreadPlan &), rhs);
93baf5664fSJonas Devlieghere 
942bdbfd50SJim Ingham   if (this != &rhs)
952bdbfd50SJim Ingham     m_opaque_sp = rhs.m_opaque_sp;
96306809f2SJonas Devlieghere   return LLDB_RECORD_RESULT(*this);
972bdbfd50SJim Ingham }
982bdbfd50SJim Ingham // Destructor
99866b7a65SJonas Devlieghere SBThreadPlan::~SBThreadPlan() = default;
1002bdbfd50SJim Ingham 
10126ca5a57SPavel Labath lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); }
1022bdbfd50SJim Ingham 
103baf5664fSJonas Devlieghere bool SBThreadPlan::IsValid() const {
104baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, IsValid);
1057f5237bcSPavel Labath   return this->operator bool();
1067f5237bcSPavel Labath }
1077f5237bcSPavel Labath SBThreadPlan::operator bool() const {
1087f5237bcSPavel Labath   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, operator bool);
1092bdbfd50SJim Ingham 
110248a1305SKonrad Kleine   return m_opaque_sp.get() != nullptr;
111baf5664fSJonas Devlieghere }
1122bdbfd50SJim Ingham 
113baf5664fSJonas Devlieghere void SBThreadPlan::Clear() {
114baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(void, SBThreadPlan, Clear);
1152bdbfd50SJim Ingham 
116baf5664fSJonas Devlieghere   m_opaque_sp.reset();
117baf5664fSJonas Devlieghere }
118baf5664fSJonas Devlieghere 
119baf5664fSJonas Devlieghere lldb::StopReason SBThreadPlan::GetStopReason() {
120baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(lldb::StopReason, SBThreadPlan, GetStopReason);
121baf5664fSJonas Devlieghere 
122baf5664fSJonas Devlieghere   return eStopReasonNone;
123baf5664fSJonas Devlieghere }
124baf5664fSJonas Devlieghere 
125baf5664fSJonas Devlieghere size_t SBThreadPlan::GetStopReasonDataCount() {
126baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadPlan, GetStopReasonDataCount);
127baf5664fSJonas Devlieghere 
128baf5664fSJonas Devlieghere   return 0;
129baf5664fSJonas Devlieghere }
130baf5664fSJonas Devlieghere 
131baf5664fSJonas Devlieghere uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) {
132baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
133baf5664fSJonas Devlieghere                      (uint32_t), idx);
134baf5664fSJonas Devlieghere 
135baf5664fSJonas Devlieghere   return 0;
136baf5664fSJonas Devlieghere }
1372bdbfd50SJim Ingham 
138b9c1b51eSKate Stone SBThread SBThreadPlan::GetThread() const {
139baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBThreadPlan, GetThread);
140baf5664fSJonas Devlieghere 
141b9c1b51eSKate Stone   if (m_opaque_sp) {
142baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(
143baf5664fSJonas Devlieghere         SBThread(m_opaque_sp->GetThread().shared_from_this()));
144b9c1b51eSKate Stone   } else
145baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThread());
1462bdbfd50SJim Ingham }
1472bdbfd50SJim Ingham 
148b9c1b51eSKate Stone bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
149baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST(bool, SBThreadPlan, GetDescription,
150baf5664fSJonas Devlieghere                            (lldb::SBStream &), description);
151baf5664fSJonas Devlieghere 
152b9c1b51eSKate Stone   if (m_opaque_sp) {
1532bdbfd50SJim Ingham     m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull);
154b9c1b51eSKate Stone   } else {
1552bdbfd50SJim Ingham     description.Printf("Empty SBThreadPlan");
1562bdbfd50SJim Ingham   }
1572bdbfd50SJim Ingham   return true;
1582bdbfd50SJim Ingham }
1592bdbfd50SJim Ingham 
160b9c1b51eSKate Stone void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) {
1612bdbfd50SJim Ingham   m_opaque_sp = lldb_object_sp;
1622bdbfd50SJim Ingham }
1632bdbfd50SJim Ingham 
164b9c1b51eSKate Stone void SBThreadPlan::SetPlanComplete(bool success) {
165baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBThreadPlan, SetPlanComplete, (bool), success);
166baf5664fSJonas Devlieghere 
1672bdbfd50SJim Ingham   if (m_opaque_sp)
1682bdbfd50SJim Ingham     m_opaque_sp->SetPlanComplete(success);
1692bdbfd50SJim Ingham }
1702bdbfd50SJim Ingham 
171b9c1b51eSKate Stone bool SBThreadPlan::IsPlanComplete() {
172baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanComplete);
173baf5664fSJonas Devlieghere 
1742bdbfd50SJim Ingham   if (m_opaque_sp)
1752bdbfd50SJim Ingham     return m_opaque_sp->IsPlanComplete();
1762bdbfd50SJim Ingham   else
1772bdbfd50SJim Ingham     return true;
1782bdbfd50SJim Ingham }
1792bdbfd50SJim Ingham 
180b9c1b51eSKate Stone bool SBThreadPlan::IsPlanStale() {
181baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanStale);
182baf5664fSJonas Devlieghere 
183c915a7d2SJim Ingham   if (m_opaque_sp)
184c915a7d2SJim Ingham     return m_opaque_sp->IsPlanStale();
185c915a7d2SJim Ingham   else
186c915a7d2SJim Ingham     return true;
187c915a7d2SJim Ingham }
188c915a7d2SJim Ingham 
189b9c1b51eSKate Stone bool SBThreadPlan::IsValid() {
190baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsValid);
191baf5664fSJonas Devlieghere 
1922bdbfd50SJim Ingham   if (m_opaque_sp)
1932bdbfd50SJim Ingham     return m_opaque_sp->ValidatePlan(nullptr);
1942bdbfd50SJim Ingham   else
1952bdbfd50SJim Ingham     return false;
1962bdbfd50SJim Ingham }
1972bdbfd50SJim Ingham 
198b9c1b51eSKate Stone // This section allows an SBThreadPlan to push another of the common types of
199b9c1b51eSKate Stone // plans...
2002bdbfd50SJim Ingham //
201b9c1b51eSKate Stone // FIXME, you should only be able to queue thread plans from inside the methods
20205097246SAdrian Prantl // of a Scripted Thread Plan.  Need a way to enforce that.
2032bdbfd50SJim Ingham 
2042bdbfd50SJim Ingham SBThreadPlan
2052bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
206b9c1b51eSKate Stone                                               lldb::addr_t size) {
207baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
208baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
209baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
210baf5664fSJonas Devlieghere 
211e103ae92SJonas Devlieghere   SBError error;
212baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
213baf5664fSJonas Devlieghere       QueueThreadPlanForStepOverRange(sb_start_address, size, error));
214e103ae92SJonas Devlieghere }
215e103ae92SJonas Devlieghere 
216e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOverRange(
217e103ae92SJonas Devlieghere     SBAddress &sb_start_address, lldb::addr_t size, SBError &error) {
218baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
219baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
220baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
221baf5664fSJonas Devlieghere                      sb_start_address, size, error);
222baf5664fSJonas Devlieghere 
223b9c1b51eSKate Stone   if (m_opaque_sp) {
2242bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
225b9c1b51eSKate Stone     if (!start_address) {
226baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
2272bdbfd50SJim Ingham     }
2282bdbfd50SJim Ingham 
2292bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2302bdbfd50SJim Ingham     SymbolContext sc;
2312bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
232e103ae92SJonas Devlieghere     Status plan_status;
233e103ae92SJonas Devlieghere 
234e103ae92SJonas Devlieghere     SBThreadPlan plan =
235e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange(
236e103ae92SJonas Devlieghere             false, range, sc, eAllThreads, plan_status));
237e103ae92SJonas Devlieghere 
238e103ae92SJonas Devlieghere     if (plan_status.Fail())
239e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
240*f7de4b5dSJim Ingham     else
241*f7de4b5dSJim Ingham       plan.m_opaque_sp->SetPrivate(true);
242e103ae92SJonas Devlieghere 
243baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
244b9c1b51eSKate Stone   } else {
245baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
2462bdbfd50SJim Ingham   }
2472bdbfd50SJim Ingham }
2482bdbfd50SJim Ingham 
2492bdbfd50SJim Ingham SBThreadPlan
2502bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
251b9c1b51eSKate Stone                                             lldb::addr_t size) {
252baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
253baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
254baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
255baf5664fSJonas Devlieghere 
256e103ae92SJonas Devlieghere   SBError error;
257baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
258baf5664fSJonas Devlieghere       QueueThreadPlanForStepInRange(sb_start_address, size, error));
259e103ae92SJonas Devlieghere }
260e103ae92SJonas Devlieghere 
261e103ae92SJonas Devlieghere SBThreadPlan
262e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
263e103ae92SJonas Devlieghere                                             lldb::addr_t size, SBError &error) {
264baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
265baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
266baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
267baf5664fSJonas Devlieghere                      sb_start_address, size, error);
268baf5664fSJonas Devlieghere 
269b9c1b51eSKate Stone   if (m_opaque_sp) {
2702bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
271b9c1b51eSKate Stone     if (!start_address) {
272baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
2732bdbfd50SJim Ingham     }
2742bdbfd50SJim Ingham 
2752bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2762bdbfd50SJim Ingham     SymbolContext sc;
2772bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
278e103ae92SJonas Devlieghere 
279e103ae92SJonas Devlieghere     Status plan_status;
280e103ae92SJonas Devlieghere     SBThreadPlan plan =
281e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange(
282248a1305SKonrad Kleine             false, range, sc, nullptr, eAllThreads, plan_status));
283e103ae92SJonas Devlieghere 
284e103ae92SJonas Devlieghere     if (plan_status.Fail())
285e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
286*f7de4b5dSJim Ingham     else
287*f7de4b5dSJim Ingham       plan.m_opaque_sp->SetPrivate(true);
288e103ae92SJonas Devlieghere 
289baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
290b9c1b51eSKate Stone   } else {
291baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
2922bdbfd50SJim Ingham   }
2932bdbfd50SJim Ingham }
2942bdbfd50SJim Ingham 
2952bdbfd50SJim Ingham SBThreadPlan
296b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
297b9c1b51eSKate Stone                                         bool first_insn) {
298baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
299baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut, (uint32_t, bool),
300baf5664fSJonas Devlieghere                      frame_idx_to_step_to, first_insn);
301baf5664fSJonas Devlieghere 
302e103ae92SJonas Devlieghere   SBError error;
303baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
304baf5664fSJonas Devlieghere       QueueThreadPlanForStepOut(frame_idx_to_step_to, first_insn, error));
305e103ae92SJonas Devlieghere }
306e103ae92SJonas Devlieghere 
307e103ae92SJonas Devlieghere SBThreadPlan
308e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
309e103ae92SJonas Devlieghere                                         bool first_insn, SBError &error) {
310baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
311baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut,
312baf5664fSJonas Devlieghere                      (uint32_t, bool, lldb::SBError &), frame_idx_to_step_to,
313baf5664fSJonas Devlieghere                      first_insn, error);
314baf5664fSJonas Devlieghere 
315b9c1b51eSKate Stone   if (m_opaque_sp) {
3162bdbfd50SJim Ingham     SymbolContext sc;
317b9c1b51eSKate Stone     sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
318b9c1b51eSKate Stone         lldb::eSymbolContextEverything);
319e103ae92SJonas Devlieghere 
320e103ae92SJonas Devlieghere     Status plan_status;
321e103ae92SJonas Devlieghere     SBThreadPlan plan =
322e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut(
323b9c1b51eSKate Stone             false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
324e103ae92SJonas Devlieghere             frame_idx_to_step_to, plan_status));
325e103ae92SJonas Devlieghere 
326e103ae92SJonas Devlieghere     if (plan_status.Fail())
327e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
328*f7de4b5dSJim Ingham     else
329*f7de4b5dSJim Ingham       plan.m_opaque_sp->SetPrivate(true);
330e103ae92SJonas Devlieghere 
331baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
332b9c1b51eSKate Stone   } else {
333baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
3342bdbfd50SJim Ingham   }
3352bdbfd50SJim Ingham }
3362bdbfd50SJim Ingham 
3372bdbfd50SJim Ingham SBThreadPlan
338b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
339baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
340baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress, (lldb::SBAddress),
341baf5664fSJonas Devlieghere                      sb_address);
342baf5664fSJonas Devlieghere 
343e103ae92SJonas Devlieghere   SBError error;
344baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(QueueThreadPlanForRunToAddress(sb_address, error));
345e103ae92SJonas Devlieghere }
346e103ae92SJonas Devlieghere 
347e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address,
348e103ae92SJonas Devlieghere                                                           SBError &error) {
349baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
350baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress,
351baf5664fSJonas Devlieghere                      (lldb::SBAddress, lldb::SBError &), sb_address, error);
352baf5664fSJonas Devlieghere 
353b9c1b51eSKate Stone   if (m_opaque_sp) {
3542bdbfd50SJim Ingham     Address *address = sb_address.get();
3552bdbfd50SJim Ingham     if (!address)
356baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
3572bdbfd50SJim Ingham 
358e103ae92SJonas Devlieghere     Status plan_status;
359e103ae92SJonas Devlieghere     SBThreadPlan plan =
360e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress(
361e103ae92SJonas Devlieghere             false, *address, false, plan_status));
362e103ae92SJonas Devlieghere 
363e103ae92SJonas Devlieghere     if (plan_status.Fail())
364e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
365*f7de4b5dSJim Ingham     else
366*f7de4b5dSJim Ingham       plan.m_opaque_sp->SetPrivate(true);
367e103ae92SJonas Devlieghere 
368baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
369b9c1b51eSKate Stone   } else {
370baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
3712bdbfd50SJim Ingham   }
3722bdbfd50SJim Ingham }
373c1c0fac7SAleksandr Urakov 
374c1c0fac7SAleksandr Urakov SBThreadPlan
375c1c0fac7SAleksandr Urakov SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name) {
376baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
377baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted, (const char *),
378baf5664fSJonas Devlieghere                      script_class_name);
379baf5664fSJonas Devlieghere 
380e103ae92SJonas Devlieghere   SBError error;
381baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
382baf5664fSJonas Devlieghere       QueueThreadPlanForStepScripted(script_class_name, error));
383e103ae92SJonas Devlieghere }
384e103ae92SJonas Devlieghere 
385e103ae92SJonas Devlieghere SBThreadPlan
386e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
387e103ae92SJonas Devlieghere                                              SBError &error) {
388baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
389baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted,
390baf5664fSJonas Devlieghere                      (const char *, lldb::SBError &), script_class_name, error);
391baf5664fSJonas Devlieghere 
392c1c0fac7SAleksandr Urakov   if (m_opaque_sp) {
393e103ae92SJonas Devlieghere     Status plan_status;
39427a14f19SJim Ingham     StructuredData::ObjectSP empty_args;
395e103ae92SJonas Devlieghere     SBThreadPlan plan =
396e103ae92SJonas Devlieghere         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepScripted(
39727a14f19SJim Ingham             false, script_class_name, empty_args, false, plan_status));
39827a14f19SJim Ingham 
39927a14f19SJim Ingham     if (plan_status.Fail())
40027a14f19SJim Ingham       error.SetErrorString(plan_status.AsCString());
401*f7de4b5dSJim Ingham     else
402*f7de4b5dSJim Ingham       plan.m_opaque_sp->SetPrivate(true);
40327a14f19SJim Ingham 
40427a14f19SJim Ingham     return LLDB_RECORD_RESULT(plan);
40527a14f19SJim Ingham   } else {
40627a14f19SJim Ingham     return LLDB_RECORD_RESULT(SBThreadPlan());
40727a14f19SJim Ingham   }
40827a14f19SJim Ingham }
40927a14f19SJim Ingham 
41027a14f19SJim Ingham SBThreadPlan
41127a14f19SJim Ingham SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
41227a14f19SJim Ingham                                              lldb::SBStructuredData &args_data,
41327a14f19SJim Ingham                                              SBError &error) {
41427a14f19SJim Ingham   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
41527a14f19SJim Ingham                      QueueThreadPlanForStepScripted,
41627a14f19SJim Ingham                      (const char *, lldb::SBStructuredData &, lldb::SBError &),
41727a14f19SJim Ingham                      script_class_name, args_data, error);
41827a14f19SJim Ingham 
41927a14f19SJim Ingham   if (m_opaque_sp) {
42027a14f19SJim Ingham     Status plan_status;
42127a14f19SJim Ingham     StructuredData::ObjectSP args_obj = args_data.m_impl_up->GetObjectSP();
42227a14f19SJim Ingham     SBThreadPlan plan =
42327a14f19SJim Ingham         SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepScripted(
42427a14f19SJim Ingham             false, script_class_name, args_obj, false, plan_status));
425e103ae92SJonas Devlieghere 
426e103ae92SJonas Devlieghere     if (plan_status.Fail())
427e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
428*f7de4b5dSJim Ingham     else
429*f7de4b5dSJim Ingham       plan.m_opaque_sp->SetPrivate(true);
430e103ae92SJonas Devlieghere 
431baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
432c1c0fac7SAleksandr Urakov   } else {
433baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
434c1c0fac7SAleksandr Urakov   }
435c1c0fac7SAleksandr Urakov }
436ae211eceSMichal Gorny 
437ae211eceSMichal Gorny namespace lldb_private {
438ae211eceSMichal Gorny namespace repro {
439ae211eceSMichal Gorny 
440ae211eceSMichal Gorny template <>
441ae211eceSMichal Gorny void RegisterMethods<SBThreadPlan>(Registry &R) {
442ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, ());
443ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::ThreadPlanSP &));
444ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::SBThreadPlan &));
445ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *));
44627a14f19SJim Ingham   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *,
44727a14f19SJim Ingham                        lldb::SBStructuredData &));
448ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(const lldb::SBThreadPlan &,
449ae211eceSMichal Gorny                        SBThreadPlan, operator=,(const lldb::SBThreadPlan &));
450ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, IsValid, ());
451ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, operator bool, ());
452ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBThreadPlan, Clear, ());
453ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::StopReason, SBThreadPlan, GetStopReason, ());
454ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(size_t, SBThreadPlan, GetStopReasonDataCount, ());
455ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
456ae211eceSMichal Gorny                        (uint32_t));
457ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBThreadPlan, GetThread, ());
458ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, GetDescription,
459ae211eceSMichal Gorny                              (lldb::SBStream &));
460ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBThreadPlan, SetPlanComplete, (bool));
461ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanComplete, ());
462ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanStale, ());
463ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsValid, ());
464ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
465ae211eceSMichal Gorny                        QueueThreadPlanForStepOverRange,
466ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t));
467ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
468ae211eceSMichal Gorny                        QueueThreadPlanForStepOverRange,
469ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
470ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
471ae211eceSMichal Gorny                        QueueThreadPlanForStepInRange,
472ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t));
473ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
474ae211eceSMichal Gorny                        QueueThreadPlanForStepInRange,
475ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
476ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
477ae211eceSMichal Gorny                        QueueThreadPlanForStepOut, (uint32_t, bool));
478ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
479ae211eceSMichal Gorny                        QueueThreadPlanForStepOut,
480ae211eceSMichal Gorny                        (uint32_t, bool, lldb::SBError &));
481ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
482ae211eceSMichal Gorny                        QueueThreadPlanForRunToAddress, (lldb::SBAddress));
483ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
484ae211eceSMichal Gorny                        QueueThreadPlanForRunToAddress,
485ae211eceSMichal Gorny                        (lldb::SBAddress, lldb::SBError &));
486ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
487ae211eceSMichal Gorny                        QueueThreadPlanForStepScripted, (const char *));
488ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
489ae211eceSMichal Gorny                        QueueThreadPlanForStepScripted,
490ae211eceSMichal Gorny                        (const char *, lldb::SBError &));
49127a14f19SJim Ingham   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
49227a14f19SJim Ingham                        QueueThreadPlanForStepScripted,
49327a14f19SJim Ingham                        (const char *, lldb::SBStructuredData &,
49427a14f19SJim Ingham                        lldb::SBError &));
495ae211eceSMichal Gorny }
496ae211eceSMichal Gorny 
497ae211eceSMichal Gorny }
498ae211eceSMichal Gorny }
499