diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2020-07-10 12:45:38 -0700 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2020-07-10 12:48:22 -0700 |
| commit | 169c83208f37f8e5539b1386030d9f3e4b15f16a (patch) | |
| tree | 4c26752549cf31de8a00407f43e96ddcb1b1a99d /lldb/source/Utility/Reproducer.cpp | |
| parent | ea201e83e292f39c3ee7fe8810a348ee98000398 (diff) | |
| download | llvm-169c83208f37f8e5539b1386030d9f3e4b15f16a.tar.gz llvm-169c83208f37f8e5539b1386030d9f3e4b15f16a.tar.bz2 llvm-169c83208f37f8e5539b1386030d9f3e4b15f16a.zip | |
[ldb/Reproducers] Add YamlRecorder and MultiProvider
This patch does several things that are all closely related:
- It introduces a new YamlRecorder as a counterpart to the existing
DataRecorder. As the name suggests the former serializes data as yaml
while the latter uses raw texts or bytes.
- It introduces a new MultiProvider base class which can be backed by
either a DataRecorder or a YamlRecorder.
- It reimplements the CommandProvider in terms of the new
MultiProvider.
Finally, it adds unit testing coverage for the MultiProvider, a naive
YamlProvider built on top of the new YamlRecorder and the existing
MutliLoader.
Differential revision: https://reviews.llvm.org/D83441
Diffstat (limited to 'lldb/source/Utility/Reproducer.cpp')
| -rw-r--r-- | lldb/source/Utility/Reproducer.cpp | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp index eb7d96baab57..7620ab2c389d 100644 --- a/lldb/source/Utility/Reproducer.cpp +++ b/lldb/source/Utility/Reproducer.cpp @@ -272,40 +272,15 @@ DataRecorder::Create(const FileSpec &filename) { return std::move(recorder); } -DataRecorder *CommandProvider::GetNewDataRecorder() { - std::size_t i = m_data_recorders.size() + 1; - std::string filename = (llvm::Twine(Info::name) + llvm::Twine("-") + - llvm::Twine(i) + llvm::Twine(".yaml")) - .str(); - auto recorder_or_error = - DataRecorder::Create(GetRoot().CopyByAppendingPathComponent(filename)); - if (!recorder_or_error) { - llvm::consumeError(recorder_or_error.takeError()); - return nullptr; - } - - m_data_recorders.push_back(std::move(*recorder_or_error)); - return m_data_recorders.back().get(); -} - -void CommandProvider::Keep() { - std::vector<std::string> files; - for (auto &recorder : m_data_recorders) { - recorder->Stop(); - files.push_back(recorder->GetFilename().GetPath()); - } - - FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file); +llvm::Expected<std::unique_ptr<YamlRecorder>> +YamlRecorder::Create(const FileSpec &filename) { std::error_code ec; - llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text); + auto recorder = std::make_unique<YamlRecorder>(std::move(filename), ec); if (ec) - return; - yaml::Output yout(os); - yout << files; + return llvm::errorCodeToError(ec); + return std::move(recorder); } -void CommandProvider::Discard() { m_data_recorders.clear(); } - void VersionProvider::Keep() { FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file); std::error_code ec; |
