summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ExpressionParser
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2018-06-04 17:41:00 +0000
committerZachary Turner <zturner@google.com>2018-06-04 17:41:00 +0000
commitbdf089246e9f77babf811fd5811b7947d7cab6ac (patch)
tree2360b62c5aa9bf9b066db9fdc88134d05a4c862b /lldb/source/Plugins/ExpressionParser
parentd0f9a87215e0a25c640229d04dcd4b806b1c2433 (diff)
downloadbcm5719-llvm-bdf089246e9f77babf811fd5811b7947d7cab6ac.tar.gz
bcm5719-llvm-bdf089246e9f77babf811fd5811b7947d7cab6ac.zip
Remove dependency from Host to clang.
Host depended on clang because HostInfo had a function to get the directory where clang was installed. We move this over to the clang expression parser plugin where it's more at home. Differential Revision: https://reviews.llvm.org/D47384 llvm-svn: 333933
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt1
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp142
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h26
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp15
4 files changed, 171 insertions, 13 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
index 5e45319091f..ec4f6d5674e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
@@ -11,6 +11,7 @@ add_lldb_library(lldbPluginExpressionParserClang PLUGIN
ClangExpressionParser.cpp
ClangExpressionVariable.cpp
ClangFunctionCaller.cpp
+ ClangHost.cpp
ClangModulesDeclVendor.cpp
ClangPersistentVariables.cpp
ClangUserExpression.cpp
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
new file mode 100644
index 00000000000..27017df423e
--- /dev/null
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
@@ -0,0 +1,142 @@
+//===-- ClangHost.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ClangHost.h"
+
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
+
+// Project includes
+#if !defined(_WIN32)
+#include "lldb/Host/posix/HostInfoPosix.h"
+#endif
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Log.h"
+
+#include <string>
+
+using namespace lldb_private;
+
+#if defined(_WIN32)
+static bool ComputeClangDirectory(FileSpec &file_spec) { return false; }
+#else
+static bool DefaultComputeClangDirectory(FileSpec &file_spec) {
+ return HostInfoPosix::ComputePathRelativeToLibrary(
+ file_spec, (llvm::Twine("/lib") + CLANG_LIBDIR_SUFFIX + "/clang/" +
+ CLANG_VERSION_STRING)
+ .str());
+}
+
+#if defined(__APPLE__)
+
+static bool VerifyClangPath(const llvm::Twine &clang_path) {
+ if (llvm::sys::fs::is_directory(clang_path))
+ return true;
+ Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+ if (log)
+ log->Printf("VerifyClangPath(): "
+ "failed to stat clang resource directory at \"%s\"",
+ clang_path.str().c_str());
+ return false;
+}
+
+bool lldb_private::ComputeClangDirectory(FileSpec &lldb_shlib_spec,
+ FileSpec &file_spec, bool verify) {
+ std::string raw_path = lldb_shlib_spec.GetPath();
+
+ auto rev_it = llvm::sys::path::rbegin(raw_path);
+ auto r_end = llvm::sys::path::rend(raw_path);
+
+ // Check for a Posix-style build of LLDB.
+ while (rev_it != r_end) {
+ if (*rev_it == "LLDB.framework")
+ break;
+ ++rev_it;
+ }
+
+ if (rev_it == r_end)
+ return DefaultComputeClangDirectory(file_spec);
+
+ // Inside Xcode and in Xcode toolchains LLDB is always in lockstep
+ // with the Swift compiler, so it can reuse its Clang resource
+ // directory. This allows LLDB and the Swift compiler to share the
+ // same Clang module cache.
+ llvm::SmallString<256> clang_path;
+ const char *swift_clang_resource_dir = "usr/lib/swift/clang";
+ auto parent = std::next(rev_it);
+ if (parent != r_end && *parent == "SharedFrameworks") {
+ // This is the top-level LLDB in the Xcode.app bundle.
+ // E.g., "Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A"
+ raw_path.resize(parent - r_end);
+ llvm::sys::path::append(clang_path, raw_path,
+ "Developer/Toolchains/XcodeDefault.xctoolchain",
+ swift_clang_resource_dir);
+ if (!verify || VerifyClangPath(clang_path)) {
+ file_spec.SetFile(clang_path.c_str(), true);
+ return true;
+ }
+ } else if (parent != r_end && *parent == "PrivateFrameworks" &&
+ std::distance(parent, r_end) > 2) {
+ ++parent;
+ ++parent;
+ if (*parent == "System") {
+ // This is LLDB inside an Xcode toolchain.
+ // E.g., "Xcode.app/Contents/Developer/Toolchains/" \
+ // "My.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework"
+ raw_path.resize(parent - r_end);
+ llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
+ if (!verify || VerifyClangPath(clang_path)) {
+ file_spec.SetFile(clang_path.c_str(), true);
+ return true;
+ }
+ raw_path = lldb_shlib_spec.GetPath();
+ }
+ raw_path.resize(rev_it - r_end);
+ } else {
+ raw_path.resize(rev_it - r_end);
+ }
+
+ // Fall back to the Clang resource directory inside the framework.
+ raw_path.append("LLDB.framework/Resources/Clang");
+ file_spec.SetFile(raw_path.c_str(), true);
+ return true;
+}
+
+static bool ComputeClangDirectory(FileSpec &file_spec) {
+ FileSpec lldb_file_spec;
+ if (!HostInfo::GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
+ return false;
+ return ComputeClangDirectory(lldb_file_spec, file_spec, true);
+}
+#else // __APPLE__
+
+// All non-Apple posix systems.
+static bool ComputeClangDirectory(FileSpec &file_spec) {
+ return DefaultComputeClangDirectory(file_spec);
+}
+#endif // __APPLE__
+#endif // _WIN32
+
+FileSpec lldb_private::GetClangResourceDir() {
+ static FileSpec g_cached_resource_dir;
+ static llvm::once_flag g_once_flag;
+ llvm::call_once(g_once_flag, []() {
+ ::ComputeClangDirectory(g_cached_resource_dir);
+ Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+ if (log)
+ log->Printf("GetClangResourceDir() => '%s'",
+ g_cached_resource_dir.GetPath().c_str());
+ });
+ return g_cached_resource_dir;
+}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h
new file mode 100644
index 00000000000..4fe423adb1a
--- /dev/null
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h
@@ -0,0 +1,26 @@
+//===-- ClangHost.h ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGHOST_H
+#define LLDB_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGHOST_H
+
+namespace lldb_private {
+
+class FileSpec;
+
+#if defined(__APPLE__)
+bool ComputeClangDirectory(FileSpec &lldb_shlib_spec, FileSpec &file_spec,
+ bool verify);
+#endif
+
+FileSpec GetClangResourceDir();
+
+} // namespace lldb_private
+
+#endif
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
index 020f8821f0b..665195f0177 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -25,6 +25,7 @@
#include "llvm/Support/Threading.h"
// Project includes
+#include "ClangHost.h"
#include "ClangModulesDeclVendor.h"
#include "lldb/Core/ModuleList.h"
@@ -144,18 +145,6 @@ void StoringDiagnosticConsumer::DumpDiagnostics(Stream &error_stream) {
}
}
-static FileSpec GetResourceDir() {
- static FileSpec g_cached_resource_dir;
-
- static llvm::once_flag g_once_flag;
-
- llvm::call_once(g_once_flag, []() {
- HostInfo::GetLLDBPath(lldb::ePathTypeClangDir, g_cached_resource_dir);
- });
-
- return g_cached_resource_dir;
-}
-
ClangModulesDeclVendor::ClangModulesDeclVendor() {}
ClangModulesDeclVendor::~ClangModulesDeclVendor() {}
@@ -610,7 +599,7 @@ ClangModulesDeclVendor::Create(Target &target) {
}
{
- FileSpec clang_resource_dir = GetResourceDir();
+ FileSpec clang_resource_dir = GetClangResourceDir();
if (llvm::sys::fs::is_directory(clang_resource_dir.GetPath())) {
compiler_invocation_arguments.push_back("-resource-dir");
OpenPOWER on IntegriCloud