SBProcess.h revision 64742744396c966e8de770e765130629b0c78335
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
18namespace lldb {
19
20class SBEvent;
21
22class SBProcess
23{
24public:
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    const char *
55    GetShortPluginName ();
56
57    void
58    Clear ();
59
60    bool
61    IsValid() const;
62
63    lldb::SBTarget
64    GetTarget() const;
65
66    lldb::ByteOrder
67    GetByteOrder() const;
68
69    size_t
70    PutSTDIN (const char *src, size_t src_len);
71
72    size_t
73    GetSTDOUT (char *dst, size_t dst_len) const;
74
75    size_t
76    GetSTDERR (char *dst, size_t dst_len) const;
77
78    size_t
79    GetAsyncProfileData(char *dst, size_t dst_len) const;
80
81    void
82    ReportEventState (const lldb::SBEvent &event, FILE *out) const;
83
84    void
85    AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
86
87    //------------------------------------------------------------------
88    /// Remote connection related functions. These will fail if the
89    /// process is not in eStateConnected. They are intended for use
90    /// when connecting to an externally managed debugserver instance.
91    //------------------------------------------------------------------
92    bool
93    RemoteAttachToProcessWithID (lldb::pid_t pid,
94                                 lldb::SBError& error);
95
96    bool
97    RemoteLaunch (char const **argv,
98                  char const **envp,
99                  const char *stdin_path,
100                  const char *stdout_path,
101                  const char *stderr_path,
102                  const char *working_directory,
103                  uint32_t launch_flags,
104                  bool stop_at_entry,
105                  lldb::SBError& error);
106
107    //------------------------------------------------------------------
108    // Thread related functions
109    //------------------------------------------------------------------
110    uint32_t
111    GetNumThreads ();
112
113    lldb::SBThread
114    GetThreadAtIndex (size_t index);
115
116    lldb::SBThread
117    GetThreadByID (lldb::tid_t sb_thread_id);
118
119    lldb::SBThread
120    GetThreadByIndexID (uint32_t index_id);
121
122    lldb::SBThread
123    GetSelectedThread () const;
124
125    bool
126    SetSelectedThread (const lldb::SBThread &thread);
127
128    bool
129    SetSelectedThreadByID (lldb::tid_t tid);
130
131    bool
132    SetSelectedThreadByIndexID (uint32_t index_id);
133
134    //------------------------------------------------------------------
135    // Stepping related functions
136    //------------------------------------------------------------------
137
138    lldb::StateType
139    GetState ();
140
141    int
142    GetExitStatus ();
143
144    const char *
145    GetExitDescription ();
146
147    //------------------------------------------------------------------
148    /// Gets the process ID
149    ///
150    /// Returns the process identifier for the process as it is known
151    /// on the system on which the process is running. For unix systems
152    /// this is typically the same as if you called "getpid()" in the
153    /// process.
154    ///
155    /// @return
156    ///     Returns LLDB_INVALID_PROCESS_ID if this object does not
157    ///     contain a valid process object, or if the process has not
158    ///     been launched. Returns a valid process ID if the process is
159    ///     valid.
160    //------------------------------------------------------------------
161    lldb::pid_t
162    GetProcessID ();
163
164    //------------------------------------------------------------------
165    /// Gets the unique ID associated with this process object
166    ///
167    /// Unique IDs start at 1 and increment up with each new process
168    /// instance. Since starting a process on a system might always
169    /// create a process with the same process ID, there needs to be a
170    /// way to tell two process instances apart.
171    ///
172    /// @return
173    ///     Returns a non-zero integer ID if this object contains a
174    ///     valid process object, zero if this object does not contain
175    ///     a valid process object.
176    //------------------------------------------------------------------
177    uint32_t
178    GetUniqueID();
179
180    uint32_t
181    GetAddressByteSize() const;
182
183    lldb::SBError
184    Destroy ();
185
186    lldb::SBError
187    Continue ();
188
189    lldb::SBError
190    Stop ();
191
192    lldb::SBError
193    Kill ();
194
195    lldb::SBError
196    Detach ();
197
198    lldb::SBError
199    Signal (int signal);
200
201    void
202    SendAsyncInterrupt();
203
204    uint32_t
205    GetStopID(bool include_expression_stops = false);
206
207    size_t
208    ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
209
210    size_t
211    WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
212
213    size_t
214    ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
215
216    uint64_t
217    ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
218
219    lldb::addr_t
220    ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
221
222    // Events
223    static lldb::StateType
224    GetStateFromEvent (const lldb::SBEvent &event);
225
226    static bool
227    GetRestartedFromEvent (const lldb::SBEvent &event);
228
229    static lldb::SBProcess
230    GetProcessFromEvent (const lldb::SBEvent &event);
231
232    static bool
233    EventIsProcessEvent (const lldb::SBEvent &event);
234
235    lldb::SBBroadcaster
236    GetBroadcaster () const;
237
238    static const char *
239    GetBroadcasterClass ();
240
241    bool
242    GetDescription (lldb::SBStream &description);
243
244    uint32_t
245    GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
246
247    uint32_t
248    LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
249
250    lldb::SBError
251    UnloadImage (uint32_t image_token);
252
253protected:
254    friend class SBAddress;
255    friend class SBBreakpoint;
256    friend class SBBreakpointLocation;
257    friend class SBCommandInterpreter;
258    friend class SBDebugger;
259    friend class SBFunction;
260    friend class SBModule;
261    friend class SBTarget;
262    friend class SBThread;
263    friend class SBValue;
264
265    lldb::ProcessSP
266    GetSP() const;
267
268    void
269    SetSP (const lldb::ProcessSP &process_sp);
270
271    lldb::ProcessWP m_opaque_wp;
272};
273
274}  // namespace lldb
275
276#endif  // LLDB_SBProcess_h_
277