LLDB mainline
SBProcess.h
Go to the documentation of this file.
1//===-- SBProcess.h ---------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_API_SBPROCESS_H
10#define LLDB_API_SBPROCESS_H
11
12#include "lldb/API/SBDefines.h"
13#include "lldb/API/SBError.h"
15#include "lldb/API/SBQueue.h"
16#include "lldb/API/SBTarget.h"
17#include <cstdio>
18
19namespace lldb {
20
21class SBEvent;
22
24public:
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)};
32
33 SBProcess();
34
35 SBProcess(const lldb::SBProcess &rhs);
36
37 const lldb::SBProcess &operator=(const lldb::SBProcess &rhs);
38
39#ifndef SWIG
40 SBProcess(const lldb::ProcessSP &process_sp);
41#endif
42
44
45 static const char *GetBroadcasterClassName();
46
47 const char *GetPluginName();
48
49 // DEPRECATED: use GetPluginName()
50 const char *GetShortPluginName();
51
52 void Clear();
53
54 explicit operator bool() const;
55
56 bool IsValid() const;
57
58 lldb::SBTarget GetTarget() const;
59
60 lldb::ByteOrder GetByteOrder() const;
61
62 size_t PutSTDIN(const char *src, size_t src_len);
63
64 size_t GetSTDOUT(char *dst, size_t dst_len) const;
65
66 size_t GetSTDERR(char *dst, size_t dst_len) const;
67
68 size_t GetAsyncProfileData(char *dst, size_t dst_len) const;
69
70#ifndef SWIG
71 void ReportEventState(const lldb::SBEvent &event, FILE *out) const;
72#endif
73
74 void ReportEventState(const lldb::SBEvent &event, SBFile file) const;
75
76 void ReportEventState(const lldb::SBEvent &event, FileSP BORROWED) const;
77
78 void AppendEventStateReport(const lldb::SBEvent &event,
80
81 /// Remote connection related functions. These will fail if the
82 /// process is not in eStateConnected. They are intended for use
83 /// when connecting to an externally managed debugserver instance.
84 bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error);
85
86 bool RemoteLaunch(char const **argv, char const **envp,
87 const char *stdin_path, const char *stdout_path,
88 const char *stderr_path, const char *working_directory,
89 uint32_t launch_flags, bool stop_at_entry,
91
92 // Thread related functions
93 uint32_t GetNumThreads();
94
95 lldb::SBThread GetThreadAtIndex(size_t index);
96
97 lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id);
98
99 lldb::SBThread GetThreadByIndexID(uint32_t index_id);
100
101 lldb::SBThread GetSelectedThread() const;
102
103 // Function for lazily creating a thread using the current OS plug-in. This
104 // function will be removed in the future when there are APIs to create
105 // SBThread objects through the interface and add them to the process through
106 // the SBProcess API.
107 lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context);
108
109 bool SetSelectedThread(const lldb::SBThread &thread);
110
111 bool SetSelectedThreadByID(lldb::tid_t tid);
112
113 bool SetSelectedThreadByIndexID(uint32_t index_id);
114
115 // Queue related functions
116 uint32_t GetNumQueues();
117
118 lldb::SBQueue GetQueueAtIndex(size_t index);
119
120 // Stepping related functions
121
122 lldb::StateType GetState();
123
124 int GetExitStatus();
125
126 const char *GetExitDescription();
127
128 /// Gets the process ID
129 ///
130 /// Returns the process identifier for the process as it is known
131 /// on the system on which the process is running. For unix systems
132 /// this is typically the same as if you called "getpid()" in the
133 /// process.
134 ///
135 /// \return
136 /// Returns LLDB_INVALID_PROCESS_ID if this object does not
137 /// contain a valid process object, or if the process has not
138 /// been launched. Returns a valid process ID if the process is
139 /// valid.
140 lldb::pid_t GetProcessID();
141
142 /// Gets the unique ID associated with this process object
143 ///
144 /// Unique IDs start at 1 and increment up with each new process
145 /// instance. Since starting a process on a system might always
146 /// create a process with the same process ID, there needs to be a
147 /// way to tell two process instances apart.
148 ///
149 /// \return
150 /// Returns a non-zero integer ID if this object contains a
151 /// valid process object, zero if this object does not contain
152 /// a valid process object.
153 uint32_t GetUniqueID();
154
155 uint32_t GetAddressByteSize() const;
156
157 lldb::SBError Destroy();
158
159 lldb::SBError Continue();
160
161 lldb::SBError Stop();
162
163 lldb::SBError Kill();
164
165 lldb::SBError Detach();
166
167 lldb::SBError Detach(bool keep_stopped);
168
169 lldb::SBError Signal(int signal);
170
171 lldb::SBUnixSignals GetUnixSignals();
172
173 void SendAsyncInterrupt();
174
175 uint32_t GetStopID(bool include_expression_stops = false);
176
177 /// Gets the stop event corresponding to stop ID.
178 //
179 /// Note that it wasn't fully implemented and tracks only the stop
180 /// event for the last natural stop ID.
181 ///
182 /// \param [in] stop_id
183 /// The ID of the stop event to return.
184 ///
185 /// \return
186 /// The stop event corresponding to stop ID.
187 lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
188
189 size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
190
191 size_t WriteMemory(addr_t addr, const void *buf, size_t size,
193
194 size_t ReadCStringFromMemory(addr_t addr, void *char_buf, size_t size,
196
197 uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
199
200 lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
201
202 // Events
203 static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
204
205 static bool GetRestartedFromEvent(const lldb::SBEvent &event);
206
207 static size_t GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event);
208
209 static const char *
210 GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx);
211
212 static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event);
213
214 static bool GetInterruptedFromEvent(const lldb::SBEvent &event);
215
217 GetStructuredDataFromEvent(const lldb::SBEvent &event);
218
219 static bool EventIsProcessEvent(const lldb::SBEvent &event);
220
221 static bool EventIsStructuredDataEvent(const lldb::SBEvent &event);
222
223 lldb::SBBroadcaster GetBroadcaster() const;
224
225 static const char *GetBroadcasterClass();
226
227 bool GetDescription(lldb::SBStream &description);
228
229 SBStructuredData GetExtendedCrashInformation();
230
231 uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const;
232
233 /// Load a shared library into this process.
234 ///
235 /// \param[in] remote_image_spec
236 /// The path for the shared library on the target what you want
237 /// to load.
238 ///
239 /// \param[out] error
240 /// An error object that gets filled in with any errors that
241 /// might occur when trying to load the shared library.
242 ///
243 /// \return
244 /// A token that represents the shared library that can be
245 /// later used to unload the shared library. A value of
246 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
247 /// library can't be opened.
248 uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error);
249
250 /// Load a shared library into this process.
251 ///
252 /// \param[in] local_image_spec
253 /// The file spec that points to the shared library that you
254 /// want to load if the library is located on the host. The
255 /// library will be copied over to the location specified by
256 /// remote_image_spec or into the current working directory with
257 /// the same filename if the remote_image_spec isn't specified.
258 ///
259 /// \param[in] remote_image_spec
260 /// If local_image_spec is specified then the location where the
261 /// library should be copied over from the host. If
262 /// local_image_spec isn't specified, then the path for the
263 /// shared library on the target what you want to load.
264 ///
265 /// \param[out] error
266 /// An error object that gets filled in with any errors that
267 /// might occur when trying to load the shared library.
268 ///
269 /// \return
270 /// A token that represents the shared library that can be
271 /// later used to unload the shared library. A value of
272 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
273 /// library can't be opened.
274 uint32_t LoadImage(const lldb::SBFileSpec &local_image_spec,
275 const lldb::SBFileSpec &remote_image_spec,
277
278 /// Load a shared library into this process, starting with a
279 /// library name and a list of paths, searching along the list of
280 /// paths till you find a matching library.
281 ///
282 /// \param[in] image_spec
283 /// The name of the shared library that you want to load.
284 /// If image_spec is a relative path, the relative path will be
285 /// appended to the search paths.
286 /// If the image_spec is an absolute path, just the basename is used.
287 ///
288 /// \param[in] paths
289 /// A list of paths to search for the library whose basename is
290 /// local_spec.
291 ///
292 /// \param[out] loaded_path
293 /// If the library was found along the paths, this will store the
294 /// full path to the found library.
295 ///
296 /// \param[out] error
297 /// An error object that gets filled in with any errors that
298 /// might occur when trying to search for the shared library.
299 ///
300 /// \return
301 /// A token that represents the shared library that can be
302 /// later passed to UnloadImage. A value of
303 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
304 /// library can't be opened.
305 uint32_t LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
306 SBStringList &paths,
307 lldb::SBFileSpec &loaded_path,
309
310 lldb::SBError UnloadImage(uint32_t image_token);
311
312 lldb::SBError SendEventData(const char *data);
313
314 /// Return the number of different thread-origin extended backtraces
315 /// this process can support.
316 ///
317 /// When the process is stopped and you have an SBThread, lldb may be
318 /// able to show a backtrace of when that thread was originally created,
319 /// or the work item was enqueued to it (in the case of a libdispatch
320 /// queue).
321 ///
322 /// \return
323 /// The number of thread-origin extended backtrace types that may be
324 /// available.
325 uint32_t GetNumExtendedBacktraceTypes();
326
327 /// Return the name of one of the thread-origin extended backtrace
328 /// methods.
329 ///
330 /// \param [in] idx
331 /// The index of the name to return. They will be returned in
332 /// the order that the user will most likely want to see them.
333 /// e.g. if the type at index 0 is not available for a thread,
334 /// see if the type at index 1 provides an extended backtrace.
335 ///
336 /// \return
337 /// The name at that index.
338 const char *GetExtendedBacktraceTypeAtIndex(uint32_t idx);
339
340 lldb::SBThreadCollection GetHistoryThreads(addr_t addr);
341
342 bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type);
343
344 /// Save the state of the process in a core file.
345 ///
346 /// \param[in] file_name - The name of the file to save the core file to.
347 ///
348 /// \param[in] flavor - Specify the flavor of a core file plug-in to save.
349 /// Currently supported flavors include "mach-o" and "minidump"
350 ///
351 /// \param[in] core_style - Specify the style of a core file to save.
352 lldb::SBError SaveCore(const char *file_name, const char *flavor,
353 SaveCoreStyle core_style);
354
355 /// Save the state of the process with the a flavor that matches the
356 /// current process' main executable (if supported).
357 ///
358 /// \param[in] file_name - The name of the file to save the core file to.
359 lldb::SBError SaveCore(const char *file_name);
360
361 /// Query the address load_addr and store the details of the memory
362 /// region that contains it in the supplied SBMemoryRegionInfo object.
363 /// To iterate over all memory regions use GetMemoryRegionList.
364 ///
365 /// \param[in] load_addr
366 /// The address to be queried.
367 ///
368 /// \param[out] region_info
369 /// A reference to an SBMemoryRegionInfo object that will contain
370 /// the details of the memory region containing load_addr.
371 ///
372 /// \return
373 /// An error object describes any errors that occurred while
374 /// querying load_addr.
375 lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr,
376 lldb::SBMemoryRegionInfo &region_info);
377
378 /// Return the list of memory regions within the process.
379 ///
380 /// \return
381 /// A list of all witin the process memory regions.
382 lldb::SBMemoryRegionInfoList GetMemoryRegions();
383
384 /// Return information about the process.
385 ///
386 /// Valid process info will only be returned when the process is
387 /// alive, use SBProcessInfo::IsValid() to check returned info is
388 /// valid.
389 lldb::SBProcessInfo GetProcessInfo();
390
391 /// Allocate memory within the process.
392 ///
393 /// This function will allocate memory in the process's address space.
394 ///
395 /// \param[in] size
396 /// The size of the allocation requested.
397 ///
398 /// \param[in] permissions
399 /// Or together any of the lldb::Permissions bits. The
400 /// permissions on a given memory allocation can't be changed
401 /// after allocation. Note that a block that isn't set writable
402 /// can still be written from lldb, just not by the process
403 /// itself.
404 ///
405 /// \param[out] error
406 /// An error object that gets filled in with any errors that
407 /// might occur when trying allocate.
408 ///
409 /// \return
410 /// The address of the allocated buffer in the process, or
411 /// LLDB_INVALID_ADDRESS if the allocation failed.
412 lldb::addr_t AllocateMemory(size_t size, uint32_t permissions,
414
415 /// Deallocate memory in the process.
416 ///
417 /// This function will deallocate memory in the process's address
418 /// space that was allocated with AllocateMemory.
419 ///
420 /// \param[in] ptr
421 /// A return value from AllocateMemory, pointing to the memory you
422 /// want to deallocate.
423 ///
424 /// \return
425 /// An error object describes any errors that occurred while
426 /// deallocating.
427 ///
428 lldb::SBError DeallocateMemory(lldb::addr_t ptr);
429
430 lldb::ScriptedObject GetScriptedImplementation();
431
432protected:
433 friend class SBAddress;
434 friend class SBBreakpoint;
437 friend class SBDebugger;
438 friend class SBExecutionContext;
439 friend class SBFunction;
440 friend class SBModule;
441 friend class SBTarget;
442 friend class SBThread;
443 friend class SBValue;
445
446 lldb::ProcessSP GetSP() const;
447
448 void SetSP(const lldb::ProcessSP &process_sp);
449
450 lldb::ProcessWP m_opaque_wp;
451};
452
453} // namespace lldb
454
455#endif // LLDB_API_SBPROCESS_H
static size_t ReadCStringFromMemory(ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
Definition: Address.cpp:190
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_API
Definition: SBDefines.h:26
FLAGS_ANONYMOUS_ENUM()
Broadcaster event bits definitions.
Definition: SBProcess.h:26
lldb::ProcessWP m_opaque_wp
Definition: SBProcess.h:450
Definition: SBAddress.h:15
StateType
Process and Thread States.
void * ScriptedObject
Definition: SBDefines.h:117
InstrumentationRuntimeType
uint64_t pid_t
Definition: lldb-types.h:81
ByteOrder
Byte ordering definitions.
class LLDB_API SBEvent
Definition: SBDefines.h:53
uint64_t addr_t
Definition: lldb-types.h:79
uint64_t tid_t
Definition: lldb-types.h:82