1 //===-- SBProcess.h ---------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SBProcess_h_
10 #define LLDB_SBProcess_h_
12 #include "lldb/API/SBDefines.h"
13 #include "lldb/API/SBError.h"
14 #include "lldb/API/SBProcessInfo.h"
15 #include "lldb/API/SBQueue.h"
16 #include "lldb/API/SBTarget.h"
23 class LLDB_API SBProcess {
25 /// Broadcaster event bits definitions.
26 FLAGS_ANONYMOUS_ENUM(){eBroadcastBitStateChanged = (1 << 0),
27 eBroadcastBitInterrupt = (1 << 1),
28 eBroadcastBitSTDOUT = (1 << 2),
29 eBroadcastBitSTDERR = (1 << 3),
30 eBroadcastBitProfileData = (1 << 4),
31 eBroadcastBitStructuredData = (1 << 5)};
35 SBProcess(const lldb::SBProcess &rhs);
37 const lldb::SBProcess &operator=(const lldb::SBProcess &rhs);
39 SBProcess(const lldb::ProcessSP &process_sp);
43 static const char *GetBroadcasterClassName();
45 const char *GetPluginName();
47 // DEPRECATED: use GetPluginName()
48 const char *GetShortPluginName();
52 explicit operator bool() const;
56 lldb::SBTarget GetTarget() const;
58 lldb::ByteOrder GetByteOrder() const;
60 size_t PutSTDIN(const char *src, size_t src_len);
62 size_t GetSTDOUT(char *dst, size_t dst_len) const;
64 size_t GetSTDERR(char *dst, size_t dst_len) const;
66 size_t GetAsyncProfileData(char *dst, size_t dst_len) const;
68 void ReportEventState(const lldb::SBEvent &event, FILE *out) const;
70 void AppendEventStateReport(const lldb::SBEvent &event,
71 lldb::SBCommandReturnObject &result);
73 /// Remote connection related functions. These will fail if the
74 /// process is not in eStateConnected. They are intended for use
75 /// when connecting to an externally managed debugserver instance.
76 bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error);
78 bool RemoteLaunch(char const **argv, char const **envp,
79 const char *stdin_path, const char *stdout_path,
80 const char *stderr_path, const char *working_directory,
81 uint32_t launch_flags, bool stop_at_entry,
82 lldb::SBError &error);
84 // Thread related functions
85 uint32_t GetNumThreads();
87 lldb::SBThread GetThreadAtIndex(size_t index);
89 lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id);
91 lldb::SBThread GetThreadByIndexID(uint32_t index_id);
93 lldb::SBThread GetSelectedThread() const;
95 // Function for lazily creating a thread using the current OS plug-in. This
96 // function will be removed in the future when there are APIs to create
97 // SBThread objects through the interface and add them to the process through
99 lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context);
101 bool SetSelectedThread(const lldb::SBThread &thread);
103 bool SetSelectedThreadByID(lldb::tid_t tid);
105 bool SetSelectedThreadByIndexID(uint32_t index_id);
107 // Queue related functions
108 uint32_t GetNumQueues();
110 lldb::SBQueue GetQueueAtIndex(size_t index);
112 // Stepping related functions
114 lldb::StateType GetState();
118 const char *GetExitDescription();
120 /// Gets the process ID
122 /// Returns the process identifier for the process as it is known
123 /// on the system on which the process is running. For unix systems
124 /// this is typically the same as if you called "getpid()" in the
128 /// Returns LLDB_INVALID_PROCESS_ID if this object does not
129 /// contain a valid process object, or if the process has not
130 /// been launched. Returns a valid process ID if the process is
132 lldb::pid_t GetProcessID();
134 /// Gets the unique ID associated with this process object
136 /// Unique IDs start at 1 and increment up with each new process
137 /// instance. Since starting a process on a system might always
138 /// create a process with the same process ID, there needs to be a
139 /// way to tell two process instances apart.
142 /// Returns a non-zero integer ID if this object contains a
143 /// valid process object, zero if this object does not contain
144 /// a valid process object.
145 uint32_t GetUniqueID();
147 uint32_t GetAddressByteSize() const;
149 lldb::SBError Destroy();
151 lldb::SBError Continue();
153 lldb::SBError Stop();
155 lldb::SBError Kill();
157 lldb::SBError Detach();
159 lldb::SBError Detach(bool keep_stopped);
161 lldb::SBError Signal(int signal);
163 lldb::SBUnixSignals GetUnixSignals();
165 void SendAsyncInterrupt();
167 uint32_t GetStopID(bool include_expression_stops = false);
169 /// Gets the stop event corresponding to stop ID.
171 /// Note that it wasn't fully implemented and tracks only the stop
172 /// event for the last natural stop ID.
174 /// \param [in] stop_id
175 /// The ID of the stop event to return.
178 /// The stop event corresponding to stop ID.
179 lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
181 size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
183 size_t WriteMemory(addr_t addr, const void *buf, size_t size,
184 lldb::SBError &error);
186 size_t ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
187 lldb::SBError &error);
189 uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
190 lldb::SBError &error);
192 lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
195 static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
197 static bool GetRestartedFromEvent(const lldb::SBEvent &event);
199 static size_t GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event);
202 GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx);
204 static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event);
206 static bool GetInterruptedFromEvent(const lldb::SBEvent &event);
208 static lldb::SBStructuredData
209 GetStructuredDataFromEvent(const lldb::SBEvent &event);
211 static bool EventIsProcessEvent(const lldb::SBEvent &event);
213 static bool EventIsStructuredDataEvent(const lldb::SBEvent &event);
215 lldb::SBBroadcaster GetBroadcaster() const;
217 static const char *GetBroadcasterClass();
219 bool GetDescription(lldb::SBStream &description);
221 /// Start Tracing with the given SBTraceOptions.
223 /// \param[in] options
224 /// Class containing trace options like trace buffer size, meta
225 /// data buffer size, TraceType and any custom parameters
226 /// {formatted as a JSON Dictionary}. In case of errors in
227 /// formatting, an error would be reported.
228 /// It must be noted that tracing options such as buffer sizes
229 /// or other custom parameters passed maybe invalid for some
230 /// trace technologies. In such cases the trace implementations
231 /// could choose to either throw an error or could round off to
232 /// the nearest valid options to start tracing if the passed
233 /// value is not supported. To obtain the actual used trace
234 /// options please use the GetTraceConfig API. For the custom
235 /// parameters, only the parameters recognized by the target
236 /// would be used and others would be ignored.
238 /// \param[out] error
239 /// An error explaining what went wrong.
242 /// A SBTrace instance, which should be used
243 /// to get the trace data or other trace related operations.
244 lldb::SBTrace StartTrace(SBTraceOptions &options, lldb::SBError &error);
246 uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const;
248 /// Load a shared library into this process.
250 /// \param[in] remote_image_spec
251 /// The path for the shared library on the target what you want
254 /// \param[out] error
255 /// An error object that gets filled in with any errors that
256 /// might occur when trying to load the shared library.
259 /// A token that represents the shared library that can be
260 /// later used to unload the shared library. A value of
261 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
262 /// library can't be opened.
263 uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error);
265 /// Load a shared library into this process.
267 /// \param[in] local_image_spec
268 /// The file spec that points to the shared library that you
269 /// want to load if the library is located on the host. The
270 /// library will be copied over to the location specified by
271 /// remote_image_spec or into the current working directory with
272 /// the same filename if the remote_image_spec isn't specified.
274 /// \param[in] remote_image_spec
275 /// If local_image_spec is specified then the location where the
276 /// library should be copied over from the host. If
277 /// local_image_spec isn't specified, then the path for the
278 /// shared library on the target what you want to load.
280 /// \param[out] error
281 /// An error object that gets filled in with any errors that
282 /// might occur when trying to load the shared library.
285 /// A token that represents the shared library that can be
286 /// later used to unload the shared library. A value of
287 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
288 /// library can't be opened.
289 uint32_t LoadImage(const lldb::SBFileSpec &local_image_spec,
290 const lldb::SBFileSpec &remote_image_spec,
291 lldb::SBError &error);
293 /// Load a shared library into this process, starting with a
294 /// library name and a list of paths, searching along the list of
295 /// paths till you find a matching library.
297 /// \param[in] image_spec
298 /// The name of the shared library that you want to load.
299 /// If image_spec is a relative path, the relative path will be
300 /// appended to the search paths.
301 /// If the image_spec is an absolute path, just the basename is used.
304 /// A list of paths to search for the library whose basename is
307 /// \param[out] loaded_path
308 /// If the library was found along the paths, this will store the
309 /// full path to the found library.
311 /// \param[out] error
312 /// An error object that gets filled in with any errors that
313 /// might occur when trying to search for the shared library.
316 /// A token that represents the shared library that can be
317 /// later passed to UnloadImage. A value of
318 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
319 /// library can't be opened.
320 uint32_t LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
322 lldb::SBFileSpec &loaded_path,
323 lldb::SBError &error);
325 lldb::SBError UnloadImage(uint32_t image_token);
327 lldb::SBError SendEventData(const char *data);
329 /// Return the number of different thread-origin extended backtraces
330 /// this process can support.
332 /// When the process is stopped and you have an SBThread, lldb may be
333 /// able to show a backtrace of when that thread was originally created,
334 /// or the work item was enqueued to it (in the case of a libdispatch
338 /// The number of thread-origin extended backtrace types that may be
340 uint32_t GetNumExtendedBacktraceTypes();
342 /// Return the name of one of the thread-origin extended backtrace
346 /// The index of the name to return. They will be returned in
347 /// the order that the user will most likely want to see them.
348 /// e.g. if the type at index 0 is not available for a thread,
349 /// see if the type at index 1 provides an extended backtrace.
352 /// The name at that index.
353 const char *GetExtendedBacktraceTypeAtIndex(uint32_t idx);
355 lldb::SBThreadCollection GetHistoryThreads(addr_t addr);
357 bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type);
359 /// Save the state of the process in a core file (or mini dump on Windows).
360 lldb::SBError SaveCore(const char *file_name);
362 /// Query the address load_addr and store the details of the memory
363 /// region that contains it in the supplied SBMemoryRegionInfo object.
364 /// To iterate over all memory regions use GetMemoryRegionList.
366 /// \param[in] load_addr
367 /// The address to be queried.
369 /// \param[out] region_info
370 /// A reference to an SBMemoryRegionInfo object that will contain
371 /// the details of the memory region containing load_addr.
374 /// An error object describes any errors that occurred while
375 /// querying load_addr.
376 lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr,
377 lldb::SBMemoryRegionInfo ®ion_info);
379 /// Return the list of memory regions within the process.
382 /// A list of all witin the process memory regions.
383 lldb::SBMemoryRegionInfoList GetMemoryRegions();
385 /// Return information about the process.
387 /// Valid process info will only be returned when the process is
388 /// alive, use SBProcessInfo::IsValid() to check returned info is
390 lldb::SBProcessInfo GetProcessInfo();
393 friend class SBAddress;
394 friend class SBBreakpoint;
395 friend class SBBreakpointLocation;
396 friend class SBCommandInterpreter;
397 friend class SBDebugger;
398 friend class SBExecutionContext;
399 friend class SBFunction;
400 friend class SBModule;
401 friend class SBTarget;
402 friend class SBThread;
403 friend class SBValue;
404 friend class lldb_private::QueueImpl;
406 lldb::ProcessSP GetSP() const;
408 void SetSP(const lldb::ProcessSP &process_sp);
410 lldb::ProcessWP m_opaque_wp;
415 #endif // LLDB_SBProcess_h_