From 53954b5e128709833ad0123839ce96e26e2fc98d Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Thu, 7 Mar 2019 20:09:15 +0000 Subject: [PATCH] [ExpressionParser] Implement ComputeClangResourceDir for Windows Summary: This function is useful for expression evaluation, especially when doing swift debugging on windows. Reviewers: aprantl, labath Reviewed By: labath Subscribers: teemperor, jdoerfert, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D59072 llvm-svn: 355631 --- lldb/include/lldb/Host/HostInfoBase.h | 3 ++ lldb/include/lldb/Host/posix/HostInfoPosix.h | 3 -- lldb/source/Host/common/HostInfoBase.cpp | 32 +++++++++++++++++++ lldb/source/Host/posix/HostInfoPosix.cpp | 37 ---------------------- .../Plugins/ExpressionParser/Clang/ClangHost.cpp | 12 +------ .../Plugins/ExpressionParser/Clang/ClangHost.h | 2 -- lldb/unittests/Expression/ClangParserTest.cpp | 7 ++-- 7 files changed, 41 insertions(+), 55 deletions(-) diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h index f322012..569b398 100644 --- a/lldb/include/lldb/Host/HostInfoBase.h +++ b/lldb/include/lldb/Host/HostInfoBase.h @@ -99,6 +99,9 @@ public: //--------------------------------------------------------------------------- static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple); + static bool ComputePathRelativeToLibrary(FileSpec &file_spec, + llvm::StringRef dir); + protected: static bool ComputeSharedLibraryDirectory(FileSpec &file_spec); static bool ComputeSupportExeDirectory(FileSpec &file_spec); diff --git a/lldb/include/lldb/Host/posix/HostInfoPosix.h b/lldb/include/lldb/Host/posix/HostInfoPosix.h index a3fbe49..2691013 100644 --- a/lldb/include/lldb/Host/posix/HostInfoPosix.h +++ b/lldb/include/lldb/Host/posix/HostInfoPosix.h @@ -32,9 +32,6 @@ public: static bool GetEnvironmentVar(const std::string &var_name, std::string &var); - static bool ComputePathRelativeToLibrary(FileSpec &file_spec, - llvm::StringRef dir); - static UserIDResolver &GetUserIDResolver(); protected: diff --git a/lldb/source/Host/common/HostInfoBase.cpp b/lldb/source/Host/common/HostInfoBase.cpp index 04604c8..388f767 100644 --- a/lldb/source/Host/common/HostInfoBase.cpp +++ b/lldb/source/Host/common/HostInfoBase.cpp @@ -214,6 +214,38 @@ ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) { return ArchSpec(normalized_triple); } +bool HostInfoBase::ComputePathRelativeToLibrary(FileSpec &file_spec, + llvm::StringRef dir) { + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); + + FileSpec lldb_file_spec = GetShlibDir(); + if (!lldb_file_spec) + return false; + + std::string raw_path = lldb_file_spec.GetPath(); + if (log) + log->Printf("HostInfo::%s() attempting to " + "derive the path %s relative to liblldb install path: %s", + __FUNCTION__, dir.data(), raw_path.c_str()); + + // Drop bin (windows) or lib + llvm::StringRef parent_path = llvm::sys::path::parent_path(raw_path); + if (parent_path.empty()) { + if (log) + log->Printf("HostInfo::%s() failed to find liblldb within the shared " + "lib path", + __FUNCTION__); + return false; + } + + raw_path = (parent_path + dir).str(); + if (log) + log->Printf("HostInfo::%s() derived the path as: %s", __FUNCTION__, + raw_path.c_str()); + file_spec.GetDirectory().SetString(raw_path); + return (bool)file_spec.GetDirectory(); +} + bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) { // To get paths related to LLDB we get the path to the executable that // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB". diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp index 6e4208dd..f300e22 100644 --- a/lldb/source/Host/posix/HostInfoPosix.cpp +++ b/lldb/source/Host/posix/HostInfoPosix.cpp @@ -120,43 +120,6 @@ uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); } FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); } -bool HostInfoPosix::ComputePathRelativeToLibrary(FileSpec &file_spec, - llvm::StringRef dir) { - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); - - FileSpec lldb_file_spec = GetShlibDir(); - if (!lldb_file_spec) - return false; - - 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. - if (log) - 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. - raw_path = (parent_path + dir).str(); - - if (log) - log->Printf("Host::%s() derived the bin path as: %s", __FUNCTION__, - 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().SetString(raw_path); - return (bool)file_spec.GetDirectory(); -} - bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) { return ComputePathRelativeToLibrary(file_spec, "/bin"); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp index b27a749..ce0b630 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp @@ -18,9 +18,6 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" -#if !defined(_WIN32) -#include "lldb/Host/posix/HostInfoPosix.h" -#endif #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Log.h" @@ -28,12 +25,6 @@ using namespace lldb_private; -#if defined(_WIN32) -static bool ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, - FileSpec &file_spec, bool verify) { - return false; -} -#else static bool VerifyClangPath(const llvm::Twine &clang_path) { if (FileSystem::Instance().IsDirectory(clang_path)) return true; @@ -67,7 +58,7 @@ static bool DefaultComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, return true; } - return HostInfoPosix::ComputePathRelativeToLibrary(file_spec, relative_path); + return HostInfo::ComputePathRelativeToLibrary(file_spec, relative_path); } bool lldb_private::ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, @@ -141,7 +132,6 @@ bool lldb_private::ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, return true; #endif // __APPLE__ } -#endif // _WIN32 FileSpec lldb_private::GetClangResourceDir() { static FileSpec g_cached_resource_dir; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h index 2482d63..9d49188 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h @@ -13,10 +13,8 @@ namespace lldb_private { class FileSpec; -#if !defined(_WIN32) bool ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, FileSpec &file_spec, bool verify); -#endif FileSpec GetClangResourceDir(); diff --git a/lldb/unittests/Expression/ClangParserTest.cpp b/lldb/unittests/Expression/ClangParserTest.cpp index 5aeb871..753d14b 100644 --- a/lldb/unittests/Expression/ClangParserTest.cpp +++ b/lldb/unittests/Expression/ClangParserTest.cpp @@ -31,7 +31,6 @@ struct ClangHostTest : public testing::Test { }; } // namespace -#if !defined(_WIN32) static std::string ComputeClangResourceDir(std::string lldb_shlib_path, bool verify = false) { FileSpec clang_dir; @@ -41,8 +40,13 @@ static std::string ComputeClangResourceDir(std::string lldb_shlib_path, } TEST_F(ClangHostTest, ComputeClangResourceDirectory) { +#if !defined(_WIN32) std::string path_to_liblldb = "/foo/bar/lib/"; std::string path_to_clang_dir = "/foo/bar/lib/clang/" CLANG_VERSION_STRING; +#else + std::string path_to_liblldb = "C:\\foo\\bar\\lib"; + std::string path_to_clang_dir = "C:\\foo\\bar\\lib\\clang\\" CLANG_VERSION_STRING; +#endif EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb), path_to_clang_dir); // The path doesn't really exist, so setting verify to true should make @@ -91,4 +95,3 @@ TEST_F(ClangHostTest, MacOSX) { ComputeClangResourceDir(GetInputFilePath(xcode))); } #endif // __APPLE__ -#endif // !_WIN32 -- 2.7.4