[Lldb-commits] [lldb] r353906 - [Reproducers] Integrate FileProvider with clang
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 12 17:30:41 PST 2019
Author: jdevlieghere
Date: Tue Feb 12 17:30:41 2019
New Revision: 353906
URL: http://llvm.org/viewvc/llvm-project?rev=353906&view=rev
Log:
[Reproducers] Integrate FileProvider with clang
This patch hooks up clang and lldb's reproducers functionality. It
ensures that when capturing a reproducer, headers and modules imported
through the expression parser are collected.
Differential revision: https://reviews.llvm.org/D58076
Added:
lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in
lldb/trunk/lit/Reproducer/TestClangFileRepro.test
lldb/trunk/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
Modified:
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
Added: lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in?rev=353906&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in (added)
+++ lldb/trunk/lit/Reproducer/Inputs/ModuleCapture.in Tue Feb 12 17:30:41 2019
@@ -0,0 +1,2 @@
+expr -- @import Cocoa
+reproducer generate
Added: lldb/trunk/lit/Reproducer/TestClangFileRepro.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestClangFileRepro.test?rev=353906&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/TestClangFileRepro.test (added)
+++ lldb/trunk/lit/Reproducer/TestClangFileRepro.test Tue Feb 12 17:30:41 2019
@@ -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/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=353906&r1=353905&r2=353906&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Tue Feb 12 17:30:41 2019
@@ -54,15 +54,15 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
-#include "ClangDiagnostic.h"
-#include "ClangExpressionParser.h"
-
#include "ClangASTSource.h"
+#include "ClangDiagnostic.h"
#include "ClangExpressionDeclMap.h"
#include "ClangExpressionHelper.h"
+#include "ClangExpressionParser.h"
#include "ClangModulesDeclVendor.h"
#include "ClangPersistentVariables.h"
#include "IRForTarget.h"
+#include "ModuleDependencyCollector.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Disassembler.h"
@@ -84,6 +84,7 @@
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Reproducer.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StringList.h"
@@ -250,6 +251,19 @@ ClangExpressionParser::ClangExpressionPa
// 1. Create a new compiler instance.
m_compiler.reset(new CompilerInstance());
+
+ // When capturing a reproducer, hook up the file collector with clang to
+ // collector modules and headers.
+ if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) {
+ repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
+ m_compiler->setModuleDepCollector(
+ std::make_shared<ModuleDependencyCollectorAdaptor>(
+ fp.GetFileCollector()));
+ DependencyOutputOptions &opts = m_compiler->getDependencyOutputOpts();
+ opts.IncludeSystemHeaders = true;
+ opts.IncludeModuleFiles = true;
+ }
+
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=353906&r1=353905&r2=353906&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Tue Feb 12 17:30:41 2019
@@ -22,6 +22,7 @@
#include "ClangHost.h"
#include "ClangModulesDeclVendor.h"
+#include "ModuleDependencyCollector.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Host/Host.h"
@@ -31,6 +32,7 @@
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Reproducer.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb_private;
@@ -631,6 +633,18 @@ ClangModulesDeclVendor::Create(Target &t
std::unique_ptr<clang::CompilerInstance> instance(
new clang::CompilerInstance);
+ // When capturing a reproducer, hook up the file collector with clang to
+ // collector modules and headers.
+ if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) {
+ repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
+ instance->setModuleDepCollector(
+ std::make_shared<ModuleDependencyCollectorAdaptor>(
+ fp.GetFileCollector()));
+ clang::DependencyOutputOptions &opts = instance->getDependencyOutputOpts();
+ opts.IncludeSystemHeaders = true;
+ opts.IncludeModuleFiles = true;
+ }
+
instance->setDiagnostics(diagnostics_engine.get());
instance->setInvocation(invocation);
Added: lldb/trunk/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h?rev=353906&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h (added)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h Tue Feb 12 17:30:41 2019
@@ -0,0 +1,38 @@
+//===-- ModuleDependencyCollector.h -----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ModuleDependencyCollector_h_
+#define liblldb_ModuleDependencyCollector_h_
+
+#include "lldb/Utility/FileCollector.h"
+#include "clang/Frontend/Utils.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace lldb_private {
+class ModuleDependencyCollectorAdaptor
+ : public clang::ModuleDependencyCollector {
+public:
+ ModuleDependencyCollectorAdaptor(FileCollector &file_collector)
+ : clang::ModuleDependencyCollector(""), m_file_collector(file_collector) {
+ }
+
+ void addFile(llvm::StringRef Filename,
+ llvm::StringRef FileDst = {}) override {
+ m_file_collector.AddFile(Filename);
+ }
+
+ bool insertSeen(llvm::StringRef Filename) override { return false; }
+ void addFileMapping(llvm::StringRef VPath, llvm::StringRef RPath) override {}
+ void writeFileMap() override {}
+
+private:
+ FileCollector &m_file_collector;
+};
+} // namespace lldb_private
+
+#endif
More information about the lldb-commits
mailing list