JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, clayborg, zturner, davide.
JDevlieghere added a project: LLDB.
Herald added subscribers: jdoerfert, teemperor.

In r353906 we hooked up clang and lldb's reproducer infrastructure to
capture files used by clang. This patch adds the necessary logic to have
clang reuse the files from lldb's reproducer during replay.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D58309

Files:
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/ClangASTImporter.h
  lldb/lit/Reproducer/Inputs/ModuleCapture.in
  lldb/lit/Reproducer/Modules/Inputs/Bar.h
  lldb/lit/Reproducer/Modules/Inputs/Foo.h
  lldb/lit/Reproducer/Modules/Inputs/ModuleCXX.in
  lldb/lit/Reproducer/Modules/Inputs/ModuleCocoa.in
  lldb/lit/Reproducer/Modules/Inputs/main.cpp
  lldb/lit/Reproducer/Modules/Inputs/module.modulemap
  lldb/lit/Reproducer/Modules/TestModuleCXX.test
  lldb/lit/Reproducer/Modules/TestModuleCocoa.test
  lldb/lit/Reproducer/TestClangFileRepro.test
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
  lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
  lldb/source/Symbol/ClangASTContext.cpp

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();
 }
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/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/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/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/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/Modules/TestModuleCXX.test
===================================================================
--- /dev/null
+++ lldb/lit/Reproducer/Modules/TestModuleCXX.test
@@ -0,0 +1,27 @@
+# Create a temporary root we can remove later.
+# RUN: mkdir -p %t.root
+# 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 -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
+
+# 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/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/Inputs/main.cpp
===================================================================
--- /dev/null
+++ lldb/lit/Reproducer/Modules/Inputs/main.cpp
@@ -0,0 +1,7 @@
+#include "Foo.h"
+
+int main(int argc, char **argv) {
+  Foo foo;
+  // break here.
+  return 0;
+}
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/Foo.h
===================================================================
--- /dev/null
+++ lldb/lit/Reproducer/Modules/Inputs/Foo.h
@@ -0,0 +1 @@
+struct Foo {};
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/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/include/lldb/Host/FileSystem.h
===================================================================
--- lldb/include/lldb/Host/FileSystem.h
+++ lldb/include/lldb/Host/FileSystem.h
@@ -181,6 +181,10 @@
   llvm::ErrorOr<std::string> GetExternalPath(const llvm::Twine &path);
   llvm::ErrorOr<std::string> GetExternalPath(const FileSpec &file_spec);
 
+  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> GetVirtualFileSystem() {
+    return m_fs;
+  }
+
 private:
   static llvm::Optional<FileSystem> &InstanceImpl();
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to