|
|
|||
File indexing completed on 2026-05-10 08:42:42
0001 //===-- SBProcess.h ---------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLDB_API_SBPROCESS_H 0010 #define LLDB_API_SBPROCESS_H 0011 0012 #include "lldb/API/SBDefines.h" 0013 #include "lldb/API/SBError.h" 0014 #include "lldb/API/SBProcessInfo.h" 0015 #include "lldb/API/SBQueue.h" 0016 #include "lldb/API/SBTarget.h" 0017 #include <cstdio> 0018 0019 namespace lldb_private { 0020 namespace python { 0021 class SWIGBridge; 0022 } 0023 } // namespace lldb_private 0024 0025 namespace lldb { 0026 0027 class SBEvent; 0028 0029 class LLDB_API SBProcess { 0030 public: 0031 /// Broadcaster event bits definitions. 0032 FLAGS_ANONYMOUS_ENUM(){eBroadcastBitStateChanged = (1 << 0), 0033 eBroadcastBitInterrupt = (1 << 1), 0034 eBroadcastBitSTDOUT = (1 << 2), 0035 eBroadcastBitSTDERR = (1 << 3), 0036 eBroadcastBitProfileData = (1 << 4), 0037 eBroadcastBitStructuredData = (1 << 5)}; 0038 0039 SBProcess(); 0040 0041 SBProcess(const lldb::SBProcess &rhs); 0042 0043 const lldb::SBProcess &operator=(const lldb::SBProcess &rhs); 0044 0045 ~SBProcess(); 0046 0047 static const char *GetBroadcasterClassName(); 0048 0049 const char *GetPluginName(); 0050 0051 LLDB_DEPRECATED_FIXME("Use GetPluginName()", "GetPluginName()") 0052 const char *GetShortPluginName(); 0053 0054 void Clear(); 0055 0056 explicit operator bool() const; 0057 0058 bool IsValid() const; 0059 0060 lldb::SBTarget GetTarget() const; 0061 0062 lldb::ByteOrder GetByteOrder() const; 0063 0064 size_t PutSTDIN(const char *src, size_t src_len); 0065 0066 size_t GetSTDOUT(char *dst, size_t dst_len) const; 0067 0068 size_t GetSTDERR(char *dst, size_t dst_len) const; 0069 0070 size_t GetAsyncProfileData(char *dst, size_t dst_len) const; 0071 0072 #ifndef SWIG 0073 void ReportEventState(const lldb::SBEvent &event, FILE *out) const; 0074 #endif 0075 0076 void ReportEventState(const lldb::SBEvent &event, SBFile file) const; 0077 0078 void ReportEventState(const lldb::SBEvent &event, FileSP BORROWED) const; 0079 0080 void AppendEventStateReport(const lldb::SBEvent &event, 0081 lldb::SBCommandReturnObject &result); 0082 0083 /// Remote connection related functions. These will fail if the 0084 /// process is not in eStateConnected. They are intended for use 0085 /// when connecting to an externally managed debugserver instance. 0086 bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error); 0087 0088 bool RemoteLaunch(char const **argv, char const **envp, 0089 const char *stdin_path, const char *stdout_path, 0090 const char *stderr_path, const char *working_directory, 0091 uint32_t launch_flags, bool stop_at_entry, 0092 lldb::SBError &error); 0093 0094 // Thread related functions 0095 uint32_t GetNumThreads(); 0096 0097 lldb::SBThread GetThreadAtIndex(size_t index); 0098 0099 lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id); 0100 0101 lldb::SBThread GetThreadByIndexID(uint32_t index_id); 0102 0103 lldb::SBThread GetSelectedThread() const; 0104 0105 // Function for lazily creating a thread using the current OS plug-in. This 0106 // function will be removed in the future when there are APIs to create 0107 // SBThread objects through the interface and add them to the process through 0108 // the SBProcess API. 0109 lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context); 0110 0111 bool SetSelectedThread(const lldb::SBThread &thread); 0112 0113 bool SetSelectedThreadByID(lldb::tid_t tid); 0114 0115 bool SetSelectedThreadByIndexID(uint32_t index_id); 0116 0117 // Queue related functions 0118 uint32_t GetNumQueues(); 0119 0120 lldb::SBQueue GetQueueAtIndex(size_t index); 0121 0122 // Stepping related functions 0123 0124 lldb::StateType GetState(); 0125 0126 int GetExitStatus(); 0127 0128 const char *GetExitDescription(); 0129 0130 /// Gets the process ID 0131 /// 0132 /// Returns the process identifier for the process as it is known 0133 /// on the system on which the process is running. For unix systems 0134 /// this is typically the same as if you called "getpid()" in the 0135 /// process. 0136 /// 0137 /// \return 0138 /// Returns LLDB_INVALID_PROCESS_ID if this object does not 0139 /// contain a valid process object, or if the process has not 0140 /// been launched. Returns a valid process ID if the process is 0141 /// valid. 0142 lldb::pid_t GetProcessID(); 0143 0144 /// Gets the unique ID associated with this process object 0145 /// 0146 /// Unique IDs start at 1 and increment up with each new process 0147 /// instance. Since starting a process on a system might always 0148 /// create a process with the same process ID, there needs to be a 0149 /// way to tell two process instances apart. 0150 /// 0151 /// \return 0152 /// Returns a non-zero integer ID if this object contains a 0153 /// valid process object, zero if this object does not contain 0154 /// a valid process object. 0155 uint32_t GetUniqueID(); 0156 0157 uint32_t GetAddressByteSize() const; 0158 0159 lldb::SBError Destroy(); 0160 0161 lldb::SBError Continue(); 0162 0163 lldb::SBError Stop(); 0164 0165 lldb::SBError Kill(); 0166 0167 lldb::SBError Detach(); 0168 0169 lldb::SBError Detach(bool keep_stopped); 0170 0171 lldb::SBError Signal(int signal); 0172 0173 lldb::SBUnixSignals GetUnixSignals(); 0174 0175 void SendAsyncInterrupt(); 0176 0177 uint32_t GetStopID(bool include_expression_stops = false); 0178 0179 /// Gets the stop event corresponding to stop ID. 0180 // 0181 /// Note that it wasn't fully implemented and tracks only the stop 0182 /// event for the last natural stop ID. 0183 /// 0184 /// \param [in] stop_id 0185 /// The ID of the stop event to return. 0186 /// 0187 /// \return 0188 /// The stop event corresponding to stop ID. 0189 lldb::SBEvent GetStopEventForStopID(uint32_t stop_id); 0190 0191 /// If the process is a scripted process, changes its state to the new state. 0192 /// No-op otherwise. 0193 /// 0194 /// \param [in] new_state 0195 /// The new state that the scripted process should be set to. 0196 /// 0197 void ForceScriptedState(StateType new_state); 0198 0199 size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error); 0200 0201 size_t WriteMemory(addr_t addr, const void *buf, size_t size, 0202 lldb::SBError &error); 0203 0204 size_t ReadCStringFromMemory(addr_t addr, void *char_buf, size_t size, 0205 lldb::SBError &error); 0206 0207 uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size, 0208 lldb::SBError &error); 0209 0210 lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error); 0211 0212 lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size, 0213 const SBAddressRangeList &ranges, 0214 uint32_t alignment, 0215 uint32_t max_matches, 0216 SBError &error); 0217 0218 lldb::addr_t FindInMemory(const void *buf, uint64_t size, 0219 const SBAddressRange &range, uint32_t alignment, 0220 SBError &error); 0221 0222 // Events 0223 static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event); 0224 0225 static bool GetRestartedFromEvent(const lldb::SBEvent &event); 0226 0227 static size_t GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event); 0228 0229 static const char * 0230 GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx); 0231 0232 static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event); 0233 0234 static bool GetInterruptedFromEvent(const lldb::SBEvent &event); 0235 0236 static lldb::SBStructuredData 0237 GetStructuredDataFromEvent(const lldb::SBEvent &event); 0238 0239 static bool EventIsProcessEvent(const lldb::SBEvent &event); 0240 0241 static bool EventIsStructuredDataEvent(const lldb::SBEvent &event); 0242 0243 lldb::SBBroadcaster GetBroadcaster() const; 0244 0245 static const char *GetBroadcasterClass(); 0246 0247 bool GetDescription(lldb::SBStream &description); 0248 0249 SBStructuredData GetExtendedCrashInformation(); 0250 0251 uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const; 0252 0253 /// Load a shared library into this process. 0254 /// 0255 /// \param[in] remote_image_spec 0256 /// The path for the shared library on the target what you want 0257 /// to load. 0258 /// 0259 /// \param[out] error 0260 /// An error object that gets filled in with any errors that 0261 /// might occur when trying to load the shared library. 0262 /// 0263 /// \return 0264 /// A token that represents the shared library that can be 0265 /// later used to unload the shared library. A value of 0266 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 0267 /// library can't be opened. 0268 uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error); 0269 0270 /// Load a shared library into this process. 0271 /// 0272 /// \param[in] local_image_spec 0273 /// The file spec that points to the shared library that you 0274 /// want to load if the library is located on the host. The 0275 /// library will be copied over to the location specified by 0276 /// remote_image_spec or into the current working directory with 0277 /// the same filename if the remote_image_spec isn't specified. 0278 /// 0279 /// \param[in] remote_image_spec 0280 /// If local_image_spec is specified then the location where the 0281 /// library should be copied over from the host. If 0282 /// local_image_spec isn't specified, then the path for the 0283 /// shared library on the target what you want to load. 0284 /// 0285 /// \param[out] error 0286 /// An error object that gets filled in with any errors that 0287 /// might occur when trying to load the shared library. 0288 /// 0289 /// \return 0290 /// A token that represents the shared library that can be 0291 /// later used to unload the shared library. A value of 0292 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 0293 /// library can't be opened. 0294 uint32_t LoadImage(const lldb::SBFileSpec &local_image_spec, 0295 const lldb::SBFileSpec &remote_image_spec, 0296 lldb::SBError &error); 0297 0298 /// Load a shared library into this process, starting with a 0299 /// library name and a list of paths, searching along the list of 0300 /// paths till you find a matching library. 0301 /// 0302 /// \param[in] image_spec 0303 /// The name of the shared library that you want to load. 0304 /// If image_spec is a relative path, the relative path will be 0305 /// appended to the search paths. 0306 /// If the image_spec is an absolute path, just the basename is used. 0307 /// 0308 /// \param[in] paths 0309 /// A list of paths to search for the library whose basename is 0310 /// local_spec. 0311 /// 0312 /// \param[out] loaded_path 0313 /// If the library was found along the paths, this will store the 0314 /// full path to the found library. 0315 /// 0316 /// \param[out] error 0317 /// An error object that gets filled in with any errors that 0318 /// might occur when trying to search for the shared library. 0319 /// 0320 /// \return 0321 /// A token that represents the shared library that can be 0322 /// later passed to UnloadImage. A value of 0323 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 0324 /// library can't be opened. 0325 uint32_t LoadImageUsingPaths(const lldb::SBFileSpec &image_spec, 0326 SBStringList &paths, 0327 lldb::SBFileSpec &loaded_path, 0328 lldb::SBError &error); 0329 0330 lldb::SBError UnloadImage(uint32_t image_token); 0331 0332 lldb::SBError SendEventData(const char *data); 0333 0334 /// Return the number of different thread-origin extended backtraces 0335 /// this process can support. 0336 /// 0337 /// When the process is stopped and you have an SBThread, lldb may be 0338 /// able to show a backtrace of when that thread was originally created, 0339 /// or the work item was enqueued to it (in the case of a libdispatch 0340 /// queue). 0341 /// 0342 /// \return 0343 /// The number of thread-origin extended backtrace types that may be 0344 /// available. 0345 uint32_t GetNumExtendedBacktraceTypes(); 0346 0347 /// Return the name of one of the thread-origin extended backtrace 0348 /// methods. 0349 /// 0350 /// \param [in] idx 0351 /// The index of the name to return. They will be returned in 0352 /// the order that the user will most likely want to see them. 0353 /// e.g. if the type at index 0 is not available for a thread, 0354 /// see if the type at index 1 provides an extended backtrace. 0355 /// 0356 /// \return 0357 /// The name at that index. 0358 const char *GetExtendedBacktraceTypeAtIndex(uint32_t idx); 0359 0360 lldb::SBThreadCollection GetHistoryThreads(addr_t addr); 0361 0362 bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type); 0363 0364 /// Save the state of the process in a core file. 0365 /// 0366 /// \param[in] file_name - The name of the file to save the core file to. 0367 /// 0368 /// \param[in] flavor - Specify the flavor of a core file plug-in to save. 0369 /// Currently supported flavors include "mach-o" and "minidump" 0370 /// 0371 /// \param[in] core_style - Specify the style of a core file to save. 0372 lldb::SBError SaveCore(const char *file_name, const char *flavor, 0373 SaveCoreStyle core_style); 0374 0375 /// Save the state of the process with the a flavor that matches the 0376 /// current process' main executable (if supported). 0377 /// 0378 /// \param[in] file_name - The name of the file to save the core file to. 0379 lldb::SBError SaveCore(const char *file_name); 0380 0381 /// Save the state of the process with the desired settings 0382 /// as defined in the options object. 0383 /// 0384 /// \param[in] options - The options to use when saving the core file. 0385 lldb::SBError SaveCore(SBSaveCoreOptions &options); 0386 0387 /// Query the address load_addr and store the details of the memory 0388 /// region that contains it in the supplied SBMemoryRegionInfo object. 0389 /// To iterate over all memory regions use GetMemoryRegionList. 0390 /// 0391 /// \param[in] load_addr 0392 /// The address to be queried. 0393 /// 0394 /// \param[out] region_info 0395 /// A reference to an SBMemoryRegionInfo object that will contain 0396 /// the details of the memory region containing load_addr. 0397 /// 0398 /// \return 0399 /// An error object describes any errors that occurred while 0400 /// querying load_addr. 0401 lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr, 0402 lldb::SBMemoryRegionInfo ®ion_info); 0403 0404 /// Return the list of memory regions within the process. 0405 /// 0406 /// \return 0407 /// A list of all witin the process memory regions. 0408 lldb::SBMemoryRegionInfoList GetMemoryRegions(); 0409 0410 /// Return information about the process. 0411 /// 0412 /// Valid process info will only be returned when the process is 0413 /// alive, use SBProcessInfo::IsValid() to check returned info is 0414 /// valid. 0415 lldb::SBProcessInfo GetProcessInfo(); 0416 0417 /// Get the file specification for the core file that is currently being used 0418 /// for the process. If the process is not loaded from a core file, then an 0419 /// invalid file specification will be returned. 0420 /// 0421 /// \return 0422 /// The path to the core file for this target or an invalid file spec if 0423 /// the process isn't loaded from a core file. 0424 lldb::SBFileSpec GetCoreFile(); 0425 0426 /// \{ 0427 /// \group Mask Address Methods 0428 /// 0429 /// \a type 0430 /// All of the methods in this group take \a type argument 0431 /// which is an AddressMaskType enum value. 0432 /// There can be different address masks for code addresses and 0433 /// data addresses, this argument can select which to get/set, 0434 /// or to use when clearing non-addressable bits from an address. 0435 /// This choice of mask can be important for example on AArch32 0436 /// systems. Where instructions where instructions start on even addresses, 0437 /// the 0th bit may be used to indicate that a function is thumb code. On 0438 /// such a target, the eAddressMaskTypeCode may clear the 0th bit from an 0439 /// address to get the actual address Whereas eAddressMaskTypeData would not. 0440 /// 0441 /// \a addr_range 0442 /// Many of the methods in this group take an \a addr_range argument 0443 /// which is an AddressMaskRange enum value. 0444 /// Needing to specify the address range is highly unusual, and the 0445 /// default argument can be used in nearly all circumstances. 0446 /// On some architectures (e.g., AArch64), it is possible to have 0447 /// different page table setups for low and high memory, so different 0448 /// numbers of bits relevant to addressing. It is possible to have 0449 /// a program running in one half of memory and accessing the other 0450 /// as heap, so we need to maintain two different sets of address masks 0451 /// to debug this correctly. 0452 0453 /// Get the current address mask that will be applied to addresses 0454 /// before reading from memory. 0455 /// 0456 /// \param[in] type 0457 /// See \ref Mask Address Methods description of this argument. 0458 /// eAddressMaskTypeAny is often a suitable value when code and 0459 /// data masks are the same on a given target. 0460 /// 0461 /// \param[in] addr_range 0462 /// See \ref Mask Address Methods description of this argument. 0463 /// This will default to eAddressMaskRangeLow which is the 0464 /// only set of masks used normally. 0465 /// 0466 /// \return 0467 /// The address mask currently in use. Bits which are not used 0468 /// for addressing will be set to 1 in the mask. 0469 lldb::addr_t GetAddressMask( 0470 lldb::AddressMaskType type, 0471 lldb::AddressMaskRange addr_range = lldb::eAddressMaskRangeLow); 0472 0473 /// Set the current address mask that can be applied to addresses 0474 /// before reading from memory. 0475 /// 0476 /// \param[in] type 0477 /// See \ref Mask Address Methods description of this argument. 0478 /// eAddressMaskTypeAll is often a suitable value when the 0479 /// same mask is being set for both code and data. 0480 /// 0481 /// \param[in] mask 0482 /// The address mask to set. Bits which are not used for addressing 0483 /// should be set to 1 in the mask. 0484 /// 0485 /// \param[in] addr_range 0486 /// See \ref Mask Address Methods description of this argument. 0487 /// This will default to eAddressMaskRangeLow which is the 0488 /// only set of masks used normally. 0489 void SetAddressMask( 0490 lldb::AddressMaskType type, lldb::addr_t mask, 0491 lldb::AddressMaskRange addr_range = lldb::eAddressMaskRangeLow); 0492 0493 /// Set the number of bits used for addressing in this Process. 0494 /// 0495 /// On Darwin and similar systems, the addressable bits are expressed 0496 /// as the number of low order bits that are relevant to addressing, 0497 /// instead of a more general address mask. 0498 /// This method calculates the correct mask value for a given number 0499 /// of low order addressable bits. 0500 /// 0501 /// \param[in] type 0502 /// See \ref Mask Address Methods description of this argument. 0503 /// eAddressMaskTypeAll is often a suitable value when the 0504 /// same mask is being set for both code and data. 0505 /// 0506 /// \param[in] num_bits 0507 /// Number of bits that are used for addressing. 0508 /// For example, a value of 42 indicates that the low 42 bits 0509 /// are relevant for addressing, and that higher-order bits may 0510 /// be used for various metadata like pointer authentication, 0511 /// Type Byte Ignore, etc. 0512 /// 0513 /// \param[in] addr_range 0514 /// See \ref Mask Address Methods description of this argument. 0515 /// This will default to eAddressMaskRangeLow which is the 0516 /// only set of masks used normally. 0517 void 0518 SetAddressableBits(AddressMaskType type, uint32_t num_bits, 0519 AddressMaskRange addr_range = lldb::eAddressMaskRangeLow); 0520 0521 /// Clear the non-address bits of an \a addr value and return a 0522 /// virtual address in memory. 0523 /// 0524 /// Bits that are not used in addressing may be used for other purposes; 0525 /// pointer authentication, or metadata in the top byte, or the 0th bit 0526 /// of armv7 code addresses to indicate arm/thumb are common examples. 0527 /// 0528 /// \param[in] addr 0529 /// The address that should be cleared of non-address bits. 0530 /// 0531 /// \param[in] type 0532 /// See \ref Mask Address Methods description of this argument. 0533 /// eAddressMaskTypeAny is the default value, correct when it 0534 /// is unknown if the address is a code or data address. 0535 lldb::addr_t 0536 FixAddress(lldb::addr_t addr, 0537 lldb::AddressMaskType type = lldb::eAddressMaskTypeAny); 0538 /// \} 0539 0540 /// Allocate memory within the process. 0541 /// 0542 /// This function will allocate memory in the process's address space. 0543 /// 0544 /// \param[in] size 0545 /// The size of the allocation requested. 0546 /// 0547 /// \param[in] permissions 0548 /// Or together any of the lldb::Permissions bits. The 0549 /// permissions on a given memory allocation can't be changed 0550 /// after allocation. Note that a block that isn't set writable 0551 /// can still be written from lldb, just not by the process 0552 /// itself. 0553 /// 0554 /// \param[out] error 0555 /// An error object that gets filled in with any errors that 0556 /// might occur when trying allocate. 0557 /// 0558 /// \return 0559 /// The address of the allocated buffer in the process, or 0560 /// LLDB_INVALID_ADDRESS if the allocation failed. 0561 lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, 0562 lldb::SBError &error); 0563 0564 /// Deallocate memory in the process. 0565 /// 0566 /// This function will deallocate memory in the process's address 0567 /// space that was allocated with AllocateMemory. 0568 /// 0569 /// \param[in] ptr 0570 /// A return value from AllocateMemory, pointing to the memory you 0571 /// want to deallocate. 0572 /// 0573 /// \return 0574 /// An error object describes any errors that occurred while 0575 /// deallocating. 0576 /// 0577 lldb::SBError DeallocateMemory(lldb::addr_t ptr); 0578 0579 lldb::SBScriptObject GetScriptedImplementation(); 0580 0581 void GetStatus(SBStream &status); 0582 0583 protected: 0584 friend class SBAddress; 0585 friend class SBBreakpoint; 0586 friend class SBBreakpointCallbackBaton; 0587 friend class SBBreakpointLocation; 0588 friend class SBCommandInterpreter; 0589 friend class SBSaveCoreOptions; 0590 friend class SBDebugger; 0591 friend class SBExecutionContext; 0592 friend class SBFunction; 0593 friend class SBModule; 0594 friend class SBPlatform; 0595 friend class SBTarget; 0596 friend class SBThread; 0597 friend class SBValue; 0598 friend class lldb_private::QueueImpl; 0599 0600 friend class lldb_private::python::SWIGBridge; 0601 0602 SBProcess(const lldb::ProcessSP &process_sp); 0603 0604 lldb::ProcessSP GetSP() const; 0605 0606 void SetSP(const lldb::ProcessSP &process_sp); 0607 0608 lldb::ProcessWP m_opaque_wp; 0609 }; 0610 0611 } // namespace lldb 0612 0613 #endif // LLDB_API_SBPROCESS_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|