aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Utility/Reproducer.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-09-11 23:27:12 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-09-11 23:27:12 +0000
commit4a491ec4916b960a8bbbdd857a352c38d4404b86 (patch)
treed6dd22c88fc3db9f35c2c60bff4d7ebc92334075 /lldb/source/Utility/Reproducer.cpp
parentd9aec34b978d688f90680e8785c4631eebe42ff3 (diff)
downloadllvm-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.cpp34
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;