summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-07-29 20:54:02 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-07-29 20:54:02 +0000
commit96b44c77f8fbc0c704c036b82ea173289b93aa72 (patch)
tree125d898c77d1f4f835c7982b4110aa5d7749462e /lldb
parentd01ae675af8eed545e910e6967cd49593a651a23 (diff)
downloadbcm5719-llvm-96b44c77f8fbc0c704c036b82ea173289b93aa72.tar.gz
bcm5719-llvm-96b44c77f8fbc0c704c036b82ea173289b93aa72.zip
[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
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Host/FileSystem.h8
-rw-r--r--lldb/include/lldb/Utility/Reproducer.h15
-rw-r--r--lldb/source/Host/common/FileSystem.cpp2
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h8
4 files changed, 19 insertions, 14 deletions
diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h
index a5f2e245140..733a4a4fe39 100644
--- a/lldb/include/lldb/Host/FileSystem.h
+++ b/lldb/include/lldb/Host/FileSystem.h
@@ -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
diff --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h
index ecd6b6f08f5..37f47208624 100644
--- a/lldb/include/lldb/Utility/Reproducer.h
+++ b/lldb/include/lldb/Utility/Reproducer.h
@@ -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.
diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp
index 3b4db43966e..0d9417120fd 100644
--- a/lldb/source/Host/common/FileSystem.cpp
+++ b/lldb/source/Host/common/FileSystem.cpp
@@ -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);
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h b/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
index 9660abf1bfa..7553860f249 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
@@ -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
OpenPOWER on IntegriCloud