From 391a9603a098d0f892135362650c72487b178d61 Mon Sep 17 00:00:00 2001 From: Caroline Tice Date: Sun, 12 Sep 2010 00:10:52 +0000 Subject: [PATCH] Remove Host::ResolveExecutableLocation (very recent addition); replace use of it with llvm::sys::Program::FindProgramByName. llvm-svn: 113709 --- lldb/include/lldb/Host/Host.h | 3 -- lldb/source/Core/FileSpec.cpp | 34 ++++++++++++++++++- lldb/source/Host/common/Host.cpp | 56 -------------------------------- 3 files changed, 33 insertions(+), 60 deletions(-) diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h index 6f8a4e4a08b7..20c83038aec7 100644 --- a/lldb/include/lldb/Host/Host.h +++ b/lldb/include/lldb/Host/Host.h @@ -259,9 +259,6 @@ public: static bool ResolveExecutableInBundle (FileSpec *file); - static bool - ResolveExecutableLocation (ConstString &directory_name, const ConstString &filename); - static uint32_t ListProcessesMatchingName (const char *name, StringList &matches, std::vector &pids); diff --git a/lldb/source/Core/FileSpec.cpp b/lldb/source/Core/FileSpec.cpp index b4aea9c888aa..fc197ad24122 100644 --- a/lldb/source/Core/FileSpec.cpp +++ b/lldb/source/Core/FileSpec.cpp @@ -18,6 +18,10 @@ #include +#include "llvm/ADT/StringRef.h" +#include "llvm/System/Path.h" +#include "llvm/System/Program.h" + #include "lldb/Core/FileSpec.h" #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/DataBufferMemoryMap.h" @@ -418,7 +422,35 @@ FileSpec::Exists () const bool FileSpec::ResolveExecutableLocation () { - return Host::ResolveExecutableLocation (m_directory, m_filename); + if (m_directory.GetLength() == 0) + { + const std::string file_str (m_filename.AsCString()); + llvm::sys::Path path = llvm::sys::Program::FindProgramByName (file_str); + llvm::StringRef dir_ref = path.getDirname(); + 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()); + if (tmp_file.Exists()) + { + m_directory = tmp_file.m_directory; + return true; + } + } + } + } + + return false; } uint64_t diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index f0d476532215..00ba8468c7cd 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -727,59 +727,3 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no) return false; } #endif - -bool -Host::ResolveExecutableLocation (ConstString &directory_name, const ConstString &filename) -{ - // If the user specified just a plain filename, there may be additional ways to find the - // file, such as searching the PATH environment variable on UNIX systems. This is the location - // to implement such additional searches. - - // For now the only search we are implementing is search $PATH, which makes no sense if - // the user already specified a directory. - - if (directory_name.GetLength() > 0) - return false; - - std::string search_path (getenv ("PATH")); - char dir_separator = ':'; - - bool done = false; - bool found = false; - size_t start = 0; - while (!done && !found) - { - size_t end = search_path.find (dir_separator, start); - size_t length; - if (end == std::string::npos) - { - done = true; - length = search_path.length() - start; - } - else - length = end - start; - - std::string directory_str = search_path.substr (start, length); - - if (directory_str.length() > 0) - { - StreamString tmp_full_path_name; - if (directory_str[directory_str.length()-1] == '/') - tmp_full_path_name.Printf ("%s%s", directory_str.c_str(), filename.AsCString()); - else - tmp_full_path_name.Printf ("%s/%s", directory_str.c_str(), filename.AsCString()); - - struct stat sb; - - if (::stat (tmp_full_path_name.GetData(), &sb) == 0) - { - found = true; - directory_name.SetCString (directory_str.c_str()); - } - } - - if (!done) - start = end + 1; - } - return found; -} -- GitLab