[Lldb-commits] [lldb] c90ca0c - [lldb] Implement WorkingDirectoryProvider in terms of DirectoryProvider (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 20 18:09:07 PDT 2020
Author: Jonas Devlieghere
Date: 2020-08-20T18:08:59-07:00
New Revision: c90ca0c8e4956e051e2f29cff0c38f9f03b32f87
URL: https://github.com/llvm/llvm-project/commit/c90ca0c8e4956e051e2f29cff0c38f9f03b32f87
DIFF: https://github.com/llvm/llvm-project/commit/c90ca0c8e4956e051e2f29cff0c38f9f03b32f87.diff
LOG: [lldb] Implement WorkingDirectoryProvider in terms of DirectoryProvider (NFC)
Add an abstract base class that can be used to create other directory
providers.
Added:
Modified:
lldb/include/lldb/Utility/Reproducer.h
lldb/source/API/SBReproducer.cpp
lldb/source/Initialization/SystemInitializerCommon.cpp
lldb/source/Utility/Reproducer.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h
index 21f43b6ad5e0..da8fd6754a20 100644
--- a/lldb/include/lldb/Utility/Reproducer.h
+++ b/lldb/include/lldb/Utility/Reproducer.h
@@ -138,28 +138,46 @@ class VersionProvider : public Provider<VersionProvider> {
static char ID;
};
-/// Provider for the LLDB current working directory.
+/// Abstract provider to storing directory paths.
+template <typename T> class DirectoryProvider : public repro::Provider<T> {
+public:
+ DirectoryProvider(const FileSpec &root) : Provider<T>(root) {}
+ void SetDirectory(std::string directory) {
+ m_directory = std::move(directory);
+ }
+ llvm::StringRef GetDirectory() { return m_directory; }
+
+ void Keep() override {
+ FileSpec file = this->GetRoot().CopyByAppendingPathComponent(T::Info::file);
+ std::error_code ec;
+ llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
+ if (ec)
+ return;
+ os << m_directory << "\n";
+ }
+
+protected:
+ std::string m_directory;
+};
+
+/// Provider for the current working directory.
///
/// When the reproducer is kept, it writes lldb's current working directory to
/// a file named cwd.txt in the reproducer root.
-class WorkingDirectoryProvider : public Provider<WorkingDirectoryProvider> {
+class WorkingDirectoryProvider
+ : public DirectoryProvider<WorkingDirectoryProvider> {
public:
- WorkingDirectoryProvider(const FileSpec &directory) : Provider(directory) {
+ WorkingDirectoryProvider(const FileSpec &directory)
+ : DirectoryProvider(directory) {
llvm::SmallString<128> cwd;
if (std::error_code EC = llvm::sys::fs::current_path(cwd))
return;
- m_cwd = std::string(cwd.str());
+ SetDirectory(std::string(cwd));
}
-
- void Update(llvm::StringRef path) { m_cwd = std::string(path); }
- llvm::StringRef GetWorkingDirectory() { return m_cwd; }
-
struct Info {
static const char *name;
static const char *file;
};
- void Keep() override;
- std::string m_cwd;
static char ID;
};
diff --git a/lldb/source/API/SBReproducer.cpp b/lldb/source/API/SBReproducer.cpp
index 9815bf11263c..7d08a88fe9e3 100644
--- a/lldb/source/API/SBReproducer.cpp
+++ b/lldb/source/API/SBReproducer.cpp
@@ -235,9 +235,9 @@ const char *SBReproducer::GetPath() {
void SBReproducer::SetWorkingDirectory(const char *path) {
if (auto *g = lldb_private::repro::Reproducer::Instance().GetGenerator()) {
auto &wp = g->GetOrCreate<repro::WorkingDirectoryProvider>();
- wp.Update(path);
+ wp.SetDirectory(path);
auto &fp = g->GetOrCreate<repro::FileProvider>();
- fp.RecordInterestingDirectory(wp.GetWorkingDirectory());
+ fp.RecordInterestingDirectory(wp.GetDirectory());
}
}
diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp
index 028040b59683..c3bef4139bcc 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -75,7 +75,7 @@ static llvm::Error InitializeFileSystem() {
repro::WorkingDirectoryProvider &wp =
g->GetOrCreate<repro::WorkingDirectoryProvider>();
- fp.RecordInterestingDirectory(wp.GetWorkingDirectory());
+ fp.RecordInterestingDirectory(wp.GetDirectory());
return llvm::Error::success();
}
diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp
index 4441f3d475ea..935e41a08a4e 100644
--- a/lldb/source/Utility/Reproducer.cpp
+++ b/lldb/source/Utility/Reproducer.cpp
@@ -290,15 +290,6 @@ void VersionProvider::Keep() {
os << m_version << "\n";
}
-void WorkingDirectoryProvider::Keep() {
- FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
- std::error_code ec;
- llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
- if (ec)
- return;
- os << m_cwd << "\n";
-}
-
void FileProvider::RecordInterestingDirectory(const llvm::Twine &dir) {
if (m_collector)
m_collector->addFile(dir);
More information about the lldb-commits
mailing list