SBProcess.h revision 411ab47806a478d932926ef7a309ea37edf1f7e7
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    //------------------------------------------------------------------
126    // Function for lazily creating a thread using the current OS
127    // plug-in. This function will be removed in the future when there
128    // are APIs to create SBThread objects through the interface and add
129    // them to the process through the SBProcess API.
130    //------------------------------------------------------------------
131    lldb::SBThread
132    CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
133
134    bool
135    SetSelectedThread (const lldb::SBThread &thread);
136
137    bool
138    SetSelectedThreadByID (lldb::tid_t tid);
139
140    bool
141    SetSelectedThreadByIndexID (uint32_t index_id);
142
143    //------------------------------------------------------------------
144    // Stepping related functions
145    //------------------------------------------------------------------
146
147    lldb::StateType
148    GetState ();
149
150    int
151    GetExitStatus ();
152
153    const char *
154    GetExitDescription ();
155
156    //------------------------------------------------------------------
157    /// Gets the process ID
158    ///
159    /// Returns the process identifier for the process as it is known
160    /// on the system on which the process is running. For unix systems
161    /// this is typically the same as if you called "getpid()" in the
162    /// process.
163    ///
164    /// @return
165    ///     Returns LLDB_INVALID_PROCESS_ID if this object does not
166    ///     contain a valid process object, or if the process has not
167    ///     been launched. Returns a valid process ID if the process is
168    ///     valid.
169    //------------------------------------------------------------------
170    lldb::pid_t
171    GetProcessID ();
172
173    //------------------------------------------------------------------
174    /// Gets the unique ID associated with this process object
175    ///
176    /// Unique IDs start at 1 and increment up with each new process
177    /// instance. Since starting a process on a system might always
178    /// create a process with the same process ID, there needs to be a
179    /// way to tell two process instances apart.
180    ///
181    /// @return
182    ///     Returns a non-zero integer ID if this object contains a
183    ///     valid process object, zero if this object does not contain
184    ///     a valid process object.
185    //------------------------------------------------------------------
186    uint32_t
187    GetUniqueID();
188
189    uint32_t
190    GetAddressByteSize() const;
191
192    lldb::SBError
193    Destroy ();
194
195    lldb::SBError
196    Continue ();
197
198    lldb::SBError
199    Stop ();
200
201    lldb::SBError
202    Kill ();
203
204    lldb::SBError
205    Detach ();
206
207    lldb::SBError
208    Signal (int signal);
209
210    void
211    SendAsyncInterrupt();
212
213    uint32_t
214    GetStopID(bool include_expression_stops = false);
215
216    size_t
217    ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
218
219    size_t
220    WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
221
222    size_t
223    ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
224
225    uint64_t
226    ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
227
228    lldb::addr_t
229    ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
230
231    // Events
232    static lldb::StateType
233    GetStateFromEvent (const lldb::SBEvent &event);
234
235    static bool
236    GetRestartedFromEvent (const lldb::SBEvent &event);
237
238    static size_t
239    GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event);
240
241    static const char *
242    GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx);
243
244    static lldb::SBProcess
245    GetProcessFromEvent (const lldb::SBEvent &event);
246
247    static bool
248    EventIsProcessEvent (const lldb::SBEvent &event);
249
250    lldb::SBBroadcaster
251    GetBroadcaster () const;
252
253    static const char *
254    GetBroadcasterClass ();
255
256    bool
257    GetDescription (lldb::SBStream &description);
258
259    uint32_t
260    GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
261
262    uint32_t
263    LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
264
265    lldb::SBError
266    UnloadImage (uint32_t image_token);
267
268protected:
269    friend class SBAddress;
270    friend class SBBreakpoint;
271    friend class SBBreakpointLocation;
272    friend class SBCommandInterpreter;
273    friend class SBDebugger;
274    friend class SBFunction;
275    friend class SBModule;
276    friend class SBTarget;
277    friend class SBThread;
278    friend class SBValue;
279
280    lldb::ProcessSP
281    GetSP() const;
282
283    void
284    SetSP (const lldb::ProcessSP &process_sp);
285
286    lldb::ProcessWP m_opaque_wp;
287};
288
289}  // namespace lldb
290
291#endif  // LLDB_SBProcess_h_
292