From 416295cd42fd15116fad13dab209418464a57d5f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 21 Jun 2024 15:00:40 -0700 Subject: [PATCH] [lldb] Resolve executables more aggressively on the host When unifying the ResolveExecutable implementations in #96256, I missed that RemoteAwarePlatform was able to resolve executables more aggressively. The host platform can rely on the current working directory to make relative paths absolute and resolve things like home directories. This should fix command-target-create-resolve-exe.test. --- .../include/lldb/Target/RemoteAwarePlatform.h | 5 ++++ lldb/source/Target/RemoteAwarePlatform.cpp | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lldb/include/lldb/Target/RemoteAwarePlatform.h b/lldb/include/lldb/Target/RemoteAwarePlatform.h index 6fbeec7888a98..fb2eecfaa23a8 100644 --- a/lldb/include/lldb/Target/RemoteAwarePlatform.h +++ b/lldb/include/lldb/Target/RemoteAwarePlatform.h @@ -20,6 +20,11 @@ class RemoteAwarePlatform : public Platform { public: using Platform::Platform; + virtual Status + ResolveExecutable(const ModuleSpec &module_spec, + lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr) override; + bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override; diff --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp index 63243d6e71307..5fc2d63876b92 100644 --- a/lldb/source/Target/RemoteAwarePlatform.cpp +++ b/lldb/source/Target/RemoteAwarePlatform.cpp @@ -29,6 +29,29 @@ bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec, return false; } +Status RemoteAwarePlatform::ResolveExecutable( + const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr) { + ModuleSpec resolved_module_spec(module_spec); + + // The host platform can resolve the path more aggressively. + if (IsHost()) { + FileSpec &resolved_file_spec = resolved_module_spec.GetFileSpec(); + + if (!FileSystem::Instance().Exists(resolved_file_spec)) { + resolved_module_spec.GetFileSpec().SetFile(resolved_file_spec.GetPath(), + FileSpec::Style::native); + FileSystem::Instance().Resolve(resolved_file_spec); + } + + if (!FileSystem::Instance().Exists(resolved_file_spec)) + FileSystem::Instance().ResolveExecutableLocation(resolved_file_spec); + } + + return Platform::ResolveExecutable(resolved_module_spec, exe_module_sp, + module_search_paths_ptr); +} + Status RemoteAwarePlatform::RunShellCommand( llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output,