1 //===-- SBProcess.h ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_SBProcess_h_
11 #define LLDB_SBProcess_h_
12 
13 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBError.h"
15 #include "lldb/API/SBTarget.h"
16 #include <stdio.h>
17 
18 namespace lldb {
19 
20 class SBEvent;
21 
22 class SBProcess
23 {
24 public:
25     //------------------------------------------------------------------
26     /// Broadcaster event bits definitions.
27     //------------------------------------------------------------------
28     enum
29     {
30         eBroadcastBitStateChanged   = (1 << 0),
31         eBroadcastBitInterrupt      = (1 << 1),
32         eBroadcastBitSTDOUT         = (1 << 2),
33         eBroadcastBitSTDERR         = (1 << 3),
34         eBroadcastBitProfileData    = (1 << 4)
35     };
36 
37     SBProcess ();
38 
39     SBProcess (const lldb::SBProcess& rhs);
40 
41     const lldb::SBProcess&
42     operator = (const lldb::SBProcess& rhs);
43 
44     SBProcess (const lldb::ProcessSP &process_sp);
45 
46     ~SBProcess();
47 
48     static const char *
49     GetBroadcasterClassName ();
50 
51     const char *
52     GetPluginName ();
53 
54     // DEPRECATED: use GetPluginName()
55     const char *
56     GetShortPluginName ();
57 
58     void
59     Clear ();
60 
61     bool
62     IsValid() const;
63 
64     lldb::SBTarget
65     GetTarget() const;
66 
67     lldb::ByteOrder
68     GetByteOrder() const;
69 
70     size_t
71     PutSTDIN (const char *src, size_t src_len);
72 
73     size_t
74     GetSTDOUT (char *dst, size_t dst_len) const;
75 
76     size_t
77     GetSTDERR (char *dst, size_t dst_len) const;
78 
79     size_t
80     GetAsyncProfileData(char *dst, size_t dst_len) const;
81 
82     void
83     ReportEventState (const lldb::SBEvent &event, FILE *out) const;
84 
85     void
86     AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
87 
88     //------------------------------------------------------------------
89     /// Remote connection related functions. These will fail if the
90     /// process is not in eStateConnected. They are intended for use
91     /// when connecting to an externally managed debugserver instance.
92     //------------------------------------------------------------------
93     bool
94     RemoteAttachToProcessWithID (lldb::pid_t pid,
95                                  lldb::SBError& error);
96 
97     bool
98     RemoteLaunch (char const **argv,
99                   char const **envp,
100                   const char *stdin_path,
101                   const char *stdout_path,
102                   const char *stderr_path,
103                   const char *working_directory,
104                   uint32_t launch_flags,
105                   bool stop_at_entry,
106                   lldb::SBError& error);
107 
108     //------------------------------------------------------------------
109     // Thread related functions
110     //------------------------------------------------------------------
111     uint32_t
112     GetNumThreads ();
113 
114     lldb::SBThread
115     GetThreadAtIndex (size_t index);
116 
117     lldb::SBThread
118     GetThreadByID (lldb::tid_t sb_thread_id);
119 
120     lldb::SBThread
121     GetThreadByIndexID (uint32_t index_id);
122 
123     lldb::SBThread
124     GetSelectedThread () const;
125 
126     //------------------------------------------------------------------
127     // Function for lazily creating a thread using the current OS
128     // plug-in. This function will be removed in the future when there
129     // are APIs to create SBThread objects through the interface and add
130     // them to the process through the SBProcess API.
131     //------------------------------------------------------------------
132     lldb::SBThread
133     CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
134 
135     bool
136     SetSelectedThread (const lldb::SBThread &thread);
137 
138     bool
139     SetSelectedThreadByID (lldb::tid_t tid);
140 
141     bool
142     SetSelectedThreadByIndexID (uint32_t index_id);
143 
144     //------------------------------------------------------------------
145     // Stepping related functions
146     //------------------------------------------------------------------
147 
148     lldb::StateType
149     GetState ();
150 
151     int
152     GetExitStatus ();
153 
154     const char *
155     GetExitDescription ();
156 
157     //------------------------------------------------------------------
158     /// Gets the process ID
159     ///
160     /// Returns the process identifier for the process as it is known
161     /// on the system on which the process is running. For unix systems
162     /// this is typically the same as if you called "getpid()" in the
163     /// process.
164     ///
165     /// @return
166     ///     Returns LLDB_INVALID_PROCESS_ID if this object does not
167     ///     contain a valid process object, or if the process has not
168     ///     been launched. Returns a valid process ID if the process is
169     ///     valid.
170     //------------------------------------------------------------------
171     lldb::pid_t
172     GetProcessID ();
173 
174     //------------------------------------------------------------------
175     /// Gets the unique ID associated with this process object
176     ///
177     /// Unique IDs start at 1 and increment up with each new process
178     /// instance. Since starting a process on a system might always
179     /// create a process with the same process ID, there needs to be a
180     /// way to tell two process instances apart.
181     ///
182     /// @return
183     ///     Returns a non-zero integer ID if this object contains a
184     ///     valid process object, zero if this object does not contain
185     ///     a valid process object.
186     //------------------------------------------------------------------
187     uint32_t
188     GetUniqueID();
189 
190     uint32_t
191     GetAddressByteSize() const;
192 
193     lldb::SBError
194     Destroy ();
195 
196     lldb::SBError
197     Continue ();
198 
199     lldb::SBError
200     Stop ();
201 
202     lldb::SBError
203     Kill ();
204 
205     lldb::SBError
206     Detach ();
207 
208     lldb::SBError
209     Detach (bool keep_stopped);
210 
211     lldb::SBError
212     Signal (int signal);
213 
214     void
215     SendAsyncInterrupt();
216 
217     uint32_t
218     GetStopID(bool include_expression_stops = false);
219 
220     size_t
221     ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
222 
223     size_t
224     WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
225 
226     size_t
227     ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
228 
229     uint64_t
230     ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
231 
232     lldb::addr_t
233     ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
234 
235     // Events
236     static lldb::StateType
237     GetStateFromEvent (const lldb::SBEvent &event);
238 
239     static bool
240     GetRestartedFromEvent (const lldb::SBEvent &event);
241 
242     static size_t
243     GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event);
244 
245     static const char *
246     GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx);
247 
248     static lldb::SBProcess
249     GetProcessFromEvent (const lldb::SBEvent &event);
250 
251     static bool
252     EventIsProcessEvent (const lldb::SBEvent &event);
253 
254     lldb::SBBroadcaster
255     GetBroadcaster () const;
256 
257     static const char *
258     GetBroadcasterClass ();
259 
260     bool
261     GetDescription (lldb::SBStream &description);
262 
263     uint32_t
264     GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
265 
266     uint32_t
267     LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
268 
269     lldb::SBError
270     UnloadImage (uint32_t image_token);
271 
272 protected:
273     friend class SBAddress;
274     friend class SBBreakpoint;
275     friend class SBBreakpointLocation;
276     friend class SBCommandInterpreter;
277     friend class SBDebugger;
278     friend class SBFunction;
279     friend class SBModule;
280     friend class SBTarget;
281     friend class SBThread;
282     friend class SBValue;
283 
284     lldb::ProcessSP
285     GetSP() const;
286 
287     void
288     SetSP (const lldb::ProcessSP &process_sp);
289 
290     lldb::ProcessWP m_opaque_wp;
291 };
292 
293 }  // namespace lldb
294 
295 #endif  // LLDB_SBProcess_h_
296