Skip to content

Commit 63e2e59

Browse files
committedFeb 13, 2019
[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 llvm-svn: 353906
1 parent a9f91c8 commit 63e2e59

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed
 
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
expr -- @import Cocoa
2+
reproducer generate
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# REQUIRES: system-darwin
2+
#
3+
# This tests that modules files from clang end up in the reproducer.
4+
#
5+
# RUN: %lldb -x -b -s %S/Inputs/ModuleCapture.in --capture %t.repro
6+
# cat %t.repro/files.yaml | FileCheck %s
7+
#
8+
# CHECK: Cocoa.h
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
expr -- @import Cocoa
2+
reproducer generate
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# REQUIRES: system-darwin
2+
#
3+
# This tests that modules files from clang end up in the reproducer.
4+
#
5+
# RUN: %lldb -x -b -s %S/Inputs/ModuleCapture.in --capture %t.repro
6+
# cat %t.repro/files.yaml | FileCheck %s
7+
#
8+
# CHECK: Cocoa.h

‎lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
#include "llvm/Support/MemoryBuffer.h"
5555
#include "llvm/Support/Signals.h"
5656

57-
#include "ClangDiagnostic.h"
58-
#include "ClangExpressionParser.h"
59-
6057
#include "ClangASTSource.h"
58+
#include "ClangDiagnostic.h"
6159
#include "ClangExpressionDeclMap.h"
6260
#include "ClangExpressionHelper.h"
61+
#include "ClangExpressionParser.h"
6362
#include "ClangModulesDeclVendor.h"
6463
#include "ClangPersistentVariables.h"
6564
#include "IRForTarget.h"
65+
#include "ModuleDependencyCollector.h"
6666

6767
#include "lldb/Core/Debugger.h"
6868
#include "lldb/Core/Disassembler.h"
@@ -84,6 +84,7 @@
8484
#include "lldb/Utility/DataBufferHeap.h"
8585
#include "lldb/Utility/LLDBAssert.h"
8686
#include "lldb/Utility/Log.h"
87+
#include "lldb/Utility/Reproducer.h"
8788
#include "lldb/Utility/Stream.h"
8889
#include "lldb/Utility/StreamString.h"
8990
#include "lldb/Utility/StringList.h"
@@ -250,6 +251,19 @@ ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope,
250251

251252
// 1. Create a new compiler instance.
252253
m_compiler.reset(new CompilerInstance());
254+
255+
// When capturing a reproducer, hook up the file collector with clang to
256+
// collector modules and headers.
257+
if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) {
258+
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
259+
m_compiler->setModuleDepCollector(
260+
std::make_shared<ModuleDependencyCollectorAdaptor>(
261+
fp.GetFileCollector()));
262+
DependencyOutputOptions &opts = m_compiler->getDependencyOutputOpts();
263+
opts.IncludeSystemHeaders = true;
264+
opts.IncludeModuleFiles = true;
265+
}
266+
253267
lldb::LanguageType frame_lang =
254268
expr.Language(); // defaults to lldb::eLanguageTypeUnknown
255269
bool overridden_target_opts = false;

‎lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "ClangHost.h"
2424
#include "ClangModulesDeclVendor.h"
25+
#include "ModuleDependencyCollector.h"
2526

2627
#include "lldb/Core/ModuleList.h"
2728
#include "lldb/Host/Host.h"
@@ -31,6 +32,7 @@
3132
#include "lldb/Utility/FileSpec.h"
3233
#include "lldb/Utility/LLDBAssert.h"
3334
#include "lldb/Utility/Log.h"
35+
#include "lldb/Utility/Reproducer.h"
3436
#include "lldb/Utility/StreamString.h"
3537

3638
using namespace lldb_private;
@@ -631,6 +633,18 @@ ClangModulesDeclVendor::Create(Target &target) {
631633
std::unique_ptr<clang::CompilerInstance> instance(
632634
new clang::CompilerInstance);
633635

636+
// When capturing a reproducer, hook up the file collector with clang to
637+
// collector modules and headers.
638+
if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) {
639+
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
640+
instance->setModuleDepCollector(
641+
std::make_shared<ModuleDependencyCollectorAdaptor>(
642+
fp.GetFileCollector()));
643+
clang::DependencyOutputOptions &opts = instance->getDependencyOutputOpts();
644+
opts.IncludeSystemHeaders = true;
645+
opts.IncludeModuleFiles = true;
646+
}
647+
634648
instance->setDiagnostics(diagnostics_engine.get());
635649
instance->setInvocation(invocation);
636650

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===-- ModuleDependencyCollector.h -----------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef liblldb_ModuleDependencyCollector_h_
10+
#define liblldb_ModuleDependencyCollector_h_
11+
12+
#include "lldb/Utility/FileCollector.h"
13+
#include "clang/Frontend/Utils.h"
14+
#include "llvm/ADT/StringRef.h"
15+
16+
namespace lldb_private {
17+
class ModuleDependencyCollectorAdaptor
18+
: public clang::ModuleDependencyCollector {
19+
public:
20+
ModuleDependencyCollectorAdaptor(FileCollector &file_collector)
21+
: clang::ModuleDependencyCollector(""), m_file_collector(file_collector) {
22+
}
23+
24+
void addFile(llvm::StringRef Filename,
25+
llvm::StringRef FileDst = {}) override {
26+
m_file_collector.AddFile(Filename);
27+
}
28+
29+
bool insertSeen(llvm::StringRef Filename) override { return false; }
30+
void addFileMapping(llvm::StringRef VPath, llvm::StringRef RPath) override {}
31+
void writeFileMap() override {}
32+
33+
private:
34+
FileCollector &m_file_collector;
35+
};
36+
} // namespace lldb_private
37+
38+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.