Index: lldb/cmake/modules/LLDBConfig.cmake =================================================================== --- lldb/cmake/modules/LLDBConfig.cmake +++ lldb/cmake/modules/LLDBConfig.cmake @@ -250,6 +250,31 @@ endif() endif() + +# If this is building against a prebuilt Clang, then the Clang resource +# directory that LLDB is using for its embedded Clang instance needs to point +# to the resource directory of the used Clang installation. +if (NOT TARGET clang-resource-headers) + if(Clang_DIR) + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR ${Clang_DIR}/../..) + elseif(LLVM_DIR) + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR ${LLVM_DIR}/../..) + elseif(LLVM_LIBRARY_DIRS) + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR ${LLVM_LIBRARY_DIRS}) + elseif(LLVM_BUILD_LIBRARY_DIR) + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR ${LLVM_BUILD_LIBRARY_DIR}) + elseif(LLVM_BINARY_DIR) + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) + endif() + set(clang_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}) + # Build the final resource directory path by appending 'clang/'. + set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}/clang/${clang_version}) + if(NOT EXISTS ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}) + unset(LLDB_EXTERNAL_CLANG_RESOURCE_DIR) + message(WARNING "Expected directory for clang-resource headers not found: ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}") + endif() +endif() + # Find Apple-specific libraries or frameworks that may be needed. if (APPLE) if(NOT APPLE_EMBEDDED) Index: lldb/cmake/modules/LLDBFramework.cmake =================================================================== --- lldb/cmake/modules/LLDBFramework.cmake +++ lldb/cmake/modules/LLDBFramework.cmake @@ -110,20 +110,7 @@ add_dependencies(liblldb clang-resource-headers) set(clang_resource_headers_dir $) else() - # In standalone builds try the best possible guess - if(Clang_DIR) - set(clang_lib_dir ${Clang_DIR}/../..) - elseif(LLVM_DIR) - set(clang_lib_dir ${LLVM_DIR}/../..) - elseif(LLVM_LIBRARY_DIRS) - set(clang_lib_dir ${LLVM_LIBRARY_DIRS}) - elseif(LLVM_BUILD_LIBRARY_DIR) - set(clang_lib_dir ${LLVM_BUILD_LIBRARY_DIR}) - elseif(LLVM_BINARY_DIR) - set(clang_lib_dir ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) - endif() - set(clang_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}) - set(clang_resource_headers_dir ${clang_lib_dir}/clang/${clang_version}/include) + set(clang_resource_headers_dir ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}/include) if(NOT EXISTS ${clang_resource_headers_dir}) message(WARNING "Expected directory for clang-resource headers not found: ${clang_resource_headers_dir}") endif() Index: lldb/include/lldb/Host/Config.h.cmake =================================================================== --- lldb/include/lldb/Host/Config.h.cmake +++ lldb/include/lldb/Host/Config.h.cmake @@ -54,4 +54,8 @@ #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" +// The full path to the resource directory of the Clang that LLDB was build +// against (or an empty path if LLDB and Clang are build together). +#define LLDB_EXTERNAL_CLANG_RESOURCE_DIR "${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}" + #endif // #ifndef LLDB_HOST_CONFIG_H Index: lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp +++ lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp @@ -61,11 +61,22 @@ "lib" LLDB_LIBDIR_SUFFIX "/lldb/clang", }; + std::vector> directories_to_check; 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); + directories_to_check.push_back(clang_dir); + } + + // Check the resource directory if LLDB was build against an existing Clang. + // The path is empty if Clang is build alongside LLDB. + llvm::SmallString<256> external_clang_dir(LLDB_EXTERNAL_CLANG_RESOURCE_DIR); + if (!external_clang_dir.empty()) + directories_to_check.push_back(external_clang_dir); + + for (const auto &clang_dir : directories_to_check) { if (!verify || VerifyClangPath(clang_dir)) { LLDB_LOG(log, "DefaultComputeClangResourceDir: Setting ClangResourceDir "