11#include "clang/Basic/Version.h"
12#include "clang/Config/config.h"
13#include "clang/Driver/Driver.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/ADT/Twine.h"
17#include "llvm/Support/FileSystem.h"
18#include "llvm/Support/Threading.h"
20#include "lldb/Host/Config.h"
37 "failed to stat clang resource directory at \"%s\"",
38 clang_path.str().c_str());
53 std::string raw_path = lldb_shlib_spec.
GetPath();
54 llvm::StringRef parent_dir = llvm::sys::path::parent_path(raw_path);
55 static const std::string clang_resource_path =
56 clang::driver::Driver::GetResourcesPath(
"bin/lldb", CLANG_RESOURCE_DIR);
58 static const llvm::StringRef kResourceDirSuffixes[] = {
66 LLDB_INSTALL_LIBDIR_BASENAME
"/lldb/clang",
69 for (
const auto &Suffix : kResourceDirSuffixes) {
70 llvm::SmallString<256> clang_dir(parent_dir);
71 llvm::SmallString<32> relative_path(Suffix);
72 llvm::sys::path::native(relative_path);
73 llvm::sys::path::append(clang_dir, relative_path);
76 "DefaultComputeClangResourceDir: Setting ClangResourceDir "
77 "to \"{0}\", verify = {1}",
78 clang_dir.str(), verify ?
"true" :
"false");
91#if !defined(__APPLE__)
95 std::string raw_path = lldb_shlib_spec.
GetPath();
97 auto rev_it = llvm::sys::path::rbegin(raw_path);
98 auto r_end = llvm::sys::path::rend(raw_path);
101 while (rev_it != r_end) {
102 if (*rev_it ==
"LLDB.framework")
116 llvm::SmallString<256> clang_path;
117 const char *swift_clang_resource_dir =
"usr/lib/swift/clang";
118 auto parent = std::next(rev_it);
119 if (parent != r_end && *parent ==
"SharedFrameworks") {
122 raw_path.resize(parent - r_end);
123 llvm::sys::path::append(clang_path, raw_path,
124 "Developer/Toolchains/XcodeDefault.xctoolchain",
125 swift_clang_resource_dir);
131 }
else if (parent != r_end && *parent ==
"PrivateFrameworks" &&
132 std::distance(parent, r_end) > 2) {
135 if (*parent ==
"System") {
139 raw_path.resize(parent - r_end);
140 llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
150 raw_path = lldb_shlib_spec.
GetPath();
151 raw_path.resize(rev_it - r_end);
152 raw_path.append(
"LLDB.framework/Resources/Clang");
160 static FileSpec g_cached_resource_dir;
161 static llvm::once_flag g_once_flag;
162 llvm::call_once(g_once_flag, []() {
163 if (
FileSpec lldb_file_spec = HostInfo::GetShlibDir())
167 LLDB_LOGF(log,
"GetClangResourceDir() => '%s'",
168 g_cached_resource_dir.
GetPath().c_str());
170 return g_cached_resource_dir;
static bool DefaultComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, FileSpec &file_spec, bool verify)
This will compute the clang resource directory assuming that clang was installed with the same prefix...
static bool VerifyClangPath(const llvm::Twine &clang_path)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
void SetDirectory(ConstString directory)
Directory string set accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
FileSpec GetClangResourceDir()
bool ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec, FileSpec &file_spec, bool verify)