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 
9d51402acSJonas Devlieghere #include "lldb/Utility/ReproducerInstrumentation.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)
562ba7ce40SJonas Devlieghere     : m_opaque_wp(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)
622ba7ce40SJonas Devlieghere     : m_opaque_wp(rhs.m_opaque_wp) {
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)
7282de8df2SPavel Labath     m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
7382de8df2SPavel Labath                                                      StructuredDataImpl());
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)
842ba7ce40SJonas Devlieghere     m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
8582de8df2SPavel Labath                                                      *args_data.m_impl_up);
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)
952ba7ce40SJonas Devlieghere     m_opaque_wp = rhs.m_opaque_wp;
96*d232abc3SJonas Devlieghere   return *this;
972bdbfd50SJim Ingham }
982bdbfd50SJim Ingham // Destructor
99866b7a65SJonas Devlieghere SBThreadPlan::~SBThreadPlan() = default;
1002bdbfd50SJim Ingham 
101baf5664fSJonas Devlieghere bool SBThreadPlan::IsValid() const {
102baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, IsValid);
1037f5237bcSPavel Labath   return this->operator bool();
1047f5237bcSPavel Labath }
1057f5237bcSPavel Labath SBThreadPlan::operator bool() const {
1067f5237bcSPavel Labath   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadPlan, operator bool);
1072bdbfd50SJim Ingham 
1082ba7ce40SJonas Devlieghere   return static_cast<bool>(GetSP());
109baf5664fSJonas Devlieghere }
1102bdbfd50SJim Ingham 
111baf5664fSJonas Devlieghere void SBThreadPlan::Clear() {
112baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(void, SBThreadPlan, Clear);
1132bdbfd50SJim Ingham 
1142ba7ce40SJonas Devlieghere   m_opaque_wp.reset();
115baf5664fSJonas Devlieghere }
116baf5664fSJonas Devlieghere 
117baf5664fSJonas Devlieghere lldb::StopReason SBThreadPlan::GetStopReason() {
118baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(lldb::StopReason, SBThreadPlan, GetStopReason);
119baf5664fSJonas Devlieghere 
120baf5664fSJonas Devlieghere   return eStopReasonNone;
121baf5664fSJonas Devlieghere }
122baf5664fSJonas Devlieghere 
123baf5664fSJonas Devlieghere size_t SBThreadPlan::GetStopReasonDataCount() {
124baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadPlan, GetStopReasonDataCount);
125baf5664fSJonas Devlieghere 
126baf5664fSJonas Devlieghere   return 0;
127baf5664fSJonas Devlieghere }
128baf5664fSJonas Devlieghere 
129baf5664fSJonas Devlieghere uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) {
130baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
131baf5664fSJonas Devlieghere                      (uint32_t), idx);
132baf5664fSJonas Devlieghere 
133baf5664fSJonas Devlieghere   return 0;
134baf5664fSJonas Devlieghere }
1352bdbfd50SJim Ingham 
136b9c1b51eSKate Stone SBThread SBThreadPlan::GetThread() const {
137baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBThreadPlan, GetThread);
138baf5664fSJonas Devlieghere 
1392ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1402ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
141*d232abc3SJonas Devlieghere     return SBThread(thread_plan_sp->GetThread().shared_from_this());
142b9c1b51eSKate Stone   } else
143*d232abc3SJonas Devlieghere     return SBThread();
1442bdbfd50SJim Ingham }
1452bdbfd50SJim Ingham 
146b9c1b51eSKate Stone bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
147baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST(bool, SBThreadPlan, GetDescription,
148baf5664fSJonas Devlieghere                            (lldb::SBStream &), description);
149baf5664fSJonas Devlieghere 
1502ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1512ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
1522ba7ce40SJonas Devlieghere     thread_plan_sp->GetDescription(description.get(), eDescriptionLevelFull);
153b9c1b51eSKate Stone   } else {
1542bdbfd50SJim Ingham     description.Printf("Empty SBThreadPlan");
1552bdbfd50SJim Ingham   }
1562bdbfd50SJim Ingham   return true;
1572bdbfd50SJim Ingham }
1582bdbfd50SJim Ingham 
1592ba7ce40SJonas Devlieghere void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_wp) {
1602ba7ce40SJonas Devlieghere   m_opaque_wp = lldb_object_wp;
1612bdbfd50SJim Ingham }
1622bdbfd50SJim Ingham 
163b9c1b51eSKate Stone void SBThreadPlan::SetPlanComplete(bool success) {
164baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBThreadPlan, SetPlanComplete, (bool), success);
165baf5664fSJonas Devlieghere 
1662ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1672ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1682ba7ce40SJonas Devlieghere     thread_plan_sp->SetPlanComplete(success);
1692bdbfd50SJim Ingham }
1702bdbfd50SJim Ingham 
171b9c1b51eSKate Stone bool SBThreadPlan::IsPlanComplete() {
172baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanComplete);
173baf5664fSJonas Devlieghere 
1742ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1752ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1762ba7ce40SJonas Devlieghere     return thread_plan_sp->IsPlanComplete();
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 
1832ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1842ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1852ba7ce40SJonas Devlieghere     return thread_plan_sp->IsPlanStale();
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 
1922ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1932ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1942ba7ce40SJonas Devlieghere     return thread_plan_sp->ValidatePlan(nullptr);
1952bdbfd50SJim Ingham   return false;
1962bdbfd50SJim Ingham }
1972bdbfd50SJim Ingham 
198d3dfd8ceSJim Ingham bool SBThreadPlan::GetStopOthers() {
199d3dfd8ceSJim Ingham   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, GetStopOthers);
200d3dfd8ceSJim Ingham 
201d3dfd8ceSJim Ingham   ThreadPlanSP thread_plan_sp(GetSP());
202d3dfd8ceSJim Ingham   if (thread_plan_sp)
203d3dfd8ceSJim Ingham     return thread_plan_sp->StopOthers();
204d3dfd8ceSJim Ingham   return false;
205d3dfd8ceSJim Ingham }
206d3dfd8ceSJim Ingham 
207d3dfd8ceSJim Ingham void SBThreadPlan::SetStopOthers(bool stop_others) {
208d3dfd8ceSJim Ingham   LLDB_RECORD_METHOD(void, SBThreadPlan, SetStopOthers, (bool), stop_others);
209d3dfd8ceSJim Ingham 
210d3dfd8ceSJim Ingham   ThreadPlanSP thread_plan_sp(GetSP());
211d3dfd8ceSJim Ingham   if (thread_plan_sp)
212d3dfd8ceSJim Ingham     thread_plan_sp->SetStopOthers(stop_others);
213d3dfd8ceSJim Ingham }
214d3dfd8ceSJim Ingham 
215b9c1b51eSKate Stone // This section allows an SBThreadPlan to push another of the common types of
216b9c1b51eSKate Stone // plans...
2172bdbfd50SJim Ingham //
218b9c1b51eSKate Stone // FIXME, you should only be able to queue thread plans from inside the methods
21905097246SAdrian Prantl // of a Scripted Thread Plan.  Need a way to enforce that.
2202bdbfd50SJim Ingham 
2212bdbfd50SJim Ingham SBThreadPlan
2222bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
223b9c1b51eSKate Stone                                               lldb::addr_t size) {
224baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
225baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
226baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
227baf5664fSJonas Devlieghere 
228e103ae92SJonas Devlieghere   SBError error;
229*d232abc3SJonas Devlieghere   return QueueThreadPlanForStepOverRange(sb_start_address, size, error);
230e103ae92SJonas Devlieghere }
231e103ae92SJonas Devlieghere 
232e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOverRange(
233e103ae92SJonas Devlieghere     SBAddress &sb_start_address, lldb::addr_t size, SBError &error) {
234baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
235baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
236baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
237baf5664fSJonas Devlieghere                      sb_start_address, size, error);
238baf5664fSJonas Devlieghere 
2392ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
2402ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
2412bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
242b9c1b51eSKate Stone     if (!start_address) {
243*d232abc3SJonas Devlieghere       return SBThreadPlan();
2442bdbfd50SJim Ingham     }
2452bdbfd50SJim Ingham 
2462bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2472bdbfd50SJim Ingham     SymbolContext sc;
2482bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
249e103ae92SJonas Devlieghere     Status plan_status;
250e103ae92SJonas Devlieghere 
2512ba7ce40SJonas Devlieghere     SBThreadPlan plan = SBThreadPlan(
2522ba7ce40SJonas Devlieghere         thread_plan_sp->GetThread().QueueThreadPlanForStepOverRange(
253e103ae92SJonas Devlieghere             false, range, sc, eAllThreads, plan_status));
254e103ae92SJonas Devlieghere 
255e103ae92SJonas Devlieghere     if (plan_status.Fail())
256e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
257f7de4b5dSJim Ingham     else
2582ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
259e103ae92SJonas Devlieghere 
260*d232abc3SJonas Devlieghere     return plan;
2612bdbfd50SJim Ingham   }
262*d232abc3SJonas Devlieghere   return SBThreadPlan();
2632bdbfd50SJim Ingham }
2642bdbfd50SJim Ingham 
2652bdbfd50SJim Ingham SBThreadPlan
2662bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
267b9c1b51eSKate Stone                                             lldb::addr_t size) {
268baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
269baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
270baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
271baf5664fSJonas Devlieghere 
272e103ae92SJonas Devlieghere   SBError error;
273*d232abc3SJonas Devlieghere   return QueueThreadPlanForStepInRange(sb_start_address, size, error);
274e103ae92SJonas Devlieghere }
275e103ae92SJonas Devlieghere 
276e103ae92SJonas Devlieghere SBThreadPlan
277e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
278e103ae92SJonas Devlieghere                                             lldb::addr_t size, SBError &error) {
279baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
280baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
281baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
282baf5664fSJonas Devlieghere                      sb_start_address, size, error);
283baf5664fSJonas Devlieghere 
2842ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
2852ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
2862bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
287b9c1b51eSKate Stone     if (!start_address) {
288*d232abc3SJonas Devlieghere       return SBThreadPlan();
2892bdbfd50SJim Ingham     }
2902bdbfd50SJim Ingham 
2912bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2922bdbfd50SJim Ingham     SymbolContext sc;
2932bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
294e103ae92SJonas Devlieghere 
295e103ae92SJonas Devlieghere     Status plan_status;
296e103ae92SJonas Devlieghere     SBThreadPlan plan =
2972ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepInRange(
298248a1305SKonrad Kleine             false, range, sc, nullptr, eAllThreads, plan_status));
299e103ae92SJonas Devlieghere 
300e103ae92SJonas Devlieghere     if (plan_status.Fail())
301e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
302f7de4b5dSJim Ingham     else
3032ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
304e103ae92SJonas Devlieghere 
305*d232abc3SJonas Devlieghere     return plan;
3062bdbfd50SJim Ingham   }
307*d232abc3SJonas Devlieghere   return SBThreadPlan();
3082bdbfd50SJim Ingham }
3092bdbfd50SJim Ingham 
3102bdbfd50SJim Ingham SBThreadPlan
311b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
312b9c1b51eSKate Stone                                         bool first_insn) {
313baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
314baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut, (uint32_t, bool),
315baf5664fSJonas Devlieghere                      frame_idx_to_step_to, first_insn);
316baf5664fSJonas Devlieghere 
317e103ae92SJonas Devlieghere   SBError error;
318*d232abc3SJonas Devlieghere   return QueueThreadPlanForStepOut(frame_idx_to_step_to, first_insn, error);
319e103ae92SJonas Devlieghere }
320e103ae92SJonas Devlieghere 
321e103ae92SJonas Devlieghere SBThreadPlan
322e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
323e103ae92SJonas Devlieghere                                         bool first_insn, SBError &error) {
324baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
325baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut,
326baf5664fSJonas Devlieghere                      (uint32_t, bool, lldb::SBError &), frame_idx_to_step_to,
327baf5664fSJonas Devlieghere                      first_insn, error);
328baf5664fSJonas Devlieghere 
3292ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
3302ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
3312bdbfd50SJim Ingham     SymbolContext sc;
3322ba7ce40SJonas Devlieghere     sc = thread_plan_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
333b9c1b51eSKate Stone         lldb::eSymbolContextEverything);
334e103ae92SJonas Devlieghere 
335e103ae92SJonas Devlieghere     Status plan_status;
336e103ae92SJonas Devlieghere     SBThreadPlan plan =
3372ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepOut(
338b9c1b51eSKate Stone             false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
339e103ae92SJonas Devlieghere             frame_idx_to_step_to, plan_status));
340e103ae92SJonas Devlieghere 
341e103ae92SJonas Devlieghere     if (plan_status.Fail())
342e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
343f7de4b5dSJim Ingham     else
3442ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
345e103ae92SJonas Devlieghere 
346*d232abc3SJonas Devlieghere     return plan;
3472bdbfd50SJim Ingham   }
348*d232abc3SJonas Devlieghere   return SBThreadPlan();
3492bdbfd50SJim Ingham }
3502bdbfd50SJim Ingham 
3512bdbfd50SJim Ingham SBThreadPlan
352b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
353baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
354baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress, (lldb::SBAddress),
355baf5664fSJonas Devlieghere                      sb_address);
356baf5664fSJonas Devlieghere 
357e103ae92SJonas Devlieghere   SBError error;
358*d232abc3SJonas Devlieghere   return QueueThreadPlanForRunToAddress(sb_address, error);
359e103ae92SJonas Devlieghere }
360e103ae92SJonas Devlieghere 
361e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address,
362e103ae92SJonas Devlieghere                                                           SBError &error) {
363baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
364baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress,
365baf5664fSJonas Devlieghere                      (lldb::SBAddress, lldb::SBError &), sb_address, error);
366baf5664fSJonas Devlieghere 
3672ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
3682ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
3692bdbfd50SJim Ingham     Address *address = sb_address.get();
3702bdbfd50SJim Ingham     if (!address)
371*d232abc3SJonas Devlieghere       return SBThreadPlan();
3722bdbfd50SJim Ingham 
373e103ae92SJonas Devlieghere     Status plan_status;
374e103ae92SJonas Devlieghere     SBThreadPlan plan =
3752ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForRunToAddress(
376e103ae92SJonas Devlieghere             false, *address, false, plan_status));
377e103ae92SJonas Devlieghere 
378e103ae92SJonas Devlieghere     if (plan_status.Fail())
379e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
380f7de4b5dSJim Ingham     else
3812ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
382e103ae92SJonas Devlieghere 
383*d232abc3SJonas Devlieghere     return plan;
3842bdbfd50SJim Ingham   }
385*d232abc3SJonas Devlieghere   return SBThreadPlan();
3862bdbfd50SJim Ingham }
387c1c0fac7SAleksandr Urakov 
388c1c0fac7SAleksandr Urakov SBThreadPlan
389c1c0fac7SAleksandr Urakov SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name) {
390baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
391baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted, (const char *),
392baf5664fSJonas Devlieghere                      script_class_name);
393baf5664fSJonas Devlieghere 
394e103ae92SJonas Devlieghere   SBError error;
395*d232abc3SJonas Devlieghere   return QueueThreadPlanForStepScripted(script_class_name, error);
396e103ae92SJonas Devlieghere }
397e103ae92SJonas Devlieghere 
398e103ae92SJonas Devlieghere SBThreadPlan
399e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
400e103ae92SJonas Devlieghere                                              SBError &error) {
401baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
402baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted,
403baf5664fSJonas Devlieghere                      (const char *, lldb::SBError &), script_class_name, error);
404baf5664fSJonas Devlieghere 
4052ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
4062ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
407e103ae92SJonas Devlieghere     Status plan_status;
40827a14f19SJim Ingham     StructuredData::ObjectSP empty_args;
409e103ae92SJonas Devlieghere     SBThreadPlan plan =
4102ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepScripted(
41127a14f19SJim Ingham             false, script_class_name, empty_args, false, plan_status));
41227a14f19SJim Ingham 
41327a14f19SJim Ingham     if (plan_status.Fail())
41427a14f19SJim Ingham       error.SetErrorString(plan_status.AsCString());
415f7de4b5dSJim Ingham     else
4162ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
41727a14f19SJim Ingham 
418*d232abc3SJonas Devlieghere     return plan;
41927a14f19SJim Ingham   }
420*d232abc3SJonas Devlieghere   return SBThreadPlan();
42127a14f19SJim Ingham }
42227a14f19SJim Ingham 
42327a14f19SJim Ingham SBThreadPlan
42427a14f19SJim Ingham SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
42527a14f19SJim Ingham                                              lldb::SBStructuredData &args_data,
42627a14f19SJim Ingham                                              SBError &error) {
42727a14f19SJim Ingham   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
42827a14f19SJim Ingham                      QueueThreadPlanForStepScripted,
42927a14f19SJim Ingham                      (const char *, lldb::SBStructuredData &, lldb::SBError &),
43027a14f19SJim Ingham                      script_class_name, args_data, error);
43127a14f19SJim Ingham 
4322ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
4332ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
43427a14f19SJim Ingham     Status plan_status;
43527a14f19SJim Ingham     StructuredData::ObjectSP args_obj = args_data.m_impl_up->GetObjectSP();
43627a14f19SJim Ingham     SBThreadPlan plan =
4372ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepScripted(
43827a14f19SJim Ingham             false, script_class_name, args_obj, false, plan_status));
439e103ae92SJonas Devlieghere 
440e103ae92SJonas Devlieghere     if (plan_status.Fail())
441e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
442f7de4b5dSJim Ingham     else
4432ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
444e103ae92SJonas Devlieghere 
445*d232abc3SJonas Devlieghere     return plan;
446c1c0fac7SAleksandr Urakov   } else {
447*d232abc3SJonas Devlieghere     return SBThreadPlan();
448c1c0fac7SAleksandr Urakov   }
449c1c0fac7SAleksandr Urakov }
450