1 //===-- SBProcess.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SBProcess_h_
11 #define LLDB_SBProcess_h_
13 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBError.h"
15 #include "lldb/API/SBProcessInfo.h"
16 #include "lldb/API/SBQueue.h"
17 #include "lldb/API/SBTarget.h"
24 class LLDB_API SBProcess {
26 //------------------------------------------------------------------
27 /// Broadcaster event bits definitions.
28 //------------------------------------------------------------------
29 FLAGS_ANONYMOUS_ENUM(){eBroadcastBitStateChanged = (1 << 0),
30 eBroadcastBitInterrupt = (1 << 1),
31 eBroadcastBitSTDOUT = (1 << 2),
32 eBroadcastBitSTDERR = (1 << 3),
33 eBroadcastBitProfileData = (1 << 4),
34 eBroadcastBitStructuredData = (1 << 5)};
38 SBProcess(const lldb::SBProcess &rhs);
40 const lldb::SBProcess &operator=(const lldb::SBProcess &rhs);
42 SBProcess(const lldb::ProcessSP &process_sp);
46 static const char *GetBroadcasterClassName();
48 const char *GetPluginName();
50 // DEPRECATED: use GetPluginName()
51 const char *GetShortPluginName();
57 lldb::SBTarget GetTarget() const;
59 lldb::ByteOrder GetByteOrder() const;
61 size_t PutSTDIN(const char *src, size_t src_len);
63 size_t GetSTDOUT(char *dst, size_t dst_len) const;
65 size_t GetSTDERR(char *dst, size_t dst_len) const;
67 size_t GetAsyncProfileData(char *dst, size_t dst_len) const;
69 void ReportEventState(const lldb::SBEvent &event, FILE *out) const;
71 void AppendEventStateReport(const lldb::SBEvent &event,
72 lldb::SBCommandReturnObject &result);
74 //------------------------------------------------------------------
75 /// Remote connection related functions. These will fail if the
76 /// process is not in eStateConnected. They are intended for use
77 /// when connecting to an externally managed debugserver instance.
78 //------------------------------------------------------------------
79 bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error);
81 bool RemoteLaunch(char const **argv, char const **envp,
82 const char *stdin_path, const char *stdout_path,
83 const char *stderr_path, const char *working_directory,
84 uint32_t launch_flags, bool stop_at_entry,
85 lldb::SBError &error);
87 //------------------------------------------------------------------
88 // Thread related functions
89 //------------------------------------------------------------------
90 uint32_t GetNumThreads();
92 lldb::SBThread GetThreadAtIndex(size_t index);
94 lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id);
96 lldb::SBThread GetThreadByIndexID(uint32_t index_id);
98 lldb::SBThread GetSelectedThread() const;
100 //------------------------------------------------------------------
101 // Function for lazily creating a thread using the current OS plug-in. This
102 // function will be removed in the future when there are APIs to create
103 // SBThread objects through the interface and add them to the process through
104 // the SBProcess API.
105 //------------------------------------------------------------------
106 lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context);
108 bool SetSelectedThread(const lldb::SBThread &thread);
110 bool SetSelectedThreadByID(lldb::tid_t tid);
112 bool SetSelectedThreadByIndexID(uint32_t index_id);
114 //------------------------------------------------------------------
115 // Queue related functions
116 //------------------------------------------------------------------
117 uint32_t GetNumQueues();
119 lldb::SBQueue GetQueueAtIndex(size_t index);
121 //------------------------------------------------------------------
122 // Stepping related functions
123 //------------------------------------------------------------------
125 lldb::StateType GetState();
129 const char *GetExitDescription();
131 //------------------------------------------------------------------
132 /// Gets the process ID
134 /// Returns the process identifier for the process as it is known
135 /// on the system on which the process is running. For unix systems
136 /// this is typically the same as if you called "getpid()" in the
140 /// Returns LLDB_INVALID_PROCESS_ID if this object does not
141 /// contain a valid process object, or if the process has not
142 /// been launched. Returns a valid process ID if the process is
144 //------------------------------------------------------------------
145 lldb::pid_t GetProcessID();
147 //------------------------------------------------------------------
148 /// Gets the unique ID associated with this process object
150 /// Unique IDs start at 1 and increment up with each new process
151 /// instance. Since starting a process on a system might always
152 /// create a process with the same process ID, there needs to be a
153 /// way to tell two process instances apart.
156 /// Returns a non-zero integer ID if this object contains a
157 /// valid process object, zero if this object does not contain
158 /// a valid process object.
159 //------------------------------------------------------------------
160 uint32_t GetUniqueID();
162 uint32_t GetAddressByteSize() const;
164 lldb::SBError Destroy();
166 lldb::SBError Continue();
168 lldb::SBError Stop();
170 lldb::SBError Kill();
172 lldb::SBError Detach();
174 lldb::SBError Detach(bool keep_stopped);
176 lldb::SBError Signal(int signal);
178 lldb::SBUnixSignals GetUnixSignals();
180 void SendAsyncInterrupt();
182 uint32_t GetStopID(bool include_expression_stops = false);
184 //------------------------------------------------------------------
185 /// Gets the stop event corresponding to stop ID.
187 /// Note that it wasn't fully implemented and tracks only the stop
188 /// event for the last natural stop ID.
190 /// @param [in] stop_id
191 /// The ID of the stop event to return.
194 /// The stop event corresponding to stop ID.
195 //------------------------------------------------------------------
196 lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
198 size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
200 size_t WriteMemory(addr_t addr, const void *buf, size_t size,
201 lldb::SBError &error);
203 size_t ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
204 lldb::SBError &error);
206 uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
207 lldb::SBError &error);
209 lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
212 static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
214 static bool GetRestartedFromEvent(const lldb::SBEvent &event);
216 static size_t GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event);
219 GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx);
221 static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event);
223 static bool GetInterruptedFromEvent(const lldb::SBEvent &event);
225 static lldb::SBStructuredData
226 GetStructuredDataFromEvent(const lldb::SBEvent &event);
228 static bool EventIsProcessEvent(const lldb::SBEvent &event);
230 static bool EventIsStructuredDataEvent(const lldb::SBEvent &event);
232 lldb::SBBroadcaster GetBroadcaster() const;
234 static const char *GetBroadcasterClass();
236 bool GetDescription(lldb::SBStream &description);
238 //------------------------------------------------------------------
239 /// Start Tracing with the given SBTraceOptions.
241 /// @param[in] options
242 /// Class containing trace options like trace buffer size, meta
243 /// data buffer size, TraceType and any custom parameters
244 /// {formatted as a JSON Dictionary}. In case of errors in
245 /// formatting, an error would be reported.
246 /// It must be noted that tracing options such as buffer sizes
247 /// or other custom parameters passed maybe invalid for some
248 /// trace technologies. In such cases the trace implementations
249 /// could choose to either throw an error or could round off to
250 /// the nearest valid options to start tracing if the passed
251 /// value is not supported. To obtain the actual used trace
252 /// options please use the GetTraceConfig API. For the custom
253 /// parameters, only the parameters recognized by the target
254 /// would be used and others would be ignored.
256 /// @param[out] error
257 /// An error explaining what went wrong.
260 /// A SBTrace instance, which should be used
261 /// to get the trace data or other trace related operations.
262 //------------------------------------------------------------------
263 lldb::SBTrace StartTrace(SBTraceOptions &options, lldb::SBError &error);
265 uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const;
267 //------------------------------------------------------------------
268 /// Load a shared library into this process.
270 /// @param[in] remote_image_spec
271 /// The path for the shared library on the target what you want
274 /// @param[out] error
275 /// An error object that gets filled in with any errors that
276 /// might occur when trying to load the shared library.
279 /// A token that represents the shared library that can be
280 /// later used to unload the shared library. A value of
281 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
282 /// library can't be opened.
283 //------------------------------------------------------------------
284 uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error);
286 //------------------------------------------------------------------
287 /// Load a shared library into this process.
289 /// @param[in] local_image_spec
290 /// The file spec that points to the shared library that you
291 /// want to load if the library is located on the host. The
292 /// library will be copied over to the location specified by
293 /// remote_image_spec or into the current working directory with
294 /// the same filename if the remote_image_spec isn't specified.
296 /// @param[in] remote_image_spec
297 /// If local_image_spec is specified then the location where the
298 /// library should be copied over from the host. If
299 /// local_image_spec isn't specified, then the path for the
300 /// shared library on the target what you want to load.
302 /// @param[out] error
303 /// An error object that gets filled in with any errors that
304 /// might occur when trying to load the shared library.
307 /// A token that represents the shared library that can be
308 /// later used to unload the shared library. A value of
309 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
310 /// library can't be opened.
311 //------------------------------------------------------------------
312 uint32_t LoadImage(const lldb::SBFileSpec &local_image_spec,
313 const lldb::SBFileSpec &remote_image_spec,
314 lldb::SBError &error);
316 //------------------------------------------------------------------
317 /// Load a shared library into this process, starting with a
318 /// library name and a list of paths, searching along the list of
319 /// paths till you find a matching library.
321 /// @param[in] local_spec
322 /// The name of the shared library that you want to load.
323 /// If local_spec is a relative path, the relative path will be
324 /// appended to the search paths.
325 /// If the local_spec is an absolute path, just the basename is used.
328 /// A list of paths to search for the library whose basename is
331 /// @param[out] loaded_path
332 /// If the library was found along the paths, this will store the
333 /// full path to the found library.
335 /// @param[out] error
336 /// An error object that gets filled in with any errors that
337 /// might occur when trying to search for the shared library.
340 /// A token that represents the shared library that can be
341 /// later passed to UnloadImage. A value of
342 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
343 /// library can't be opened.
344 //------------------------------------------------------------------
345 uint32_t LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
347 lldb::SBFileSpec &loaded_path,
348 lldb::SBError &error);
350 lldb::SBError UnloadImage(uint32_t image_token);
352 lldb::SBError SendEventData(const char *data);
354 //------------------------------------------------------------------
355 /// Return the number of different thread-origin extended backtraces
356 /// this process can support.
358 /// When the process is stopped and you have an SBThread, lldb may be
359 /// able to show a backtrace of when that thread was originally created,
360 /// or the work item was enqueued to it (in the case of a libdispatch
364 /// The number of thread-origin extended backtrace types that may be
366 //------------------------------------------------------------------
367 uint32_t GetNumExtendedBacktraceTypes();
369 //------------------------------------------------------------------
370 /// Return the name of one of the thread-origin extended backtrace
374 /// The index of the name to return. They will be returned in
375 /// the order that the user will most likely want to see them.
376 /// e.g. if the type at index 0 is not available for a thread,
377 /// see if the type at index 1 provides an extended backtrace.
380 /// The name at that index.
381 //------------------------------------------------------------------
382 const char *GetExtendedBacktraceTypeAtIndex(uint32_t idx);
384 lldb::SBThreadCollection GetHistoryThreads(addr_t addr);
386 bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type);
388 /// Save the state of the process in a core file (or mini dump on Windows).
389 lldb::SBError SaveCore(const char *file_name);
391 //------------------------------------------------------------------
392 /// Query the address load_addr and store the details of the memory
393 /// region that contains it in the supplied SBMemoryRegionInfo object.
394 /// To iterate over all memory regions use GetMemoryRegionList.
396 /// @param[in] load_addr
397 /// The address to be queried.
399 /// @param[out] region_info
400 /// A reference to an SBMemoryRegionInfo object that will contain
401 /// the details of the memory region containing load_addr.
404 /// An error object describes any errors that occurred while
405 /// querying load_addr.
406 //------------------------------------------------------------------
407 lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr,
408 lldb::SBMemoryRegionInfo ®ion_info);
410 //------------------------------------------------------------------
411 /// Return the list of memory regions within the process.
414 /// A list of all witin the process memory regions.
415 //------------------------------------------------------------------
416 lldb::SBMemoryRegionInfoList GetMemoryRegions();
418 //------------------------------------------------------------------
419 /// Return information about the process.
421 /// Valid process info will only be returned when the process is
422 /// alive, use SBProcessInfo::IsValid() to check returned info is
424 //------------------------------------------------------------------
425 lldb::SBProcessInfo GetProcessInfo();
428 friend class SBAddress;
429 friend class SBBreakpoint;
430 friend class SBBreakpointLocation;
431 friend class SBCommandInterpreter;
432 friend class SBDebugger;
433 friend class SBExecutionContext;
434 friend class SBFunction;
435 friend class SBModule;
436 friend class SBTarget;
437 friend class SBThread;
438 friend class SBValue;
439 friend class lldb_private::QueueImpl;
441 lldb::ProcessSP GetSP() const;
443 void SetSP(const lldb::ProcessSP &process_sp);
445 lldb::ProcessWP m_opaque_wp;
450 #endif // LLDB_SBProcess_h_