1 //===-- SBThreadPlan.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_API_SBTHREADPLAN_H
10 #define LLDB_API_SBTHREADPLAN_H
11 
12 #include "lldb/API/SBDefines.h"
13 
14 #include <cstdio>
15 
16 namespace lldb_private {
17 namespace python {
18 class SWIGBridge;
19 }
20 } // namespace lldb_private
21 
22 namespace lldb {
23 
24 class LLDB_API SBThreadPlan {
25 
26 public:
27   SBThreadPlan();
28 
29   SBThreadPlan(const lldb::SBThreadPlan &threadPlan);
30 
31   SBThreadPlan(lldb::SBThread &thread, const char *class_name);
32 
33   SBThreadPlan(lldb::SBThread &thread, const char *class_name,
34                lldb::SBStructuredData &args_data);
35 
36   ~SBThreadPlan();
37 
38   explicit operator bool() const;
39 
40   bool IsValid() const;
41 
42   void Clear();
43 
44   lldb::StopReason GetStopReason();
45 
46   /// Get the number of words associated with the stop reason.
47   /// See also GetStopReasonDataAtIndex().
48   size_t GetStopReasonDataCount();
49 
50   /// Get information associated with a stop reason.
51   ///
52   /// Breakpoint stop reasons will have data that consists of pairs of
53   /// breakpoint IDs followed by the breakpoint location IDs (they always come
54   /// in pairs).
55   ///
56   /// Stop Reason              Count Data Type
57   /// ======================== ===== =========================================
58   /// eStopReasonNone          0
59   /// eStopReasonTrace         0
60   /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
61   /// eStopReasonWatchpoint    1     watchpoint id
62   /// eStopReasonSignal        1     unix signal number
63   /// eStopReasonException     N     exception data
64   /// eStopReasonExec          0
65   /// eStopReasonFork          1     pid of the child process
66   /// eStopReasonVFork         1     pid of the child process
67   /// eStopReasonVForkDone     0
68   /// eStopReasonPlanComplete  0
69   uint64_t GetStopReasonDataAtIndex(uint32_t idx);
70 
71   SBThread GetThread() const;
72 
73   const lldb::SBThreadPlan &operator=(const lldb::SBThreadPlan &rhs);
74 
75   bool GetDescription(lldb::SBStream &description) const;
76 
77   void SetPlanComplete(bool success);
78 
79   bool IsPlanComplete();
80 
81   bool IsPlanStale();
82 
83   bool IsValid();
84 
85   bool GetStopOthers();
86 
87   void SetStopOthers(bool stop_others);
88 
89   // This section allows an SBThreadPlan to push another of the common types of
90   // plans...
91   SBThreadPlan QueueThreadPlanForStepOverRange(SBAddress &start_address,
92                                                lldb::addr_t range_size);
93   SBThreadPlan QueueThreadPlanForStepOverRange(SBAddress &start_address,
94                                                lldb::addr_t range_size,
95                                                SBError &error);
96 
97   SBThreadPlan QueueThreadPlanForStepInRange(SBAddress &start_address,
98                                              lldb::addr_t range_size);
99   SBThreadPlan QueueThreadPlanForStepInRange(SBAddress &start_address,
100                                              lldb::addr_t range_size,
101                                              SBError &error);
102 
103   SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
104                                          bool first_insn = false);
105   SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
106                                          bool first_insn, SBError &error);
107 
108   SBThreadPlan QueueThreadPlanForRunToAddress(SBAddress address);
109   SBThreadPlan QueueThreadPlanForRunToAddress(SBAddress address,
110                                               SBError &error);
111 
112   SBThreadPlan QueueThreadPlanForStepScripted(const char *script_class_name);
113   SBThreadPlan QueueThreadPlanForStepScripted(const char *script_class_name,
114                                               SBError &error);
115   SBThreadPlan QueueThreadPlanForStepScripted(const char *script_class_name,
116                                               lldb::SBStructuredData &args_data,
117                                               SBError &error);
118 
119 protected:
120   friend class lldb_private::python::SWIGBridge;
121 
122   SBThreadPlan(const lldb::ThreadPlanSP &lldb_object_sp);
123 
124 private:
125   friend class SBBreakpoint;
126   friend class SBBreakpointLocation;
127   friend class SBFrame;
128   friend class SBProcess;
129   friend class SBDebugger;
130   friend class SBValue;
131   friend class lldb_private::QueueImpl;
132   friend class SBQueueItem;
133 
134   lldb::ThreadPlanSP GetSP() const { return m_opaque_wp.lock(); }
135   lldb_private::ThreadPlan *get() const { return GetSP().get(); }
136   void SetThreadPlan(const lldb::ThreadPlanSP &lldb_object_sp);
137 
138   lldb::ThreadPlanWP m_opaque_wp;
139 };
140 
141 } // namespace lldb
142 
143 #endif // LLDB_API_SBTHREADPLAN_H
144