[Lldb-commits] [PATCH] D59708: [ExpressionParser] Add swift-lldb case for finding clang resource dir

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 25 12:53:17 PDT 2019


xiaobai updated this revision to Diff 192185.
xiaobai added a comment.
Herald added a subscriber: jdoerfert.

- Respect LIBDIR for swift-lldb case
- Loop over a list of known directory suffixes
- Change default behavior to not set file_spec and return false upon failure.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59708/new/

https://reviews.llvm.org/D59708

Files:
  source/Plugins/ExpressionParser/Clang/ClangHost.cpp
  unittests/Expression/ClangParserTest.cpp


Index: unittests/Expression/ClangParserTest.cpp
===================================================================
--- unittests/Expression/ClangParserTest.cpp
+++ unittests/Expression/ClangParserTest.cpp
@@ -50,9 +50,8 @@
   EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb), path_to_clang_dir);
 
   // The path doesn't really exist, so setting verify to true should make
-  // ComputeClangResourceDir to not give you path_to_clang_dir.
-  EXPECT_NE(ComputeClangResourceDir(path_to_liblldb, true),
-            ComputeClangResourceDir(path_to_liblldb));
+  // ComputeClangResourceDir not give you path_to_clang_dir.
+  EXPECT_NE(ComputeClangResourceDir(path_to_liblldb, true), path_to_clang_dir);
 }
 
 #if defined(__APPLE__)
Index: source/Plugins/ExpressionParser/Clang/ClangHost.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangHost.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangHost.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Threading.h"
 
+#include "lldb/Host/Config.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Utility/FileSpec.h"
@@ -41,24 +42,39 @@
 /// installed with the same prefix as lldb.
 ///
 static bool DefaultComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
-                                         FileSpec &file_spec, bool verify) {
+                                                 FileSpec &file_spec,
+                                                 bool verify) {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
   std::string raw_path = lldb_shlib_spec.GetPath();
   llvm::StringRef parent_dir = llvm::sys::path::parent_path(raw_path);
 
-  llvm::SmallString<256> clang_dir(parent_dir);
-  llvm::SmallString<32> relative_path;
-  llvm::sys::path::append(relative_path,
-                          llvm::Twine("lib") + CLANG_LIBDIR_SUFFIX, "clang",
-                          CLANG_VERSION_STRING);
-
-  llvm::sys::path::append(clang_dir, relative_path);
-  if (!verify || VerifyClangPath(clang_dir)) {
-    file_spec.GetDirectory().SetString(clang_dir);
-    FileSystem::Instance().Resolve(file_spec);
-    return true;
+  static const llvm::StringRef kResourceDirSuffixes[] = {
+      // LLVM.org's build of LLDB uses the clang resource directory placed
+      // in $install_dir/lib{,64}/clang/$clang_version.
+      "lib" CLANG_LIBDIR_SUFFIX "/clang/" CLANG_VERSION_STRING,
+      // swift-lldb uses the clang resource directory copied from swift, which
+      // by default is placed in $install_dir/lib{,64}/lldb/clang. LLDB places
+      // it there, so we use LLDB_LIBDIR_SUFFIX.
+      "lib" LLDB_LIBDIR_SUFFIX "/lldb/clang",
+  };
+
+  for (const auto &Suffix : kResourceDirSuffixes) {
+    llvm::SmallString<256> clang_dir(parent_dir);
+    llvm::SmallString<32> relative_path(Suffix);
+    llvm::sys::path::native(relative_path);
+    llvm::sys::path::append(clang_dir, relative_path);
+    if (!verify || VerifyClangPath(clang_dir)) {
+      if (log)
+        log->Printf("DefaultComputeClangResourceDir: Setting ClangResourceDir "
+                    "to \"%s\", verify = %s",
+                    clang_dir.str().str().c_str(), verify ? "true" : "false");
+      file_spec.GetDirectory().SetString(clang_dir);
+      FileSystem::Instance().Resolve(file_spec);
+      return true;
+    }
   }
 
-  return HostInfo::ComputePathRelativeToLibrary(file_spec, relative_path);
+  return false;
 }
 
 bool lldb_private::ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59708.192185.patch
Type: text/x-patch
Size: 3604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190325/a0d8317f/attachment.bin>


More information about the lldb-commits mailing list