TargetList.h revision 24943d2ee8bfaa7cf5893e4709143924157a5c1e
1//===-- TargetList.h --------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_TargetList_h_ 11#define liblldb_TargetList_h_ 12 13// C Includes 14// C++ Includes 15// Other libraries and framework includes 16// Project includes 17#include "lldb/Core/Broadcaster.h" 18#include "lldb/Host/Mutex.h" 19#include "lldb/Target/Target.h" 20 21namespace lldb_private { 22 23class TargetList : public Broadcaster 24{ 25private: 26 friend class Debugger; 27 28 //------------------------------------------------------------------ 29 /// Constructor 30 /// 31 /// The constructor for the target list is private. Clients can 32 /// get ahold of of the one and only target list through the 33 /// lldb_private::Debugger::GetSharedInstance().GetTargetList(). 34 /// 35 /// @see static TargetList& lldb_private::Debugger::GetTargetList(). 36 //------------------------------------------------------------------ 37 TargetList(); 38 39public: 40 41 //------------------------------------------------------------------ 42 /// Broadcaster event bits definitions. 43 //------------------------------------------------------------------ 44 enum 45 { 46 eBroadcastBitInterrupt = (1 << 0) 47 }; 48 49 50 ~TargetList(); 51 52 //------------------------------------------------------------------ 53 /// Create a new Target. 54 /// 55 /// Clients must use this function to create a Target. This allows 56 /// a global list of targets to be maintained in a central location 57 /// so signal handlers and other global functions can use it to 58 /// locate an appropriate target to deliver asynchronous information 59 /// to. 60 /// 61 /// @param[in] file_spec 62 /// The main executable file for a debug target. This value 63 /// can be NULL and the file can be set later using: 64 /// Target::SetExecutableModule (ModuleSP&) 65 /// 66 /// @param[in] arch 67 /// The architecture to use when launching the \a file_spec for 68 /// debugging. This can be NULL if the architecture is not known 69 /// or when attaching to a process. 70 /// 71 /// @param[in] uuid_ptr 72 /// An optional UUID to use when loading a target. When this is 73 /// specified, plug-ins might be able to track down a different 74 /// executable than the one on disk specified by "file_spec" in 75 /// an alternate SDK or build location (such as when doing 76 /// symbolication on non-native OS builds). 77 /// 78 /// @return 79 /// A shared pointer to a target object. 80 //------------------------------------------------------------------ 81 Error 82 CreateTarget (const FileSpec& file_spec, 83 const ArchSpec& arch, 84 const UUID *uuid_ptr, 85 bool get_dependent_files, 86 lldb::TargetSP &target_sp); 87 88 //------------------------------------------------------------------ 89 /// Delete a Target object from the list. 90 /// 91 /// When clients are done with the Target objets, this function 92 /// should be called to release the memory associated with a target 93 /// object. 94 /// 95 /// @param[in] target_sp 96 /// The shared pointer to a target. 97 /// 98 /// @return 99 /// Returns \b true if the target was successfully removed from 100 /// from this target list, \b false otherwise. The client will 101 /// be left with the last remaining shared pointer to the target 102 /// in \a target_sp which can then be properly released. 103 //------------------------------------------------------------------ 104 bool 105 DeleteTarget (lldb::TargetSP &target_sp); 106 107 int 108 GetNumTargets () const; 109 110 lldb::TargetSP 111 GetTargetAtIndex (uint32_t index) const; 112 113 //------------------------------------------------------------------ 114 /// Find the target that contains has an executable whose path 115 /// matches \a exe_file_spec, and whose architecture matches 116 /// \a arch_ptr if arch_ptr is not NULL. 117 /// 118 /// @param[in] exe_file_spec 119 /// A file spec containing a basename, or a full path (directory 120 /// and basename). If \a exe_file_spec contains only a filename 121 /// (empty GetDirectory() value) then matching will be done 122 /// solely based on the filenames and directories won't be 123 /// compared. If \a exe_file_spec contains a filename and a 124 /// directory, then both must match. 125 /// 126 /// @param[in] exe_arch_ptr 127 /// If not NULL then the architecture also needs to match, else 128 /// the architectures will be compared. 129 /// 130 /// @return 131 /// A shared pointer to a target object. The returned shared 132 /// pointer will contain NULL if no target objects have a 133 /// executable whose full or partial path matches 134 /// with a matching process ID. 135 //------------------------------------------------------------------ 136 lldb::TargetSP 137 FindTargetWithExecutableAndArchitecture (const FileSpec &exe_file_spec, 138 const ArchSpec *exe_arch_ptr = NULL) const; 139 140 //------------------------------------------------------------------ 141 /// Find the target that contains a process with process ID \a 142 /// pid. 143 /// 144 /// @param[in] pid 145 /// The process ID to search our target list for. 146 /// 147 /// @return 148 /// A shared pointer to a target object. The returned shared 149 /// pointer will contain NULL if no target objects own a process 150 /// with a matching process ID. 151 //------------------------------------------------------------------ 152 lldb::TargetSP 153 FindTargetWithProcessID (lldb::pid_t pid) const; 154 155 lldb::TargetSP 156 FindTargetWithProcess (lldb_private::Process *process) const; 157 158 lldb::TargetSP 159 GetTargetSP (Target *target) const; 160 161 //------------------------------------------------------------------ 162 /// Send an async interrupt to one or all processes. 163 /// 164 /// Find the target that contains the process with process ID \a 165 /// pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's 166 /// event queue. 167 /// 168 /// @param[in] pid 169 /// The process ID to search our target list for, if \a pid is 170 /// LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to 171 /// all processes. 172 /// 173 /// @return 174 /// The number of async interrupts sent. 175 //------------------------------------------------------------------ 176 uint32_t 177 SendAsyncInterrupt (lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 178 179 uint32_t 180 SignalIfRunning (lldb::pid_t pid, int signo); 181 182 uint32_t 183 SetCurrentTarget (Target *target); 184 185 void 186 SetCurrentTargetWithIndex (uint32_t idx); 187 188 lldb::TargetSP 189 GetCurrentTarget (); 190 191 192protected: 193 typedef std::vector<lldb::TargetSP> collection; 194 //------------------------------------------------------------------ 195 // Member variables. 196 //------------------------------------------------------------------ 197 collection m_target_list; 198 mutable Mutex m_target_list_mutex; 199 uint32_t m_current_target_idx; 200private: 201 DISALLOW_COPY_AND_ASSIGN (TargetList); 202}; 203 204} // namespace lldb_private 205 206#endif // liblldb_TargetList_h_ 207