Index: lldb/include/lldb/Host/FileSystem.h =================================================================== --- lldb/include/lldb/Host/FileSystem.h +++ lldb/include/lldb/Host/FileSystem.h @@ -181,6 +181,10 @@ llvm::ErrorOr GetExternalPath(const llvm::Twine &path); llvm::ErrorOr GetExternalPath(const FileSpec &file_spec); + llvm::IntrusiveRefCntPtr GetVirtualFileSystem() { + return m_fs; + } + private: static llvm::Optional &InstanceImpl(); llvm::IntrusiveRefCntPtr m_fs; Index: lldb/include/lldb/Symbol/ClangASTImporter.h =================================================================== --- lldb/include/lldb/Symbol/ClangASTImporter.h +++ lldb/include/lldb/Symbol/ClangASTImporter.h @@ -21,6 +21,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Symbol/CompilerDeclContext.h" #include "lldb/lldb-types.h" @@ -93,7 +94,9 @@ vbase_offsets; }; - ClangASTImporter() : m_file_manager(clang::FileSystemOptions()) {} + ClangASTImporter() + : m_file_manager(clang::FileSystemOptions(), + FileSystem::Instance().GetVirtualFileSystem()) {} clang::QualType CopyType(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, clang::QualType type); Index: lldb/lit/Reproducer/Modules/Inputs/Bar.h =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/Inputs/Bar.h @@ -0,0 +1,3 @@ +struct Bar { + int success; +}; Index: lldb/lit/Reproducer/Modules/Inputs/Foo.h =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/Inputs/Foo.h @@ -0,0 +1 @@ +struct Foo {}; Index: lldb/lit/Reproducer/Modules/Inputs/ModuleCXX.in =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/Inputs/ModuleCXX.in @@ -0,0 +1,6 @@ +breakpoint set -f main.cpp -l 5 +run +expr -l Objective-C++ -- @import Foo +expr -l Objective-C++ -- @import Bar +expr -- Bar() +reproducer generate Index: lldb/lit/Reproducer/Modules/Inputs/main.cpp =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/Inputs/main.cpp @@ -0,0 +1,9 @@ +#include "Foo.h" + +void stop() {} + +int main(int argc, char **argv) { + Foo foo; + stop(); // break here. + return 0; +} Index: lldb/lit/Reproducer/Modules/Inputs/module.modulemap =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/Inputs/module.modulemap @@ -0,0 +1,7 @@ +module Foo { + header "Foo.h" +} + +module Bar { + header "Bar.h" +} Index: lldb/lit/Reproducer/Modules/TestModuleCXX.test =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/TestModuleCXX.test @@ -0,0 +1,31 @@ +# Start fresh. +# RUN: rm -rf %t.root +# RUN: rm -rf %t.cache + +# Create a temporary root we can remove later. +# RUN: mkdir -p %t.root +# RUN: mkdir -p %t.cache +# RUN: cp %S/Inputs/main.cpp %t.root +# RUN: cp %S/Inputs/Foo.h %t.root +# RUN: cp %S/Inputs/Bar.h %t.root +# RUN: cp %S/Inputs/module.modulemap %t.root + +# Compile the test case form the temporary root. +# RUN: %clang %t.root/main.cpp -g -fmodules -fmodules -fcxx-modules -fmodules-cache-path=%t.cache -o %t.root/a.out + +# Capture the debug session. +# RUN: %lldb -x -b -s %S/Inputs/ModuleCXX.in --capture %t.repro %t.root/a.out | FileCheck %s --check-prefix CAPTURE +# CAPTURE: (success = 0) + +# RUN: cat %t.repro/files.yaml | FileCheck %s --check-prefix YAML +# YAML-DAG: Foo.h +# YAML-DAG: Bar.h +# YAML-DAG: module.modulemap + +# Remove the temporary root. +# RUN: rm -rf %t.root +# RUN: rm -rf %t.cache + +# Replay the debug session. +# RUN: %lldb -x -b -s %S/Inputs/ModuleCXX.in --replay %t.repro %t.root/a.out | FileCheck %s --check-prefix REPLAY +# REPLAY: (success = 0) Index: lldb/lit/Reproducer/Modules/TestModuleCocoa.test =================================================================== --- /dev/null +++ lldb/lit/Reproducer/Modules/TestModuleCocoa.test @@ -0,0 +1,8 @@ +# REQUIRES: system-darwin +# +# This tests that modules files from clang end up in the reproducer. +# +# RUN: %lldb -x -b -s %S/Inputs/ModuleCocoa.in --capture %t.repro +# cat %t.repro/files.yaml | FileCheck %s --check-prefix YAML +# +# CHECK: Cocoa.h Index: lldb/lit/Reproducer/TestClangFileRepro.test =================================================================== --- lldb/lit/Reproducer/TestClangFileRepro.test +++ /dev/null @@ -1,8 +0,0 @@ -# REQUIRES: system-darwin -# -# This tests that modules files from clang end up in the reproducer. -# -# RUN: %lldb -x -b -s %S/Inputs/ModuleCapture.in --capture %t.repro -# cat %t.repro/files.yaml | FileCheck %s -# -# CHECK: Cocoa.h Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -258,6 +258,10 @@ opts.IncludeModuleFiles = true; } + // Make sure clang uses the same VFS as LLDB. + m_compiler->setVirtualFileSystem( + FileSystem::Instance().GetVirtualFileSystem()); + lldb::LanguageType frame_lang = expr.Language(); // defaults to lldb::eLanguageTypeUnknown bool overridden_target_opts = false; Index: lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -661,6 +661,8 @@ opts.IncludeModuleFiles = true; } + // Make sure clang uses the same VFS as LLDB. + instance->setVirtualFileSystem(FileSystem::Instance().GetVirtualFileSystem()); instance->setDiagnostics(diagnostics_engine.get()); instance->setInvocation(invocation); Index: lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp =================================================================== --- lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp +++ lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp @@ -8,6 +8,7 @@ #include "ClangHighlighter.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Target/Language.h" #include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/StreamString.h" @@ -135,7 +136,8 @@ using namespace clang; FileSystemOptions file_opts; - FileManager file_mgr(file_opts); + FileManager file_mgr(file_opts, + FileSystem::Instance().GetVirtualFileSystem()); unsigned line_number = previous_lines.count('\n') + 1U; Index: lldb/source/Symbol/ClangASTContext.cpp =================================================================== --- lldb/source/Symbol/ClangASTContext.cpp +++ lldb/source/Symbol/ClangASTContext.cpp @@ -911,7 +911,8 @@ clang::FileManager *ClangASTContext::getFileManager() { if (m_file_manager_up == nullptr) { clang::FileSystemOptions file_system_options; - m_file_manager_up.reset(new clang::FileManager(file_system_options)); + m_file_manager_up.reset(new clang::FileManager( + file_system_options, FileSystem::Instance().GetVirtualFileSystem())); } return m_file_manager_up.get(); }