[Lldb-commits] [lldb] r355631 - [ExpressionParser] Implement ComputeClangResourceDir for Windows

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 7 12:09:16 PST 2019


Author: xiaobai
Date: Thu Mar  7 12:09:15 2019
New Revision: 355631

URL: http://llvm.org/viewvc/llvm-project?rev=355631&view=rev
Log:
[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

Modified:
    lldb/trunk/include/lldb/Host/HostInfoBase.h
    lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
    lldb/trunk/source/Host/common/HostInfoBase.cpp
    lldb/trunk/source/Host/posix/HostInfoPosix.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h
    lldb/trunk/unittests/Expression/ClangParserTest.cpp

Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostInfoBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostInfoBase.h Thu Mar  7 12:09:15 2019
@@ -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);

Modified: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h (original)
+++ lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h Thu Mar  7 12:09:15 2019
@@ -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:

Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Thu Mar  7 12:09:15 2019
@@ -214,6 +214,38 @@ ArchSpec HostInfoBase::GetAugmentedArchS
   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".

Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Thu Mar  7 12:09:15 2019
@@ -120,43 +120,6 @@ uint32_t HostInfoPosix::GetEffectiveGrou
 
 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");
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp Thu Mar  7 12:09:15 2019
@@ -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 DefaultComputeClangResourceD
     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::ComputeClangResourceD
   return true;
 #endif // __APPLE__
 }
-#endif // _WIN32
 
 FileSpec lldb_private::GetClangResourceDir() {
   static FileSpec g_cached_resource_dir;

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h Thu Mar  7 12:09:15 2019
@@ -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();
 

Modified: lldb/trunk/unittests/Expression/ClangParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Expression/ClangParserTest.cpp?rev=355631&r1=355630&r2=355631&view=diff
==============================================================================
--- lldb/trunk/unittests/Expression/ClangParserTest.cpp (original)
+++ lldb/trunk/unittests/Expression/ClangParserTest.cpp Thu Mar  7 12:09:15 2019
@@ -31,7 +31,6 @@ struct ClangHostTest : public testing::T
 };
 } // 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 ComputeClangResourceD
 }
 
 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




More information about the lldb-commits mailing list