summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/posix/HostInfoPosix.h3
-rw-r--r--lldb/source/Host/macosx/HostInfoMacOSX.mm12
-rw-r--r--lldb/source/Host/posix/HostInfoPosix.cpp46
3 files changed, 40 insertions, 21 deletions
diff --git a/lldb/include/lldb/Host/posix/HostInfoPosix.h b/lldb/include/lldb/Host/posix/HostInfoPosix.h
index d9901c24c85..6d22776e185 100644
--- a/lldb/include/lldb/Host/posix/HostInfoPosix.h
+++ b/lldb/include/lldb/Host/posix/HostInfoPosix.h
@@ -37,6 +37,9 @@ protected:
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
static bool ComputeHeaderDirectory(FileSpec &file_spec);
static bool ComputePythonDirectory(FileSpec &file_spec);
+ static bool ComputeClangDirectory(FileSpec &file_spec);
+ static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
+ llvm::StringRef dir);
};
}
diff --git a/lldb/source/Host/macosx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/HostInfoMacOSX.mm
index 99979282920..1c526c6eccc 100644
--- a/lldb/source/Host/macosx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/HostInfoMacOSX.mm
@@ -233,11 +233,13 @@ bool HostInfoMacOSX::ComputeClangDirectory(FileSpec &file_spec) {
std::string raw_path = lldb_file_spec.GetPath();
size_t framework_pos = raw_path.find("LLDB.framework");
- if (framework_pos != std::string::npos) {
- framework_pos += strlen("LLDB.framework");
- raw_path.resize(framework_pos);
- raw_path.append("/Resources/Clang");
- }
+ if (framework_pos == std::string::npos)
+ return HostInfoPosix::ComputeClangDirectory(file_spec);
+
+ framework_pos += strlen("LLDB.framework");
+ raw_path.resize(framework_pos);
+ raw_path.append("/Resources/Clang");
+
file_spec.SetFile(raw_path.c_str(), true);
return true;
}
diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp
index 9ff96625cdb..689928cd38f 100644
--- a/lldb/source/Host/posix/HostInfoPosix.cpp
+++ b/lldb/source/Host/posix/HostInfoPosix.cpp
@@ -14,7 +14,11 @@
#include "lldb/Core/Log.h"
#include "lldb/Host/posix/HostInfoPosix.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <grp.h>
@@ -124,44 +128,54 @@ uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh", false); }
-bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
+bool HostInfoPosix::ComputePathRelativeToLibrary(FileSpec &file_spec,
+ llvm::StringRef dir) {
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
return false;
- char raw_path[PATH_MAX];
- lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
+ std::string raw_path = lldb_file_spec.GetPath();
+ // drop library directory
+ llvm::StringRef parent_path = llvm::sys::path::parent_path(raw_path);
// Most Posix systems (e.g. Linux/*BSD) will attempt to replace a */lib with
- // */bin as the base
- // directory for helper exe programs. This will fail if the /lib and /bin
- // directories are
- // rooted in entirely different trees.
+ // */bin as the base directory for helper exe programs. This will fail if the
+ // /lib and /bin directories are rooted in entirely different trees.
if (log)
- log->Printf("HostInfoPosix::ComputeSupportExeDirectory() attempting to "
- "derive the bin path (ePathTypeSupportExecutableDir) from "
- "this path: %s",
- raw_path);
- char *lib_pos = ::strstr(raw_path, "/lib");
- if (lib_pos != nullptr) {
+ log->Printf("HostInfoPosix::ComputePathRelativeToLibrary() attempting to "
+ "derive the %s path from this path: %s",
+ dir.data(), raw_path.c_str());
+
+ if (!parent_path.empty()) {
// Now write in bin in place of lib.
- ::snprintf(lib_pos, PATH_MAX - (lib_pos - raw_path), "/bin");
+ raw_path = (parent_path + dir).str();
if (log)
log->Printf("Host::%s() derived the bin path as: %s", __FUNCTION__,
- raw_path);
+ raw_path.c_str());
} else {
if (log)
log->Printf("Host::%s() failed to find /lib/liblldb within the shared "
"lib path, bailing on bin path construction",
__FUNCTION__);
}
- file_spec.GetDirectory().SetCString(raw_path);
+ file_spec.GetDirectory().SetString(raw_path);
return (bool)file_spec.GetDirectory();
}
+bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
+ return ComputePathRelativeToLibrary(file_spec, "/bin");
+}
+
+bool HostInfoPosix::ComputeClangDirectory(FileSpec &file_spec) {
+ return ComputePathRelativeToLibrary(
+ file_spec, (llvm::Twine("/lib") + CLANG_LIBDIR_SUFFIX + "/clang/" +
+ CLANG_VERSION_STRING)
+ .str());
+}
+
bool HostInfoPosix::ComputeHeaderDirectory(FileSpec &file_spec) {
FileSpec temp_file("/opt/local/include/lldb", false);
file_spec.GetDirectory().SetCString(temp_file.GetPath().c_str());
OpenPOWER on IntegriCloud