26#include "llvm/ADT/SmallString.h"
27#include "llvm/Support/FileSystem.h"
40 TargetList::GetStaticBroadcasterClass().AsCString()),
41 m_target_list(), m_target_list_mutex(), m_selected_target_idx(0) {
46 llvm::StringRef user_exe_path,
47 llvm::StringRef triple_str,
50 TargetSP &target_sp) {
53 debugger, user_exe_path, triple_str, load_dependent_files,
54 platform_options, target_sp);
56 if (target_sp && result.Success())
62 llvm::StringRef user_exe_path,
65 PlatformSP &platform_sp, TargetSP &target_sp) {
68 debugger, user_exe_path, specified_arch, load_dependent_files,
69 platform_sp, target_sp);
71 if (target_sp && result.Success())
77 Debugger &debugger, llvm::StringRef user_exe_path,
90 if (!triple_str.empty() && !arch.IsValid()) {
91 error.SetErrorStringWithFormat(
"invalid triple '%s'",
92 triple_str.str().c_str());
102 const bool select_platform =
true;
110 bool prefer_platform_arch =
false;
111 auto update_platform_arch = [&](
const ArchSpec &module_arch) {
114 if (!platform_arch.TripleOSWasSpecified() ||
115 !platform_arch.TripleVendorWasSpecified()) {
116 prefer_platform_arch =
true;
117 platform_arch = module_arch;
121 if (!user_exe_path.empty()) {
127 if (platform_sp->IsHost() &&
130 module_spec.GetFileSpec());
140 module_spec.GetFileSpec(), file_offset, file_size, module_specs);
145 if (num_specs == 1) {
147 if (platform_arch.IsValid()) {
148 if (platform_arch.IsCompatibleMatch(
158 platform_arch.DumpTriple(platform_arch_strm.
AsRawOstream());
161 error.SetErrorStringWithFormat(
162 "the specified architecture '%s' is not compatible with '%s' "
165 module_spec.GetFileSpec().GetPath().c_str());
170 prefer_platform_arch =
true;
174 }
else if (arch.IsValid()) {
176 module_spec.GetArchitecture() = arch;
178 matching_module_spec))
183 std::vector<PlatformSP> candidates;
184 std::vector<ArchSpec> archs;
186 archs.push_back(spec.GetArchitecture());
187 if (PlatformSP platform_for_archs_sp =
188 platform_list.
GetOrCreate(archs, {}, candidates)) {
189 platform_sp = platform_for_archs_sp;
190 }
else if (candidates.empty()) {
191 error.SetErrorString(
"no matching platforms found for this file");
196 std::set<llvm::StringRef> platform_set;
198 "more than one platform supports this executable (");
199 for (
const auto &candidate : candidates) {
200 llvm::StringRef platform_name = candidate->GetName();
201 if (platform_set.count(platform_name))
203 if (!platform_set.empty())
206 platform_set.insert(platform_name);
208 error_strm.
Printf(
"), specify an architecture to disambiguate");
218 if (!prefer_platform_arch && arch.IsValid()) {
219 if (!platform_sp->IsCompatibleArchitecture(
221 platform_sp = platform_list.
GetOrCreate(arch, {}, &platform_arch);
225 }
else if (platform_arch.IsValid()) {
229 if (!platform_sp->IsCompatibleArchitecture(
232 platform_list.
GetOrCreate(platform_arch, {}, &fixed_platform_arch);
238 if (!platform_arch.IsValid())
239 platform_arch = arch;
242 platform_arch, load_dependent_files,
243 platform_sp, target_sp);
247 llvm::StringRef user_exe_path,
250 lldb::PlatformSP &platform_sp,
251 lldb::TargetSP &target_sp) {
253 user_exe_path.str().c_str(),
256 const bool is_dummy_target =
false;
261 if (!platform_sp || !platform_sp->IsCompatibleArchitecture(
271 arch = specified_arch;
277 llvm::SmallString<64> unglobbed_path;
281 if (unglobbed_path.empty())
284 file =
FileSpec(unglobbed_path.c_str());
287 bool user_exe_path_is_bundle =
false;
288 char resolved_bundle_exe_path[
PATH_MAX];
289 resolved_bundle_exe_path[0] =
'\0';
292 user_exe_path_is_bundle =
true;
294 if (file.
IsRelative() && !user_exe_path.empty()) {
295 llvm::SmallString<64> cwd;
296 if (! llvm::sys::fs::current_path(cwd)) {
304 ModuleSP exe_module_sp;
309 error = platform_sp->ResolveExecutable(module_spec, exe_module_sp,
310 executable_search_paths.
GetSize()
311 ? &executable_search_paths
315 if (
error.Success() && exe_module_sp) {
316 if (exe_module_sp->GetObjectFile() ==
nullptr) {
318 error.SetErrorStringWithFormat(
319 "\"%s\" doesn't contain architecture %s", file.
GetPath().c_str(),
322 error.SetErrorStringWithFormat(
"unsupported file type \"%s\"",
327 target_sp.reset(
new Target(debugger, arch, platform_sp, is_dummy_target));
328 target_sp->SetExecutableModule(exe_module_sp, load_dependent_files);
329 if (user_exe_path_is_bundle)
330 exe_module_sp->GetFileSpec().GetPath(resolved_bundle_exe_path,
331 sizeof(resolved_bundle_exe_path));
332 if (target_sp->GetPreloadSymbols())
333 exe_module_sp->PreloadSymbols();
338 target_sp.reset(
new Target(debugger, arch, platform_sp, is_dummy_target));
347 if (!user_exe_path.empty()) {
350 if (user_exe_path_is_bundle && resolved_bundle_exe_path[0]) {
351 target_sp->SetArg0(resolved_bundle_exe_path);
354 target_sp->SetArg0(file.
GetPath().c_str());
360 target_sp->AppendExecutableSearchPaths(file_dir);
383 [&exe_file_spec, exe_arch_ptr](
const TargetSP &item) {
384 Module *exe_module = item->GetExecutableModulePointer();
386 !FileSpec::Match(exe_file_spec, exe_module->GetFileSpec()))
389 return !exe_arch_ptr ||
390 exe_arch_ptr->IsCompatibleMatch(exe_module->GetArchitecture());
402 [pid](
const TargetSP &item) {
403 auto *process_ptr = item->GetProcessSP().get();
404 return process_ptr && (process_ptr->GetID() == pid);
420 [process](
const TargetSP &item) {
421 return item->GetProcessSP().get() == process;
437 [target](
const TargetSP &item) { return item.get() == target; });
445 uint32_t num_async_interrupts_sent = 0;
450 Process *process = target_sp->GetProcessSP().get();
453 ++num_async_interrupts_sent;
462 return num_async_interrupts_sent;
472 process = target_sp->GetProcessSP().get();
473 if (process && process->
IsAlive()) {
482 process = target_sp->GetProcessSP().get();
483 if (process && process->
IsAlive()) {
489 return num_signals_sent;
515 "target already exists it the list");
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_SCOPED_TIMERF(...)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
void DumpTriple(llvm::raw_ostream &s) const
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
An event broadcasting class.
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
void CheckInWithManager()
A uniqued constant string class.
A class to manage flag bits.
CommandInterpreter & GetCommandInterpreter()
PlatformList & GetPlatformList()
Target & GetDummyTarget()
size_t GetSize() const
Get the number of files in the file list.
void AppendPathComponent(llvm::StringRef component)
void SetDirectory(ConstString directory)
Directory string set accessor.
bool IsRelative() const
Returns true if the filespec represents a relative path.
const ConstString & GetDirectory() const
Directory string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
static bool ResolveExecutableInBundle(FileSpec &file)
When executable files may live within a directory, where the directory represents an executable bundl...
ModuleSpecIterable ModuleSpecs()
bool GetModuleSpecAtIndex(size_t i, ModuleSpec &module_spec) const
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
ArchSpec & GetArchitecture()
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
A plug-in interface definition class for debugging a process.
void SendAsyncInterrupt()
Status Signal(int signal)
Sends a process a UNIX signal signal.
virtual bool IsAlive()
Check if a process is still alive.
const char * GetData() const
llvm::StringRef GetString() const
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void SetSelectedTargetInternal(uint32_t index)
lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid) const
Find the target that contains a process with process ID pid.
lldb::TargetSP GetTargetAtIndex(uint32_t index) const
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.
TargetList(Debugger &debugger)
Constructor.
std::recursive_mutex m_target_list_mutex
uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const
lldb::TargetSP GetTargetSP(Target *target) const
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
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)
lldb::TargetSP GetSelectedTarget()
void AddTargetInternal(lldb::TargetSP target_sp, bool do_select)
static ConstString & GetStaticBroadcasterClass()
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...
uint32_t m_selected_target_idx
static FileSpecList GetDefaultExecutableSearchPaths()
bool ResolveFullPath(llvm::StringRef Expr, llvm::SmallVectorImpl< char > &Output)
Resolve an entire path that begins with a tilde expression, replacing the username portion with the m...
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.