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)
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)
722ba7ce40SJonas Devlieghere     m_opaque_wp =
732ba7ce40SJonas Devlieghere         std::make_shared<ThreadPlanPython>(*thread, class_name, 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)
842ba7ce40SJonas Devlieghere     m_opaque_wp = 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)
952ba7ce40SJonas Devlieghere     m_opaque_wp = rhs.m_opaque_wp;
96306809f2SJonas Devlieghere   return LLDB_RECORD_RESULT(*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) {
141baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(
1422ba7ce40SJonas Devlieghere         SBThread(thread_plan_sp->GetThread().shared_from_this()));
143b9c1b51eSKate Stone   } else
144baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThread());
1452bdbfd50SJim Ingham }
1462bdbfd50SJim Ingham 
147b9c1b51eSKate Stone bool SBThreadPlan::GetDescription(lldb::SBStream &description) const {
148baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST(bool, SBThreadPlan, GetDescription,
149baf5664fSJonas Devlieghere                            (lldb::SBStream &), description);
150baf5664fSJonas Devlieghere 
1512ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1522ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
1532ba7ce40SJonas Devlieghere     thread_plan_sp->GetDescription(description.get(), eDescriptionLevelFull);
154b9c1b51eSKate Stone   } else {
1552bdbfd50SJim Ingham     description.Printf("Empty SBThreadPlan");
1562bdbfd50SJim Ingham   }
1572bdbfd50SJim Ingham   return true;
1582bdbfd50SJim Ingham }
1592bdbfd50SJim Ingham 
1602ba7ce40SJonas Devlieghere void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_wp) {
1612ba7ce40SJonas Devlieghere   m_opaque_wp = lldb_object_wp;
1622bdbfd50SJim Ingham }
1632bdbfd50SJim Ingham 
164b9c1b51eSKate Stone void SBThreadPlan::SetPlanComplete(bool success) {
165baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBThreadPlan, SetPlanComplete, (bool), success);
166baf5664fSJonas Devlieghere 
1672ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1682ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1692ba7ce40SJonas Devlieghere     thread_plan_sp->SetPlanComplete(success);
1702bdbfd50SJim Ingham }
1712bdbfd50SJim Ingham 
172b9c1b51eSKate Stone bool SBThreadPlan::IsPlanComplete() {
173baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanComplete);
174baf5664fSJonas Devlieghere 
1752ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1762ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1772ba7ce40SJonas Devlieghere     return thread_plan_sp->IsPlanComplete();
1782bdbfd50SJim Ingham   return true;
1792bdbfd50SJim Ingham }
1802bdbfd50SJim Ingham 
181b9c1b51eSKate Stone bool SBThreadPlan::IsPlanStale() {
182baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsPlanStale);
183baf5664fSJonas Devlieghere 
1842ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1852ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1862ba7ce40SJonas Devlieghere     return thread_plan_sp->IsPlanStale();
187c915a7d2SJim Ingham   return true;
188c915a7d2SJim Ingham }
189c915a7d2SJim Ingham 
190b9c1b51eSKate Stone bool SBThreadPlan::IsValid() {
191baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, IsValid);
192baf5664fSJonas Devlieghere 
1932ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
1942ba7ce40SJonas Devlieghere   if (thread_plan_sp)
1952ba7ce40SJonas Devlieghere     return thread_plan_sp->ValidatePlan(nullptr);
1962bdbfd50SJim Ingham   return false;
1972bdbfd50SJim Ingham }
1982bdbfd50SJim Ingham 
199*d3dfd8ceSJim Ingham bool SBThreadPlan::GetStopOthers() {
200*d3dfd8ceSJim Ingham   LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, GetStopOthers);
201*d3dfd8ceSJim Ingham 
202*d3dfd8ceSJim Ingham   ThreadPlanSP thread_plan_sp(GetSP());
203*d3dfd8ceSJim Ingham   if (thread_plan_sp)
204*d3dfd8ceSJim Ingham     return thread_plan_sp->StopOthers();
205*d3dfd8ceSJim Ingham   return false;
206*d3dfd8ceSJim Ingham }
207*d3dfd8ceSJim Ingham 
208*d3dfd8ceSJim Ingham void SBThreadPlan::SetStopOthers(bool stop_others) {
209*d3dfd8ceSJim Ingham   LLDB_RECORD_METHOD(void, SBThreadPlan, SetStopOthers, (bool), stop_others);
210*d3dfd8ceSJim Ingham 
211*d3dfd8ceSJim Ingham   ThreadPlanSP thread_plan_sp(GetSP());
212*d3dfd8ceSJim Ingham   if (thread_plan_sp)
213*d3dfd8ceSJim Ingham     thread_plan_sp->SetStopOthers(stop_others);
214*d3dfd8ceSJim Ingham }
215*d3dfd8ceSJim Ingham 
216b9c1b51eSKate Stone // This section allows an SBThreadPlan to push another of the common types of
217b9c1b51eSKate Stone // plans...
2182bdbfd50SJim Ingham //
219b9c1b51eSKate Stone // FIXME, you should only be able to queue thread plans from inside the methods
22005097246SAdrian Prantl // of a Scripted Thread Plan.  Need a way to enforce that.
2212bdbfd50SJim Ingham 
2222bdbfd50SJim Ingham SBThreadPlan
2232bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address,
224b9c1b51eSKate Stone                                               lldb::addr_t size) {
225baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
226baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
227baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
228baf5664fSJonas Devlieghere 
229e103ae92SJonas Devlieghere   SBError error;
230baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
231baf5664fSJonas Devlieghere       QueueThreadPlanForStepOverRange(sb_start_address, size, error));
232e103ae92SJonas Devlieghere }
233e103ae92SJonas Devlieghere 
234e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOverRange(
235e103ae92SJonas Devlieghere     SBAddress &sb_start_address, lldb::addr_t size, SBError &error) {
236baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
237baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOverRange,
238baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
239baf5664fSJonas Devlieghere                      sb_start_address, size, error);
240baf5664fSJonas Devlieghere 
2412ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
2422ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
2432bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
244b9c1b51eSKate Stone     if (!start_address) {
245baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
2462bdbfd50SJim Ingham     }
2472bdbfd50SJim Ingham 
2482bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2492bdbfd50SJim Ingham     SymbolContext sc;
2502bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
251e103ae92SJonas Devlieghere     Status plan_status;
252e103ae92SJonas Devlieghere 
2532ba7ce40SJonas Devlieghere     SBThreadPlan plan = SBThreadPlan(
2542ba7ce40SJonas Devlieghere         thread_plan_sp->GetThread().QueueThreadPlanForStepOverRange(
255e103ae92SJonas Devlieghere             false, range, sc, eAllThreads, plan_status));
256e103ae92SJonas Devlieghere 
257e103ae92SJonas Devlieghere     if (plan_status.Fail())
258e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
259f7de4b5dSJim Ingham     else
2602ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
261e103ae92SJonas Devlieghere 
262baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
2632bdbfd50SJim Ingham   }
2642ba7ce40SJonas Devlieghere   return LLDB_RECORD_RESULT(SBThreadPlan());
2652bdbfd50SJim Ingham }
2662bdbfd50SJim Ingham 
2672bdbfd50SJim Ingham SBThreadPlan
2682bdbfd50SJim Ingham SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
269b9c1b51eSKate Stone                                             lldb::addr_t size) {
270baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
271baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
272baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t), sb_start_address, size);
273baf5664fSJonas Devlieghere 
274e103ae92SJonas Devlieghere   SBError error;
275baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
276baf5664fSJonas Devlieghere       QueueThreadPlanForStepInRange(sb_start_address, size, error));
277e103ae92SJonas Devlieghere }
278e103ae92SJonas Devlieghere 
279e103ae92SJonas Devlieghere SBThreadPlan
280e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address,
281e103ae92SJonas Devlieghere                                             lldb::addr_t size, SBError &error) {
282baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
283baf5664fSJonas Devlieghere                      QueueThreadPlanForStepInRange,
284baf5664fSJonas Devlieghere                      (lldb::SBAddress &, lldb::addr_t, lldb::SBError &),
285baf5664fSJonas Devlieghere                      sb_start_address, size, error);
286baf5664fSJonas Devlieghere 
2872ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
2882ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
2892bdbfd50SJim Ingham     Address *start_address = sb_start_address.get();
290b9c1b51eSKate Stone     if (!start_address) {
291baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
2922bdbfd50SJim Ingham     }
2932bdbfd50SJim Ingham 
2942bdbfd50SJim Ingham     AddressRange range(*start_address, size);
2952bdbfd50SJim Ingham     SymbolContext sc;
2962bdbfd50SJim Ingham     start_address->CalculateSymbolContext(&sc);
297e103ae92SJonas Devlieghere 
298e103ae92SJonas Devlieghere     Status plan_status;
299e103ae92SJonas Devlieghere     SBThreadPlan plan =
3002ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepInRange(
301248a1305SKonrad Kleine             false, range, sc, nullptr, eAllThreads, plan_status));
302e103ae92SJonas Devlieghere 
303e103ae92SJonas Devlieghere     if (plan_status.Fail())
304e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
305f7de4b5dSJim Ingham     else
3062ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
307e103ae92SJonas Devlieghere 
308baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
3092bdbfd50SJim Ingham   }
3102ba7ce40SJonas Devlieghere   return LLDB_RECORD_RESULT(SBThreadPlan());
3112bdbfd50SJim Ingham }
3122bdbfd50SJim Ingham 
3132bdbfd50SJim Ingham SBThreadPlan
314b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
315b9c1b51eSKate Stone                                         bool first_insn) {
316baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
317baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut, (uint32_t, bool),
318baf5664fSJonas Devlieghere                      frame_idx_to_step_to, first_insn);
319baf5664fSJonas Devlieghere 
320e103ae92SJonas Devlieghere   SBError error;
321baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
322baf5664fSJonas Devlieghere       QueueThreadPlanForStepOut(frame_idx_to_step_to, first_insn, error));
323e103ae92SJonas Devlieghere }
324e103ae92SJonas Devlieghere 
325e103ae92SJonas Devlieghere SBThreadPlan
326e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
327e103ae92SJonas Devlieghere                                         bool first_insn, SBError &error) {
328baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
329baf5664fSJonas Devlieghere                      QueueThreadPlanForStepOut,
330baf5664fSJonas Devlieghere                      (uint32_t, bool, lldb::SBError &), frame_idx_to_step_to,
331baf5664fSJonas Devlieghere                      first_insn, error);
332baf5664fSJonas Devlieghere 
3332ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
3342ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
3352bdbfd50SJim Ingham     SymbolContext sc;
3362ba7ce40SJonas Devlieghere     sc = thread_plan_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(
337b9c1b51eSKate Stone         lldb::eSymbolContextEverything);
338e103ae92SJonas Devlieghere 
339e103ae92SJonas Devlieghere     Status plan_status;
340e103ae92SJonas Devlieghere     SBThreadPlan plan =
3412ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepOut(
342b9c1b51eSKate Stone             false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion,
343e103ae92SJonas Devlieghere             frame_idx_to_step_to, plan_status));
344e103ae92SJonas Devlieghere 
345e103ae92SJonas Devlieghere     if (plan_status.Fail())
346e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
347f7de4b5dSJim Ingham     else
3482ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
349e103ae92SJonas Devlieghere 
350baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
3512bdbfd50SJim Ingham   }
3522ba7ce40SJonas Devlieghere   return LLDB_RECORD_RESULT(SBThreadPlan());
3532bdbfd50SJim Ingham }
3542bdbfd50SJim Ingham 
3552bdbfd50SJim Ingham SBThreadPlan
356b9c1b51eSKate Stone SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) {
357baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
358baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress, (lldb::SBAddress),
359baf5664fSJonas Devlieghere                      sb_address);
360baf5664fSJonas Devlieghere 
361e103ae92SJonas Devlieghere   SBError error;
362baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(QueueThreadPlanForRunToAddress(sb_address, error));
363e103ae92SJonas Devlieghere }
364e103ae92SJonas Devlieghere 
365e103ae92SJonas Devlieghere SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address,
366e103ae92SJonas Devlieghere                                                           SBError &error) {
367baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
368baf5664fSJonas Devlieghere                      QueueThreadPlanForRunToAddress,
369baf5664fSJonas Devlieghere                      (lldb::SBAddress, lldb::SBError &), sb_address, error);
370baf5664fSJonas Devlieghere 
3712ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
3722ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
3732bdbfd50SJim Ingham     Address *address = sb_address.get();
3742bdbfd50SJim Ingham     if (!address)
375baf5664fSJonas Devlieghere       return LLDB_RECORD_RESULT(SBThreadPlan());
3762bdbfd50SJim Ingham 
377e103ae92SJonas Devlieghere     Status plan_status;
378e103ae92SJonas Devlieghere     SBThreadPlan plan =
3792ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForRunToAddress(
380e103ae92SJonas Devlieghere             false, *address, false, plan_status));
381e103ae92SJonas Devlieghere 
382e103ae92SJonas Devlieghere     if (plan_status.Fail())
383e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
384f7de4b5dSJim Ingham     else
3852ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
386e103ae92SJonas Devlieghere 
387baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
3882bdbfd50SJim Ingham   }
3892ba7ce40SJonas Devlieghere   return LLDB_RECORD_RESULT(SBThreadPlan());
3902bdbfd50SJim Ingham }
391c1c0fac7SAleksandr Urakov 
392c1c0fac7SAleksandr Urakov SBThreadPlan
393c1c0fac7SAleksandr Urakov SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name) {
394baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
395baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted, (const char *),
396baf5664fSJonas Devlieghere                      script_class_name);
397baf5664fSJonas Devlieghere 
398e103ae92SJonas Devlieghere   SBError error;
399baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(
400baf5664fSJonas Devlieghere       QueueThreadPlanForStepScripted(script_class_name, error));
401e103ae92SJonas Devlieghere }
402e103ae92SJonas Devlieghere 
403e103ae92SJonas Devlieghere SBThreadPlan
404e103ae92SJonas Devlieghere SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
405e103ae92SJonas Devlieghere                                              SBError &error) {
406baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
407baf5664fSJonas Devlieghere                      QueueThreadPlanForStepScripted,
408baf5664fSJonas Devlieghere                      (const char *, lldb::SBError &), script_class_name, error);
409baf5664fSJonas Devlieghere 
4102ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
4112ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
412e103ae92SJonas Devlieghere     Status plan_status;
41327a14f19SJim Ingham     StructuredData::ObjectSP empty_args;
414e103ae92SJonas Devlieghere     SBThreadPlan plan =
4152ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepScripted(
41627a14f19SJim Ingham             false, script_class_name, empty_args, false, plan_status));
41727a14f19SJim Ingham 
41827a14f19SJim Ingham     if (plan_status.Fail())
41927a14f19SJim Ingham       error.SetErrorString(plan_status.AsCString());
420f7de4b5dSJim Ingham     else
4212ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
42227a14f19SJim Ingham 
42327a14f19SJim Ingham     return LLDB_RECORD_RESULT(plan);
42427a14f19SJim Ingham   }
4252ba7ce40SJonas Devlieghere   return LLDB_RECORD_RESULT(SBThreadPlan());
42627a14f19SJim Ingham }
42727a14f19SJim Ingham 
42827a14f19SJim Ingham SBThreadPlan
42927a14f19SJim Ingham SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name,
43027a14f19SJim Ingham                                              lldb::SBStructuredData &args_data,
43127a14f19SJim Ingham                                              SBError &error) {
43227a14f19SJim Ingham   LLDB_RECORD_METHOD(lldb::SBThreadPlan, SBThreadPlan,
43327a14f19SJim Ingham                      QueueThreadPlanForStepScripted,
43427a14f19SJim Ingham                      (const char *, lldb::SBStructuredData &, lldb::SBError &),
43527a14f19SJim Ingham                      script_class_name, args_data, error);
43627a14f19SJim Ingham 
4372ba7ce40SJonas Devlieghere   ThreadPlanSP thread_plan_sp(GetSP());
4382ba7ce40SJonas Devlieghere   if (thread_plan_sp) {
43927a14f19SJim Ingham     Status plan_status;
44027a14f19SJim Ingham     StructuredData::ObjectSP args_obj = args_data.m_impl_up->GetObjectSP();
44127a14f19SJim Ingham     SBThreadPlan plan =
4422ba7ce40SJonas Devlieghere         SBThreadPlan(thread_plan_sp->GetThread().QueueThreadPlanForStepScripted(
44327a14f19SJim Ingham             false, script_class_name, args_obj, false, plan_status));
444e103ae92SJonas Devlieghere 
445e103ae92SJonas Devlieghere     if (plan_status.Fail())
446e103ae92SJonas Devlieghere       error.SetErrorString(plan_status.AsCString());
447f7de4b5dSJim Ingham     else
4482ba7ce40SJonas Devlieghere       plan.GetSP()->SetPrivate(true);
449e103ae92SJonas Devlieghere 
450baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(plan);
451c1c0fac7SAleksandr Urakov   } else {
452baf5664fSJonas Devlieghere     return LLDB_RECORD_RESULT(SBThreadPlan());
453c1c0fac7SAleksandr Urakov   }
454c1c0fac7SAleksandr Urakov }
455ae211eceSMichal Gorny 
456ae211eceSMichal Gorny namespace lldb_private {
457ae211eceSMichal Gorny namespace repro {
458ae211eceSMichal Gorny 
459ae211eceSMichal Gorny template <>
460ae211eceSMichal Gorny void RegisterMethods<SBThreadPlan>(Registry &R) {
461ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, ());
462ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::ThreadPlanSP &));
463ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (const lldb::SBThreadPlan &));
464ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *));
46527a14f19SJim Ingham   LLDB_REGISTER_CONSTRUCTOR(SBThreadPlan, (lldb::SBThread &, const char *,
46627a14f19SJim Ingham                        lldb::SBStructuredData &));
467ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(const lldb::SBThreadPlan &,
468ae211eceSMichal Gorny                        SBThreadPlan, operator=,(const lldb::SBThreadPlan &));
469ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, IsValid, ());
470ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, operator bool, ());
471ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBThreadPlan, Clear, ());
472ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::StopReason, SBThreadPlan, GetStopReason, ());
473ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(size_t, SBThreadPlan, GetStopReasonDataCount, ());
474ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(uint64_t, SBThreadPlan, GetStopReasonDataAtIndex,
475ae211eceSMichal Gorny                        (uint32_t));
476ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBThreadPlan, GetThread, ());
477ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBThreadPlan, GetDescription,
478ae211eceSMichal Gorny                              (lldb::SBStream &));
479ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBThreadPlan, SetPlanComplete, (bool));
480ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanComplete, ());
481ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanStale, ());
482ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsValid, ());
483*d3dfd8ceSJim Ingham   LLDB_REGISTER_METHOD(void, SBThreadPlan, SetStopOthers, (bool));
484*d3dfd8ceSJim Ingham   LLDB_REGISTER_METHOD(bool, SBThreadPlan, GetStopOthers, ());
485ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
486ae211eceSMichal Gorny                        QueueThreadPlanForStepOverRange,
487ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t));
488ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
489ae211eceSMichal Gorny                        QueueThreadPlanForStepOverRange,
490ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
491ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
492ae211eceSMichal Gorny                        QueueThreadPlanForStepInRange,
493ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t));
494ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
495ae211eceSMichal Gorny                        QueueThreadPlanForStepInRange,
496ae211eceSMichal Gorny                        (lldb::SBAddress &, lldb::addr_t, lldb::SBError &));
497ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
498ae211eceSMichal Gorny                        QueueThreadPlanForStepOut, (uint32_t, bool));
499ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
500ae211eceSMichal Gorny                        QueueThreadPlanForStepOut,
501ae211eceSMichal Gorny                        (uint32_t, bool, lldb::SBError &));
502ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
503ae211eceSMichal Gorny                        QueueThreadPlanForRunToAddress, (lldb::SBAddress));
504ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
505ae211eceSMichal Gorny                        QueueThreadPlanForRunToAddress,
506ae211eceSMichal Gorny                        (lldb::SBAddress, lldb::SBError &));
507ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
508ae211eceSMichal Gorny                        QueueThreadPlanForStepScripted, (const char *));
509ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
510ae211eceSMichal Gorny                        QueueThreadPlanForStepScripted,
511ae211eceSMichal Gorny                        (const char *, lldb::SBError &));
51227a14f19SJim Ingham   LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
51327a14f19SJim Ingham                        QueueThreadPlanForStepScripted,
51427a14f19SJim Ingham                        (const char *, lldb::SBStructuredData &,
51527a14f19SJim Ingham                        lldb::SBError &));
516ae211eceSMichal Gorny }
517ae211eceSMichal Gorny 
518ae211eceSMichal Gorny }
519ae211eceSMichal Gorny }
520