LLDB mainline
TargetList.h
Go to the documentation of this file.
1//===-- TargetList.h --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_TARGET_TARGETLIST_H
10#define LLDB_TARGET_TARGETLIST_H
11
12#include <mutex>
13#include <vector>
14
15#include "lldb/Target/Target.h"
18
19namespace lldb_private {
20
21class TargetList : public Broadcaster {
22private:
23 friend class Debugger;
24
25 /// Constructor
26 ///
27 /// The constructor for the target list is private. Clients can
28 /// get ahold of the one and only target list through the
29 /// lldb_private::Debugger::GetSharedInstance().GetTargetList().
30 ///
31 /// \see static TargetList& lldb_private::Debugger::GetTargetList().
32 TargetList(Debugger &debugger);
33
34public:
35 /// Broadcaster event bits definitions.
36 enum { eBroadcastBitInterrupt = (1 << 0) };
37
38 // These two functions fill out the Broadcaster interface:
39
40 static llvm::StringRef GetStaticBroadcasterClass();
41
42 llvm::StringRef GetBroadcasterClass() const override {
44 }
45
46 typedef std::vector<lldb::TargetSP> collection;
49
50 /// Create a new Target.
51 ///
52 /// Clients must use this function to create a Target. This allows
53 /// a global list of targets to be maintained in a central location
54 /// so signal handlers and other global functions can use it to
55 /// locate an appropriate target to deliver asynchronous information
56 /// to.
57 ///
58 /// \param[in] debugger
59 /// The debugger to associate this target with
60 ///
61 /// \param[in] user_exe_path
62 /// The main executable file for a debug target. This value
63 /// can be empty and the file can be set later using:
64 /// Target::SetExecutableModule (ModuleSP&)
65 ///
66 /// \param[in] triple_str
67 /// A target triple string to be used for the target. This can
68 /// be nullptr if the triple is not known or when attaching to a
69 /// process.
70 ///
71 /// \param[in] get_dependent_modules
72 /// Track down the dependent modules for an executable and
73 /// load those into the module list.
74 ///
75 /// \param[in] platform_options
76 /// A pointer to the platform options to use when creating this
77 /// target. If this value is nullptr, then the currently selected
78 /// platform will be used.
79 ///
80 /// \param[out] target_sp
81 /// A shared pointer to a target that will be filled in if
82 /// this call is successful.
83 ///
84 /// \return
85 /// An error object that indicates success or failure
86 Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path,
87 llvm::StringRef triple_str,
88 LoadDependentFiles get_dependent_modules,
89 const OptionGroupPlatform *platform_options,
90 lldb::TargetSP &target_sp);
91
92 /// Create a new Target.
93 ///
94 /// Same as the function above, but used when you already know the
95 /// platform you will be using
96 Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path,
97 const ArchSpec &arch,
98 LoadDependentFiles get_dependent_modules,
99 lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp);
100
101 /// Delete a Target object from the list.
102 ///
103 /// When clients are done with the Target objects, this function
104 /// should be called to release the memory associated with a target
105 /// object.
106 ///
107 /// \param[in] target_sp
108 /// The shared pointer to a target.
109 ///
110 /// \return
111 /// Returns \b true if the target was successfully removed from
112 /// from this target list, \b false otherwise. The client will
113 /// be left with the last remaining shared pointer to the target
114 /// in \a target_sp which can then be properly released.
115 bool DeleteTarget(lldb::TargetSP &target_sp);
116
117 size_t GetNumTargets() const;
118
119 lldb::TargetSP GetTargetAtIndex(uint32_t index) const;
120
121 uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const;
122
123 /// Find the target that contains has an executable whose path
124 /// matches \a exe_file_spec, and whose architecture matches
125 /// \a arch_ptr if arch_ptr is not nullptr.
126 ///
127 /// \param[in] exe_file_spec
128 /// A file spec containing a basename, or a full path (directory
129 /// and basename). If \a exe_file_spec contains only a filename
130 /// (empty GetDirectory() value) then matching will be done
131 /// solely based on the filenames and directories won't be
132 /// compared. If \a exe_file_spec contains a filename and a
133 /// directory, then both must match.
134 ///
135 /// \param[in] exe_arch_ptr
136 /// If not nullptr then the architecture also needs to match, else
137 /// the architectures will be compared.
138 ///
139 /// \return
140 /// A shared pointer to a target object. The returned shared
141 /// pointer will contain nullptr if no target objects have a
142 /// executable whose full or partial path matches
143 /// with a matching process ID.
145 const FileSpec &exe_file_spec,
146 const ArchSpec *exe_arch_ptr = nullptr) const;
147
148 /// Find the target that contains a process with process ID \a
149 /// pid.
150 ///
151 /// \param[in] pid
152 /// The process ID to search our target list for.
153 ///
154 /// \return
155 /// A shared pointer to a target object. The returned shared
156 /// pointer will contain nullptr if no target objects own a process
157 /// with a matching process ID.
159
161
162 lldb::TargetSP GetTargetSP(Target *target) const;
163
164 /// Send an async interrupt to one or all processes.
165 ///
166 /// Find the target that contains the process with process ID \a
167 /// pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's
168 /// event queue.
169 ///
170 /// \param[in] pid
171 /// The process ID to search our target list for, if \a pid is
172 /// LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to
173 /// all processes.
174 ///
175 /// \return
176 /// The number of async interrupts sent.
178
179 uint32_t SignalIfRunning(lldb::pid_t pid, int signo);
180
181 void SetSelectedTarget(uint32_t index);
182
183 void SetSelectedTarget(const lldb::TargetSP &target);
184
186
187 /// Returns whether any module, including ones in the process of being
188 /// added, contains this module. I don't want to give direct access to
189 /// these not yet added target, but for interruption purposes, we might
190 /// need to ask whether this target contains this module.
191 bool AnyTargetContainsModule(Module &module);
192
196
197private:
199 std::unordered_set<lldb::TargetSP> m_in_process_target_list;
200 mutable std::recursive_mutex m_target_list_mutex;
202
204 Debugger &debugger, llvm::StringRef user_exe_path,
205 llvm::StringRef triple_str, LoadDependentFiles load_dependent_files,
206 const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp);
207
208 static Status CreateTargetInternal(Debugger &debugger,
209 llvm::StringRef user_exe_path,
210 const ArchSpec &arch,
211 LoadDependentFiles get_dependent_modules,
212 lldb::PlatformSP &platform_sp,
213 lldb::TargetSP &target_sp);
214
216
218
219 bool IsTargetInProcess(lldb::TargetSP target_sp);
220
221 void AddTargetInternal(lldb::TargetSP target_sp, bool do_select);
222
223 void SetSelectedTargetInternal(uint32_t index);
224
225 TargetList(const TargetList &) = delete;
226 const TargetList &operator=(const TargetList &) = delete;
227};
228
229} // namespace lldb_private
230
231#endif // LLDB_TARGET_TARGETLIST_H
An architecture specification class.
Definition ArchSpec.h:31
Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name)
Construct with a broadcaster with a name.
A file utility class.
Definition FileSpec.h:57
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
A plug-in interface definition class for debugging a process.
Definition Process.h:357
An error handling class.
Definition Status.h:118
void SetSelectedTargetInternal(uint32_t index)
static llvm::StringRef GetStaticBroadcasterClass()
lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid) const
Find the target that contains a process with process ID pid.
bool IsTargetInProcess(lldb::TargetSP target_sp)
lldb::TargetSP GetTargetAtIndex(uint32_t index) const
std::vector< lldb::TargetSP > collection
Definition TargetList.h:46
TargetList(const TargetList &)=delete
TargetIterable Targets()
Definition TargetList.h:193
TargetList(Debugger &debugger)
Constructor.
std::recursive_mutex m_target_list_mutex
Definition TargetList.h:200
uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const
lldb::TargetSP GetTargetSP(Target *target) const
void UnregisterInProcessTarget(lldb::TargetSP target_sp)
void SetSelectedTarget(uint32_t index)
uint32_t SendAsyncInterrupt(lldb::pid_t pid=LLDB_INVALID_PROCESS_ID)
Send an async interrupt to one or all processes.
bool DeleteTarget(lldb::TargetSP &target_sp)
Delete a Target object from the list.
lldb::TargetSP FindTargetWithProcess(lldb_private::Process *process) const
llvm::StringRef GetBroadcasterClass() const override
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
Definition TargetList.h:42
void RegisterInProcessTarget(lldb::TargetSP target_sp)
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
lldb::TargetSP GetSelectedTarget()
void AddTargetInternal(lldb::TargetSP target_sp, bool do_select)
static Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles load_dependent_files, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
bool AnyTargetContainsModule(Module &module)
Returns whether any module, including ones in the process of being added, contains this module.
size_t GetNumTargets() const
uint32_t SignalIfRunning(lldb::pid_t pid, int signo)
lldb::TargetSP FindTargetWithExecutableAndArchitecture(const FileSpec &exe_file_spec, const ArchSpec *exe_arch_ptr=nullptr) const
Find the target that contains has an executable whose path matches exe_file_spec, and whose architect...
const TargetList & operator=(const TargetList &)=delete
std::unordered_set< lldb::TargetSP > m_in_process_target_list
Definition TargetList.h:199
LockingAdaptedIterable< std::recursive_mutex, collection > TargetIterable
Definition TargetList.h:48
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Platform > PlatformSP
uint64_t pid_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Target > TargetSP