summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common/FileSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/common/FileSystem.cpp')
-rw-r--r--lldb/source/Host/common/FileSystem.cpp35
1 files changed, 35 insertions, 0 deletions
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;
+}
OpenPOWER on IntegriCloud