11#include "clang/Basic/Version.h"
12#include "clang/Config/config.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/ADT/Twine.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Threading.h"
19#include "lldb/Host/Config.h"
36 "failed to stat clang resource directory at \"%s\"",
37 clang_path.str().c_str());
52 std::string raw_path = lldb_shlib_spec.
GetPath();
53 llvm::StringRef parent_dir = llvm::sys::path::parent_path(raw_path);
55 static const llvm::StringRef kResourceDirSuffixes[] = {
58 CLANG_INSTALL_LIBDIR_BASENAME
"/clang/" CLANG_VERSION_MAJOR_STRING,
62 LLDB_INSTALL_LIBDIR_BASENAME
"/lldb/clang",
65 for (
const auto &Suffix : kResourceDirSuffixes) {
66 llvm::SmallString<256> clang_dir(parent_dir);
67 llvm::SmallString<32> relative_path(Suffix);
68 llvm::sys::path::native(relative_path);
69 llvm::sys::path::append(clang_dir, relative_path);
72 "DefaultComputeClangResourceDir: Setting ClangResourceDir "
73 "to \"{0}\", verify = {1}",
74 clang_dir.str(), verify ?
"true" :
"false");
86#if !defined(__APPLE__)
90 std::string raw_path = lldb_shlib_spec.
GetPath();
92 auto rev_it = llvm::sys::path::rbegin(raw_path);
93 auto r_end = llvm::sys::path::rend(raw_path);
96 while (rev_it != r_end) {
97 if (*rev_it ==
"LLDB.framework")
111 llvm::SmallString<256> clang_path;
112 const char *swift_clang_resource_dir =
"usr/lib/swift/clang";
113 auto parent = std::next(rev_it);
114 if (parent != r_end && *parent ==
"SharedFrameworks") {
117 raw_path.resize(parent - r_end);
118 llvm::sys::path::append(clang_path, raw_path,
119 "Developer/Toolchains/XcodeDefault.xctoolchain",
120 swift_clang_resource_dir);
126 }
else if (parent != r_end && *parent ==
"PrivateFrameworks" &&
127 std::distance(parent, r_end) > 2) {
130 if (*parent ==
"System") {
134 raw_path.resize(parent - r_end);
135 llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
145 raw_path = lldb_shlib_spec.
GetPath();
146 raw_path.resize(rev_it - r_end);
147 raw_path.append(
"LLDB.framework/Resources/Clang");
155 static FileSpec g_cached_resource_dir;
156 static llvm::once_flag g_once_flag;
157 llvm::call_once(g_once_flag, []() {
158 if (
FileSpec lldb_file_spec = HostInfo::GetShlibDir())
162 LLDB_LOGF(log,
"GetClangResourceDir() => '%s'",
163 g_cached_resource_dir.
GetPath().c_str());
165 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)