diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBFileSpec.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Host/common/FileSystem.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Host/common/MonitoringProcessLauncher.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Host/macosx/objcxx/Host.mm | 5 | ||||
-rw-r--r-- | lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Target/ProcessLaunchInfo.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Utility/FileSpec.cpp | 36 |
8 files changed, 47 insertions, 43 deletions
diff --git a/lldb/source/API/SBFileSpec.cpp b/lldb/source/API/SBFileSpec.cpp index 011b88225ef..027528c46ca 100644 --- a/lldb/source/API/SBFileSpec.cpp +++ b/lldb/source/API/SBFileSpec.cpp @@ -12,6 +12,7 @@ #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBStream.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Host/PosixApi.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Log.h" @@ -61,7 +62,7 @@ bool SBFileSpec::Exists() const { } bool SBFileSpec::ResolveExecutableLocation() { - return m_opaque_ap->ResolveExecutableLocation(); + return FileSystem::Instance().ResolveExecutableLocation(*m_opaque_ap); } int SBFileSpec::ResolvePath(const char *src_path, char *dst_path, diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index 5f8d8fb4282..c5f4db6128c 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -13,6 +13,8 @@ #include "lldb/Utility/TildeExpressionResolver.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Program.h" #include "llvm/Support/Threading.h" #include <algorithm> @@ -178,3 +180,36 @@ void FileSystem::Resolve(FileSpec &file_spec) { // Update the FileSpec with the resolved path. file_spec.SetPath(path); } + +bool FileSystem::ResolveExecutableLocation(FileSpec &file_spec) { + // If the directory is set there's nothing to do. + const ConstString &directory = file_spec.GetDirectory(); + if (directory) + return false; + + // We cannot look for a file if there's no file name. + const ConstString &filename = file_spec.GetFilename(); + if (!filename) + return false; + + // Search for the file on the host. + const std::string filename_str(filename.GetCString()); + llvm::ErrorOr<std::string> error_or_path = + llvm::sys::findProgramByName(filename_str); + if (!error_or_path) + return false; + + // findProgramByName returns "." if it can't find the file. + llvm::StringRef path = *error_or_path; + llvm::StringRef parent = llvm::sys::path::parent_path(path); + if (parent.empty() || parent == ".") + return false; + + // Make sure that the result exists. + FileSpec result(*error_or_path, false); + if (!Exists(result)) + return false; + + file_spec = result; + return true; +} diff --git a/lldb/source/Host/common/MonitoringProcessLauncher.cpp b/lldb/source/Host/common/MonitoringProcessLauncher.cpp index 76c11454f57..bdded150e7b 100644 --- a/lldb/source/Host/common/MonitoringProcessLauncher.cpp +++ b/lldb/source/Host/common/MonitoringProcessLauncher.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/MonitoringProcessLauncher.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Host/HostProcess.h" #include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Utility/Log.h" @@ -38,7 +39,7 @@ MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info, status(exe_spec.GetPath(), stats); } if (!exists(stats)) { - exe_spec.ResolveExecutableLocation(); + FileSystem::Instance().ResolveExecutableLocation(exe_spec); status(exe_spec.GetPath(), stats); } diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm index a70bf0421ec..c113a17f20f 100644 --- a/lldb/source/Host/macosx/objcxx/Host.mm +++ b/lldb/source/Host/macosx/objcxx/Host.mm @@ -55,10 +55,11 @@ #include <unistd.h> #include "lldb/Host/ConnectionFileDescriptor.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/ThreadLauncher.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/Process.h" +#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/CleanUp.h" #include "lldb/Utility/DataBufferHeap.h" @@ -1282,7 +1283,7 @@ Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) { status(exe_spec.GetPath(), stats); } if (!exists(stats)) { - exe_spec.ResolveExecutableLocation(); + FileSystem::Instance().ResolveExecutableLocation(exe_spec); status(exe_spec.GetPath(), stats); } if (!exists(stats)) { diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index 0016a5cd558..996bd2671da 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -135,7 +135,8 @@ PlatformPOSIX::ResolveExecutable(const ModuleSpec &module_spec, } if (!resolved_module_spec.GetFileSpec().Exists()) - resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); + FileSystem::Instance().ResolveExecutableLocation( + resolved_module_spec.GetFileSpec()); // Resolve any executable within a bundle on MacOSX Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index fd1a4022b65..a4e590e2053 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -199,7 +199,8 @@ Status PlatformWindows::ResolveExecutable( } if (!resolved_module_spec.GetFileSpec().Exists()) - resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); + FileSystem::Instance().ResolveExecutableLocation( + resolved_module_spec.GetFileSpec()); if (resolved_module_spec.GetFileSpec().Exists()) error.Clear(); diff --git a/lldb/source/Target/ProcessLaunchInfo.cpp b/lldb/source/Target/ProcessLaunchInfo.cpp index 9569750bc5f..b0153ece80d 100644 --- a/lldb/source/Target/ProcessLaunchInfo.cpp +++ b/lldb/source/Target/ProcessLaunchInfo.cpp @@ -151,7 +151,7 @@ const FileSpec &ProcessLaunchInfo::GetShell() const { return m_shell; } void ProcessLaunchInfo::SetShell(const FileSpec &shell) { m_shell = shell; if (m_shell) { - m_shell.ResolveExecutableLocation(); + FileSystem::Instance().ResolveExecutableLocation(m_shell); m_flags.Set(lldb::eLaunchFlagLaunchInShell); } else m_flags.Clear(lldb::eLaunchFlagLaunchInShell); diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index c41a0643742..c0dfea36ee3 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -458,42 +458,6 @@ void FileSpec::Dump(Stream *s) const { //------------------------------------------------------------------ bool FileSpec::Exists() const { return llvm::sys::fs::exists(GetPath()); } -bool FileSpec::ResolveExecutableLocation() { - // CLEANUP: Use StringRef for string handling. - if (!m_directory) { - const char *file_cstr = m_filename.GetCString(); - if (file_cstr) { - const std::string file_str(file_cstr); - llvm::ErrorOr<std::string> error_or_path = - llvm::sys::findProgramByName(file_str); - if (!error_or_path) - return false; - std::string path = error_or_path.get(); - llvm::StringRef dir_ref = llvm::sys::path::parent_path(path); - if (!dir_ref.empty()) { - // FindProgramByName returns "." if it can't find the file. - if (strcmp(".", dir_ref.data()) == 0) - return false; - - m_directory.SetCString(dir_ref.data()); - if (Exists()) - return true; - else { - // If FindProgramByName found the file, it returns the directory + - // filename in its return results. We need to separate them. - FileSpec tmp_file(dir_ref.data(), false); - if (tmp_file.Exists()) { - m_directory = tmp_file.m_directory; - return true; - } - } - } - } - } - - return false; -} - bool FileSpec::ResolvePath() { if (m_is_resolved) return true; // We have already resolved this path |