|
|
|||
File indexing completed on 2026-05-10 08:42:55
0001 //===-- TargetList.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_TARGET_TARGETLIST_H 0010 #define LLDB_TARGET_TARGETLIST_H 0011 0012 #include <mutex> 0013 #include <vector> 0014 0015 #include "lldb/Target/Target.h" 0016 #include "lldb/Utility/Broadcaster.h" 0017 #include "lldb/Utility/Iterable.h" 0018 0019 namespace lldb_private { 0020 0021 class TargetList : public Broadcaster { 0022 private: 0023 friend class Debugger; 0024 0025 /// Constructor 0026 /// 0027 /// The constructor for the target list is private. Clients can 0028 /// get ahold of the one and only target list through the 0029 /// lldb_private::Debugger::GetSharedInstance().GetTargetList(). 0030 /// 0031 /// \see static TargetList& lldb_private::Debugger::GetTargetList(). 0032 TargetList(Debugger &debugger); 0033 0034 public: 0035 /// Broadcaster event bits definitions. 0036 enum { eBroadcastBitInterrupt = (1 << 0) }; 0037 0038 // These two functions fill out the Broadcaster interface: 0039 0040 static llvm::StringRef GetStaticBroadcasterClass(); 0041 0042 llvm::StringRef GetBroadcasterClass() const override { 0043 return GetStaticBroadcasterClass(); 0044 } 0045 0046 typedef std::vector<lldb::TargetSP> collection; 0047 typedef LockingAdaptedIterable<collection, lldb::TargetSP, vector_adapter, 0048 std::recursive_mutex> 0049 TargetIterable; 0050 0051 /// Create a new Target. 0052 /// 0053 /// Clients must use this function to create a Target. This allows 0054 /// a global list of targets to be maintained in a central location 0055 /// so signal handlers and other global functions can use it to 0056 /// locate an appropriate target to deliver asynchronous information 0057 /// to. 0058 /// 0059 /// \param[in] debugger 0060 /// The debugger to associate this target with 0061 /// 0062 /// \param[in] user_exe_path 0063 /// The main executable file for a debug target. This value 0064 /// can be empty and the file can be set later using: 0065 /// Target::SetExecutableModule (ModuleSP&) 0066 /// 0067 /// \param[in] triple_str 0068 /// A target triple string to be used for the target. This can 0069 /// be nullptr if the triple is not known or when attaching to a 0070 /// process. 0071 /// 0072 /// \param[in] get_dependent_modules 0073 /// Track down the dependent modules for an executable and 0074 /// load those into the module list. 0075 /// 0076 /// \param[in] platform_options 0077 /// A pointer to the platform options to use when creating this 0078 /// target. If this value is nullptr, then the currently selected 0079 /// platform will be used. 0080 /// 0081 /// \param[out] target_sp 0082 /// A shared pointer to a target that will be filled in if 0083 /// this call is successful. 0084 /// 0085 /// \return 0086 /// An error object that indicates success or failure 0087 Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, 0088 llvm::StringRef triple_str, 0089 LoadDependentFiles get_dependent_modules, 0090 const OptionGroupPlatform *platform_options, 0091 lldb::TargetSP &target_sp); 0092 0093 /// Create a new Target. 0094 /// 0095 /// Same as the function above, but used when you already know the 0096 /// platform you will be using 0097 Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, 0098 const ArchSpec &arch, 0099 LoadDependentFiles get_dependent_modules, 0100 lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp); 0101 0102 /// Delete a Target object from the list. 0103 /// 0104 /// When clients are done with the Target objects, this function 0105 /// should be called to release the memory associated with a target 0106 /// object. 0107 /// 0108 /// \param[in] target_sp 0109 /// The shared pointer to a target. 0110 /// 0111 /// \return 0112 /// Returns \b true if the target was successfully removed from 0113 /// from this target list, \b false otherwise. The client will 0114 /// be left with the last remaining shared pointer to the target 0115 /// in \a target_sp which can then be properly released. 0116 bool DeleteTarget(lldb::TargetSP &target_sp); 0117 0118 size_t GetNumTargets() const; 0119 0120 lldb::TargetSP GetTargetAtIndex(uint32_t index) const; 0121 0122 uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const; 0123 0124 /// Find the target that contains has an executable whose path 0125 /// matches \a exe_file_spec, and whose architecture matches 0126 /// \a arch_ptr if arch_ptr is not nullptr. 0127 /// 0128 /// \param[in] exe_file_spec 0129 /// A file spec containing a basename, or a full path (directory 0130 /// and basename). If \a exe_file_spec contains only a filename 0131 /// (empty GetDirectory() value) then matching will be done 0132 /// solely based on the filenames and directories won't be 0133 /// compared. If \a exe_file_spec contains a filename and a 0134 /// directory, then both must match. 0135 /// 0136 /// \param[in] exe_arch_ptr 0137 /// If not nullptr then the architecture also needs to match, else 0138 /// the architectures will be compared. 0139 /// 0140 /// \return 0141 /// A shared pointer to a target object. The returned shared 0142 /// pointer will contain nullptr if no target objects have a 0143 /// executable whose full or partial path matches 0144 /// with a matching process ID. 0145 lldb::TargetSP FindTargetWithExecutableAndArchitecture( 0146 const FileSpec &exe_file_spec, 0147 const ArchSpec *exe_arch_ptr = nullptr) const; 0148 0149 /// Find the target that contains a process with process ID \a 0150 /// pid. 0151 /// 0152 /// \param[in] pid 0153 /// The process ID to search our target list for. 0154 /// 0155 /// \return 0156 /// A shared pointer to a target object. The returned shared 0157 /// pointer will contain nullptr if no target objects own a process 0158 /// with a matching process ID. 0159 lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid) const; 0160 0161 lldb::TargetSP FindTargetWithProcess(lldb_private::Process *process) const; 0162 0163 lldb::TargetSP GetTargetSP(Target *target) const; 0164 0165 /// Send an async interrupt to one or all processes. 0166 /// 0167 /// Find the target that contains the process with process ID \a 0168 /// pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's 0169 /// event queue. 0170 /// 0171 /// \param[in] pid 0172 /// The process ID to search our target list for, if \a pid is 0173 /// LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to 0174 /// all processes. 0175 /// 0176 /// \return 0177 /// The number of async interrupts sent. 0178 uint32_t SendAsyncInterrupt(lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 0179 0180 uint32_t SignalIfRunning(lldb::pid_t pid, int signo); 0181 0182 void SetSelectedTarget(uint32_t index); 0183 0184 void SetSelectedTarget(const lldb::TargetSP &target); 0185 0186 lldb::TargetSP GetSelectedTarget(); 0187 0188 /// Returns whether any module, including ones in the process of being 0189 /// added, contains this module. I don't want to give direct access to 0190 /// these not yet added target, but for interruption purposes, we might 0191 /// need to ask whether this target contains this module. 0192 bool AnyTargetContainsModule(Module &module); 0193 0194 TargetIterable Targets() { 0195 return TargetIterable(m_target_list, m_target_list_mutex); 0196 } 0197 0198 private: 0199 collection m_target_list; 0200 std::unordered_set<lldb::TargetSP> m_in_process_target_list; 0201 mutable std::recursive_mutex m_target_list_mutex; 0202 uint32_t m_selected_target_idx; 0203 0204 static Status CreateTargetInternal( 0205 Debugger &debugger, llvm::StringRef user_exe_path, 0206 llvm::StringRef triple_str, LoadDependentFiles load_dependent_files, 0207 const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp); 0208 0209 static Status CreateTargetInternal(Debugger &debugger, 0210 llvm::StringRef user_exe_path, 0211 const ArchSpec &arch, 0212 LoadDependentFiles get_dependent_modules, 0213 lldb::PlatformSP &platform_sp, 0214 lldb::TargetSP &target_sp); 0215 0216 void RegisterInProcessTarget(lldb::TargetSP target_sp); 0217 0218 void UnregisterInProcessTarget(lldb::TargetSP target_sp); 0219 0220 bool IsTargetInProcess(lldb::TargetSP target_sp); 0221 0222 void AddTargetInternal(lldb::TargetSP target_sp, bool do_select); 0223 0224 void SetSelectedTargetInternal(uint32_t index); 0225 0226 TargetList(const TargetList &) = delete; 0227 const TargetList &operator=(const TargetList &) = delete; 0228 }; 0229 0230 } // namespace lldb_private 0231 0232 #endif // LLDB_TARGET_TARGETLIST_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|