diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2019-09-11 23:27:12 +0000 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2019-09-11 23:27:12 +0000 |
| commit | 4a491ec4916b960a8bbbdd857a352c38d4404b86 (patch) | |
| tree | d6dd22c88fc3db9f35c2c60bff4d7ebc92334075 /lldb/source/Utility/Reproducer.cpp | |
| parent | d9aec34b978d688f90680e8785c4631eebe42ff3 (diff) | |
| download | llvm-4a491ec4916b960a8bbbdd857a352c38d4404b86.tar.gz llvm-4a491ec4916b960a8bbbdd857a352c38d4404b86.tar.bz2 llvm-4a491ec4916b960a8bbbdd857a352c38d4404b86.zip | |
[Reproducer] Move the command loader into the reproducer (NFC)
This just moves the CommandLoader utility into the reproducer namespace
and makes it accessible outside the API layer. This is setting things up
for a bigger change.
llvm-svn: 371689
Diffstat (limited to 'lldb/source/Utility/Reproducer.cpp')
| -rw-r--r-- | lldb/source/Utility/Reproducer.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp index fa337660e8d0..8e44f0801772 100644 --- a/lldb/source/Utility/Reproducer.cpp +++ b/lldb/source/Utility/Reproducer.cpp @@ -281,6 +281,40 @@ llvm::raw_ostream *ProcessGDBRemoteProvider::GetHistoryStream() { return m_stream_up.get(); } +std::unique_ptr<CommandLoader> CommandLoader::Create(Loader *loader) { + if (!loader) + return {}; + + FileSpec file = loader->GetFile<repro::CommandProvider::Info>(); + if (!file) + return {}; + + auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath()); + if (auto err = error_or_file.getError()) + return {}; + + std::vector<std::string> files; + llvm::yaml::Input yin((*error_or_file)->getBuffer()); + yin >> files; + + if (auto err = yin.error()) + return {}; + + for (auto &file : files) { + FileSpec absolute_path = + loader->GetRoot().CopyByAppendingPathComponent(file); + file = absolute_path.GetPath(); + } + + return std::make_unique<CommandLoader>(std::move(files)); +} + +llvm::Optional<std::string> CommandLoader::GetNextFile() { + if (m_index >= m_files.size()) + return {}; + return m_files[m_index++]; +} + void ProviderBase::anchor() {} char CommandProvider::ID = 0; char FileProvider::ID = 0; |
