[Lldb-commits] [lldb] r354283 - [Reproducers] Make clang use lldb's VFS.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 18 12:31:19 PST 2019


Author: jdevlieghere
Date: Mon Feb 18 12:31:18 2019
New Revision: 354283

URL: http://llvm.org/viewvc/llvm-project?rev=354283&view=rev
Log:
[Reproducers] Make clang use lldb's VFS.

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.

Differential revision: https://reviews.llvm.org/D58309

Added:
    lldb/trunk/lit/Reproducer/Modules/
    lldb/trunk/lit/Reproducer/Modules/Inputs/
    lldb/trunk/lit/Reproducer/Modules/Inputs/Bar.h
    lldb/trunk/lit/Reproducer/Modules/Inputs/Foo.h
    lldb/trunk/lit/Reproducer/Modules/Inputs/ModuleCXX.in
    lldb/trunk/lit/Reproducer/Modules/Inputs/main.cpp
    lldb/trunk/lit/Reproducer/Modules/Inputs/module.modulemap
    lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test
Removed:
    lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in
    lldb/trunk/lit/Reproducer/TestClangFileRepro.test
Modified:
    lldb/trunk/include/lldb/Host/FileSystem.h
    lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
    lldb/trunk/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp

Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Mon Feb 18 12:31:18 2019
@@ -181,6 +181,10 @@ public:
   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;

Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Mon Feb 18 12:31:18 2019
@@ -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 @@ public:
         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);

Removed: lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in?rev=354282&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in (original)
+++ lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in (removed)
@@ -1,2 +0,0 @@
-expr -- @import Cocoa
-reproducer generate

Added: lldb/trunk/lit/Reproducer/Modules/Inputs/Bar.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/Inputs/Bar.h?rev=354283&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/Inputs/Bar.h (added)
+++ lldb/trunk/lit/Reproducer/Modules/Inputs/Bar.h Mon Feb 18 12:31:18 2019
@@ -0,0 +1,3 @@
+struct Bar {
+  int success;
+};

Added: lldb/trunk/lit/Reproducer/Modules/Inputs/Foo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/Inputs/Foo.h?rev=354283&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/Inputs/Foo.h (added)
+++ lldb/trunk/lit/Reproducer/Modules/Inputs/Foo.h Mon Feb 18 12:31:18 2019
@@ -0,0 +1 @@
+struct Foo {};

Added: lldb/trunk/lit/Reproducer/Modules/Inputs/ModuleCXX.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/Inputs/ModuleCXX.in?rev=354283&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/Inputs/ModuleCXX.in (added)
+++ lldb/trunk/lit/Reproducer/Modules/Inputs/ModuleCXX.in Mon Feb 18 12:31:18 2019
@@ -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

Added: lldb/trunk/lit/Reproducer/Modules/Inputs/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/Inputs/main.cpp?rev=354283&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/Inputs/main.cpp (added)
+++ lldb/trunk/lit/Reproducer/Modules/Inputs/main.cpp Mon Feb 18 12:31:18 2019
@@ -0,0 +1,9 @@
+#include "Foo.h"
+
+void stop() {}
+
+int main(int argc, char **argv) {
+  Foo foo;
+  stop(); // break here.
+  return 0;
+}

Added: lldb/trunk/lit/Reproducer/Modules/Inputs/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/Inputs/module.modulemap?rev=354283&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/Inputs/module.modulemap (added)
+++ lldb/trunk/lit/Reproducer/Modules/Inputs/module.modulemap Mon Feb 18 12:31:18 2019
@@ -0,0 +1,7 @@
+module Foo {
+  header "Foo.h"
+}
+
+module Bar {
+  header "Bar.h"
+}

Added: lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test?rev=354283&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test (added)
+++ lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test Mon Feb 18 12:31:18 2019
@@ -0,0 +1,34 @@
+# Start fresh.
+# RUN: rm -rf %t.root
+# RUN: rm -rf %t.clang-cache
+# RUN: rm -rf %t.lldb-cache
+
+# Create a temporary root we can remove later.
+# RUN: mkdir -p %t.root
+# RUN: mkdir -p %t.clang-cache
+# RUN: mkdir -p %t.lldb-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 -fcxx-modules -fmodules-cache-path=%t.clang-cache -o %t.root/a.out
+
+# Capture the debug session.
+# RUN: %lldb -x -b -o 'settings set symbols.clang-modules-cache-path %t.lldb-cache' -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.clang-cache
+# RUN: rm -rf %t.lldb-cache
+
+# Replay the debug session.
+# RUN: %lldb -x -b -o 'settings set symbols.clang-modules-cache-path %t.lldb-cache' -s %S/Inputs/ModuleCXX.in --replay %t.repro %t.root/a.out | FileCheck %s --check-prefix REPLAY
+# REPLAY: (success = 0)

Removed: lldb/trunk/lit/Reproducer/TestClangFileRepro.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestClangFileRepro.test?rev=354282&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/TestClangFileRepro.test (original)
+++ lldb/trunk/lit/Reproducer/TestClangFileRepro.test (removed)
@@ -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

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Mon Feb 18 12:31:18 2019
@@ -258,6 +258,10 @@ ClangExpressionParser::ClangExpressionPa
     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;

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Mon Feb 18 12:31:18 2019
@@ -661,6 +661,8 @@ ClangModulesDeclVendor::Create(Target &t
     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);
 

Modified: lldb/trunk/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp Mon Feb 18 12:31:18 2019
@@ -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 @@ void ClangHighlighter::Highlight(const H
   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;
 

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Mon Feb 18 12:31:18 2019
@@ -911,7 +911,8 @@ SelectorTable *ClangASTContext::getSelec
 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();
 }

Modified: lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp?rev=354283&r1=354282&r2=354283&view=diff
==============================================================================
--- lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp (original)
+++ lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp Mon Feb 18 12:31:18 2019
@@ -9,6 +9,7 @@
 #include "gtest/gtest.h"
 
 #include "lldb/Core/Highlighter.h"
+#include "lldb/Host/FileSystem.h"
 
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
 #include "Plugins/Language/ObjC/ObjCLanguage.h"
@@ -27,6 +28,7 @@ public:
 void HighlighterTest::SetUpTestCase() {
   // The HighlighterManager uses the language plugins under the hood, so we
   // have to initialize them here for our test process.
+  FileSystem::Initialize();
   CPlusPlusLanguage::Initialize();
   ObjCLanguage::Initialize();
   ObjCPlusPlusLanguage::Initialize();
@@ -36,6 +38,7 @@ void HighlighterTest::TearDownTestCase()
   CPlusPlusLanguage::Terminate();
   ObjCLanguage::Terminate();
   ObjCPlusPlusLanguage::Terminate();
+  FileSystem::Terminate();
 }
 
 static std::string getName(lldb::LanguageType type) {




More information about the lldb-commits mailing list