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_
18 // Other libraries and framework includes
20 #include "lldb/Core/Broadcaster.h"
21 #include "lldb/Target/Target.h"
23 namespace lldb_private {
25 class TargetList : public Broadcaster {
27 friend class Debugger;
29 //------------------------------------------------------------------
32 /// The constructor for the target list is private. Clients can
33 /// get ahold of of the one and only target list through the
34 /// lldb_private::Debugger::GetSharedInstance().GetTargetList().
36 /// @see static TargetList& lldb_private::Debugger::GetTargetList().
37 //------------------------------------------------------------------
38 TargetList(Debugger &debugger);
41 //------------------------------------------------------------------
42 /// Broadcaster event bits definitions.
43 //------------------------------------------------------------------
44 enum { eBroadcastBitInterrupt = (1 << 0) };
46 // These two functions fill out the Broadcaster interface:
48 static ConstString &GetStaticBroadcasterClass();
50 ConstString &GetBroadcasterClass() const override {
51 return GetStaticBroadcasterClass();
54 ~TargetList() override;
56 //------------------------------------------------------------------
57 /// Create a new Target.
59 /// Clients must use this function to create a Target. This allows
60 /// a global list of targets to be maintained in a central location
61 /// so signal handlers and other global functions can use it to
62 /// locate an appropriate target to deliver asynchronous information
65 /// @param[in] debugger
66 /// The debugger to associate this target with
68 /// @param[in] file_spec
69 /// The main executable file for a debug target. This value
70 /// can be nullptr and the file can be set later using:
71 /// Target::SetExecutableModule (ModuleSP&)
73 /// @param[in] triple_cstr
74 /// A target triple string to be used for the target. This can
75 /// be nullptr if the triple is not known or when attaching to a
78 /// @param[in] get_dependent_modules
79 /// Track down the dependent modules for an executable and
80 /// load those into the module list.
82 /// @param[in] platform_options
83 /// A pointer to the platform options to use when creating this
84 /// target. If this value is nullptr, then the currently selected
85 /// platform will be used.
87 /// @param[out] target_sp
88 /// A shared pointer to a target that will be filled in if
89 /// this call is successful.
92 /// An error object that indicates success or failure
93 //------------------------------------------------------------------
94 Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path,
95 llvm::StringRef triple_str, bool get_dependent_modules,
96 const OptionGroupPlatform *platform_options,
97 lldb::TargetSP &target_sp);
99 //------------------------------------------------------------------
100 /// Create a new Target.
102 /// Same as the function above, but used when you already know the
103 /// platform you will be using
104 //------------------------------------------------------------------
105 Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path,
106 const ArchSpec &arch, bool get_dependent_modules,
107 lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp);
109 //------------------------------------------------------------------
110 /// Delete a Target object from the list.
112 /// When clients are done with the Target objects, this function
113 /// should be called to release the memory associated with a target
116 /// @param[in] target_sp
117 /// The shared pointer to a target.
120 /// Returns \b true if the target was successfully removed from
121 /// from this target list, \b false otherwise. The client will
122 /// be left with the last remaining shared pointer to the target
123 /// in \a target_sp which can then be properly released.
124 //------------------------------------------------------------------
125 bool DeleteTarget(lldb::TargetSP &target_sp);
127 int GetNumTargets() const;
129 lldb::TargetSP GetTargetAtIndex(uint32_t index) const;
131 uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const;
133 //------------------------------------------------------------------
134 /// Find the target that contains has an executable whose path
135 /// matches \a exe_file_spec, and whose architecture matches
136 /// \a arch_ptr if arch_ptr is not nullptr.
138 /// @param[in] exe_file_spec
139 /// A file spec containing a basename, or a full path (directory
140 /// and basename). If \a exe_file_spec contains only a filename
141 /// (empty GetDirectory() value) then matching will be done
142 /// solely based on the filenames and directories won't be
143 /// compared. If \a exe_file_spec contains a filename and a
144 /// directory, then both must match.
146 /// @param[in] exe_arch_ptr
147 /// If not nullptr then the architecture also needs to match, else
148 /// the architectures will be compared.
151 /// A shared pointer to a target object. The returned shared
152 /// pointer will contain nullptr if no target objects have a
153 /// executable whose full or partial path matches
154 /// with a matching process ID.
155 //------------------------------------------------------------------
156 lldb::TargetSP FindTargetWithExecutableAndArchitecture(
157 const FileSpec &exe_file_spec,
158 const ArchSpec *exe_arch_ptr = nullptr) const;
160 //------------------------------------------------------------------
161 /// Find the target that contains a process with process ID \a
165 /// The process ID to search our target list for.
168 /// A shared pointer to a target object. The returned shared
169 /// pointer will contain nullptr if no target objects own a process
170 /// with a matching process ID.
171 //------------------------------------------------------------------
172 lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid) const;
174 lldb::TargetSP FindTargetWithProcess(lldb_private::Process *process) const;
176 lldb::TargetSP GetTargetSP(Target *target) const;
178 //------------------------------------------------------------------
179 /// Send an async interrupt to one or all processes.
181 /// Find the target that contains the process with process ID \a
182 /// pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's
186 /// The process ID to search our target list for, if \a pid is
187 /// LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to
191 /// The number of async interrupts sent.
192 //------------------------------------------------------------------
193 uint32_t SendAsyncInterrupt(lldb::pid_t pid = LLDB_INVALID_PROCESS_ID);
195 uint32_t SignalIfRunning(lldb::pid_t pid, int signo);
197 uint32_t SetSelectedTarget(Target *target);
199 lldb::TargetSP GetSelectedTarget();
202 typedef std::vector<lldb::TargetSP> collection;
203 //------------------------------------------------------------------
205 //------------------------------------------------------------------
206 collection m_target_list;
207 lldb::TargetSP m_dummy_target_sp;
208 mutable std::recursive_mutex m_target_list_mutex;
209 uint32_t m_selected_target_idx;
212 lldb::TargetSP GetDummyTarget(lldb_private::Debugger &debugger);
214 Status CreateDummyTarget(Debugger &debugger,
215 llvm::StringRef specified_arch_name,
216 lldb::TargetSP &target_sp);
218 Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path,
219 llvm::StringRef triple_str,
220 bool get_dependent_files,
221 const OptionGroupPlatform *platform_options,
222 lldb::TargetSP &target_sp, bool is_dummy_target);
224 Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path,
225 const ArchSpec &arch, bool get_dependent_modules,
226 lldb::PlatformSP &platform_sp,
227 lldb::TargetSP &target_sp, bool is_dummy_target);
229 DISALLOW_COPY_AND_ASSIGN(TargetList);
232 } // namespace lldb_private
234 #endif // liblldb_TargetList_h_