forked from OSchip/llvm-project
Remove Host::ResolveExecutableLocation (very recent addition); replace use of
it with llvm::sys::Program::FindProgramByName. llvm-svn: 113709
This commit is contained in:
parent
32b3de519d
commit
391a9603a0
lldb
|
@ -259,9 +259,6 @@ public:
|
||||||
static bool
|
static bool
|
||||||
ResolveExecutableInBundle (FileSpec *file);
|
ResolveExecutableInBundle (FileSpec *file);
|
||||||
|
|
||||||
static bool
|
|
||||||
ResolveExecutableLocation (ConstString &directory_name, const ConstString &filename);
|
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids);
|
ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
|
#include "llvm/System/Path.h"
|
||||||
|
#include "llvm/System/Program.h"
|
||||||
|
|
||||||
#include "lldb/Core/FileSpec.h"
|
#include "lldb/Core/FileSpec.h"
|
||||||
#include "lldb/Core/DataBufferHeap.h"
|
#include "lldb/Core/DataBufferHeap.h"
|
||||||
#include "lldb/Core/DataBufferMemoryMap.h"
|
#include "lldb/Core/DataBufferMemoryMap.h"
|
||||||
|
@ -418,7 +422,35 @@ FileSpec::Exists () const
|
||||||
bool
|
bool
|
||||||
FileSpec::ResolveExecutableLocation ()
|
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
|
uint64_t
|
||||||
|
|
|
@ -727,59 +727,3 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue