forked from OSchip/llvm-project
[Reproducers] Pass FileCollector around as a shared_ptr (NFC)
Instead of passing the FileCollector around as a reference or raw pointer, use a shared_ptr. This change's motivation is twofold. First it adds compatibility for the newly added `FileCollectorFileSystem`. Secondly, it addresses a lifetime issue we only see when LLDB is used from Xcode, where a reference to the FileCollector outlives the reproducer instance. llvm-svn: 367258
This commit is contained in:
parent
d01ae675af
commit
96b44c77f8
|
@ -34,8 +34,8 @@ public:
|
|||
FileSystem()
|
||||
: m_fs(llvm::vfs::getRealFileSystem()), m_collector(nullptr),
|
||||
m_mapped(false) {}
|
||||
FileSystem(llvm::FileCollector &collector)
|
||||
: m_fs(llvm::vfs::getRealFileSystem()), m_collector(&collector),
|
||||
FileSystem(std::shared_ptr<llvm::FileCollector> collector)
|
||||
: m_fs(llvm::vfs::getRealFileSystem()), m_collector(collector),
|
||||
m_mapped(false) {}
|
||||
FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
||||
bool mapped = false)
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
static FileSystem &Instance();
|
||||
|
||||
static void Initialize();
|
||||
static void Initialize(llvm::FileCollector &collector);
|
||||
static void Initialize(std::shared_ptr<llvm::FileCollector> collector);
|
||||
static llvm::Error Initialize(const FileSpec &mapping);
|
||||
static void Initialize(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
|
||||
static void Terminate();
|
||||
|
@ -188,7 +188,7 @@ public:
|
|||
private:
|
||||
static llvm::Optional<FileSystem> &InstanceImpl();
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
|
||||
llvm::FileCollector *m_collector;
|
||||
std::shared_ptr<llvm::FileCollector> m_collector;
|
||||
bool m_mapped;
|
||||
};
|
||||
} // namespace lldb_private
|
||||
|
|
|
@ -91,23 +91,26 @@ public:
|
|||
|
||||
FileProvider(const FileSpec &directory)
|
||||
: Provider(directory),
|
||||
m_collector(directory.CopyByAppendingPathComponent("root").GetPath(),
|
||||
directory.GetPath()) {}
|
||||
m_collector(std::make_shared<llvm::FileCollector>(
|
||||
directory.CopyByAppendingPathComponent("root").GetPath(),
|
||||
directory.GetPath())) {}
|
||||
|
||||
llvm::FileCollector &GetFileCollector() { return m_collector; }
|
||||
std::shared_ptr<llvm::FileCollector> GetFileCollector() {
|
||||
return m_collector;
|
||||
}
|
||||
|
||||
void Keep() override {
|
||||
auto mapping = GetRoot().CopyByAppendingPathComponent(Info::file);
|
||||
// Temporary files that are removed during execution can cause copy errors.
|
||||
if (auto ec = m_collector.copyFiles(/*stop_on_error=*/false))
|
||||
if (auto ec = m_collector->copyFiles(/*stop_on_error=*/false))
|
||||
return;
|
||||
m_collector.writeMapping(mapping.GetPath());
|
||||
m_collector->writeMapping(mapping.GetPath());
|
||||
}
|
||||
|
||||
static char ID;
|
||||
|
||||
private:
|
||||
llvm::FileCollector m_collector;
|
||||
std::shared_ptr<llvm::FileCollector> m_collector;
|
||||
};
|
||||
|
||||
/// Provider for the LLDB version number.
|
||||
|
|
|
@ -49,7 +49,7 @@ void FileSystem::Initialize() {
|
|||
InstanceImpl().emplace();
|
||||
}
|
||||
|
||||
void FileSystem::Initialize(FileCollector &collector) {
|
||||
void FileSystem::Initialize(std::shared_ptr<FileCollector> collector) {
|
||||
lldbassert(!InstanceImpl() && "Already initialized.");
|
||||
InstanceImpl().emplace(collector);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,15 @@ namespace lldb_private {
|
|||
class ModuleDependencyCollectorAdaptor
|
||||
: public clang::ModuleDependencyCollector {
|
||||
public:
|
||||
ModuleDependencyCollectorAdaptor(llvm::FileCollector &file_collector)
|
||||
ModuleDependencyCollectorAdaptor(
|
||||
std::shared_ptr<llvm::FileCollector> file_collector)
|
||||
: clang::ModuleDependencyCollector(""), m_file_collector(file_collector) {
|
||||
}
|
||||
|
||||
void addFile(llvm::StringRef Filename,
|
||||
llvm::StringRef FileDst = {}) override {
|
||||
m_file_collector.addFile(Filename);
|
||||
if (m_file_collector)
|
||||
m_file_collector->addFile(Filename);
|
||||
}
|
||||
|
||||
bool insertSeen(llvm::StringRef Filename) override { return false; }
|
||||
|
@ -31,7 +33,7 @@ public:
|
|||
void writeFileMap() override {}
|
||||
|
||||
private:
|
||||
llvm::FileCollector &m_file_collector;
|
||||
std::shared_ptr<llvm::FileCollector> m_file_collector;
|
||||
};
|
||||
} // namespace lldb_private
|
||||
|
||||
|
|
Loading…
Reference in New Issue