1 //===-- TargetList.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_TargetList_h_
11 #define liblldb_TargetList_h_
15 // Other libraries and framework includes
17 #include "lldb/Core/Broadcaster.h"
18 #include "lldb/Host/Mutex.h"
19 #include "lldb/Target/Target.h"
21 namespace lldb_private {
23 class TargetList : public Broadcaster
26 friend class Debugger;
28 //------------------------------------------------------------------
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().
35 /// @see static TargetList& lldb_private::Debugger::GetTargetList().
36 //------------------------------------------------------------------
37 TargetList(Debugger &debugger);
41 //------------------------------------------------------------------
42 /// Broadcaster event bits definitions.
43 //------------------------------------------------------------------
46 eBroadcastBitInterrupt = (1 << 0)
50 // These two functions fill out the Broadcaster interface:
52 static ConstString &GetStaticBroadcasterClass ();
54 virtual ConstString &GetBroadcasterClass() const
56 return GetStaticBroadcasterClass();
59 virtual ~TargetList();
61 //------------------------------------------------------------------
62 /// Create a new Target.
64 /// Clients must use this function to create a Target. This allows
65 /// a global list of targets to be maintained in a central location
66 /// so signal handlers and other global functions can use it to
67 /// locate an appropriate target to deliver asynchronous information
70 /// @param[in] debugger
71 /// The debugger to associate this target with
73 /// @param[in] file_spec
74 /// The main executable file for a debug target. This value
75 /// can be NULL and the file can be set later using:
76 /// Target::SetExecutableModule (ModuleSP&)
78 /// @param[in] triple_cstr
79 /// A target triple string to be used for the target. This can
80 /// be NULL if the triple is not known or when attaching to a
83 /// @param[in] get_dependent_modules
84 /// Track down the dependent modules for an executable and
85 /// load those into the module list.
87 /// @param[in] platform_options
88 /// A pointer to the platform options to use when creating this
89 /// target. If this value is NULL, then the currently selected
90 /// platform will be used.
92 /// @param[out] target_sp
93 /// A shared pointer to a target that will be filled in if
94 /// this call is successful.
97 /// An error object that indicates success or failure
98 //------------------------------------------------------------------
100 CreateTarget (Debugger &debugger,
101 const char *user_exe_path,
102 const char *triple_cstr,
103 bool get_dependent_modules,
104 const OptionGroupPlatform *platform_options,
105 lldb::TargetSP &target_sp);
107 //------------------------------------------------------------------
108 /// Create a new Target.
110 /// Same as the function above, but used when you already know the
111 /// platform you will be using
112 //------------------------------------------------------------------
114 CreateTarget (Debugger &debugger,
115 const char *user_exe_path,
116 const ArchSpec& arch,
117 bool get_dependent_modules,
118 lldb::PlatformSP &platform_sp,
119 lldb::TargetSP &target_sp);
121 //------------------------------------------------------------------
122 /// Delete a Target object from the list.
124 /// When clients are done with the Target objets, this function
125 /// should be called to release the memory associated with a target
128 /// @param[in] target_sp
129 /// The shared pointer to a target.
132 /// Returns \b true if the target was successfully removed from
133 /// from this target list, \b false otherwise. The client will
134 /// be left with the last remaining shared pointer to the target
135 /// in \a target_sp which can then be properly released.
136 //------------------------------------------------------------------
138 DeleteTarget (lldb::TargetSP &target_sp);
141 GetNumTargets () const;
144 GetTargetAtIndex (uint32_t index) const;
147 GetIndexOfTarget (lldb::TargetSP target_sp) const;
149 //------------------------------------------------------------------
150 /// Find the target that contains has an executable whose path
151 /// matches \a exe_file_spec, and whose architecture matches
152 /// \a arch_ptr if arch_ptr is not NULL.
154 /// @param[in] exe_file_spec
155 /// A file spec containing a basename, or a full path (directory
156 /// and basename). If \a exe_file_spec contains only a filename
157 /// (empty GetDirectory() value) then matching will be done
158 /// solely based on the filenames and directories won't be
159 /// compared. If \a exe_file_spec contains a filename and a
160 /// directory, then both must match.
162 /// @param[in] exe_arch_ptr
163 /// If not NULL then the architecture also needs to match, else
164 /// the architectures will be compared.
167 /// A shared pointer to a target object. The returned shared
168 /// pointer will contain NULL if no target objects have a
169 /// executable whose full or partial path matches
170 /// with a matching process ID.
171 //------------------------------------------------------------------
173 FindTargetWithExecutableAndArchitecture (const FileSpec &exe_file_spec,
174 const ArchSpec *exe_arch_ptr = NULL) const;
176 //------------------------------------------------------------------
177 /// Find the target that contains a process with process ID \a
181 /// The process ID to search our target list for.
184 /// A shared pointer to a target object. The returned shared
185 /// pointer will contain NULL if no target objects own a process
186 /// with a matching process ID.
187 //------------------------------------------------------------------
189 FindTargetWithProcessID (lldb::pid_t pid) const;
192 FindTargetWithProcess (lldb_private::Process *process) const;
195 GetTargetSP (Target *target) const;
197 //------------------------------------------------------------------
198 /// Send an async interrupt to one or all processes.
200 /// Find the target that contains the process with process ID \a
201 /// pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's
205 /// The process ID to search our target list for, if \a pid is
206 /// LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to
210 /// The number of async interrupts sent.
211 //------------------------------------------------------------------
213 SendAsyncInterrupt (lldb::pid_t pid = LLDB_INVALID_PROCESS_ID);
216 SignalIfRunning (lldb::pid_t pid, int signo);
219 SetSelectedTarget (Target *target);
222 GetSelectedTarget ();
226 typedef std::vector<lldb::TargetSP> collection;
227 //------------------------------------------------------------------
229 //------------------------------------------------------------------
230 collection m_target_list;
231 mutable Mutex m_target_list_mutex;
232 uint32_t m_selected_target_idx;
234 DISALLOW_COPY_AND_ASSIGN (TargetList);
237 } // namespace lldb_private
239 #endif // liblldb_TargetList_h_