summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Utility/Reproducer.h9
-rw-r--r--lldb/source/Commands/CommandObjectReproducer.cpp15
2 files changed, 13 insertions, 11 deletions
diff --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h
index 1bc8d7af013..3db98a781d4 100644
--- a/lldb/include/lldb/Utility/Reproducer.h
+++ b/lldb/include/lldb/Utility/Reproducer.h
@@ -302,6 +302,15 @@ public:
return GetRoot().CopyByAppendingPathComponent(T::file);
}
+ template <typename T> llvm::Expected<std::string> LoadBuffer() {
+ FileSpec file = GetFile<typename T::Info>();
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
+ llvm::vfs::getRealFileSystem()->getBufferForFile(file.GetPath());
+ if (!buffer)
+ return llvm::errorCodeToError(buffer.getError());
+ return (*buffer)->getBuffer().str();
+ }
+
llvm::Error LoadIndex();
const FileSpec &GetRoot() const { return m_root; }
diff --git a/lldb/source/Commands/CommandObjectReproducer.cpp b/lldb/source/Commands/CommandObjectReproducer.cpp
index 424595fc0bd..0c2e95d5d21 100644
--- a/lldb/source/Commands/CommandObjectReproducer.cpp
+++ b/lldb/source/Commands/CommandObjectReproducer.cpp
@@ -265,19 +265,12 @@ protected:
return true;
}
case eReproducerProviderVersion: {
- FileSpec version_file = loader->GetFile<VersionProvider::Info>();
-
- // Load the version info into a buffer.
- ErrorOr<std::unique_ptr<MemoryBuffer>> buffer =
- vfs::getRealFileSystem()->getBufferForFile(version_file.GetPath());
- if (!buffer) {
- SetError(result, errorCodeToError(buffer.getError()));
+ Expected<std::string> version = loader->LoadBuffer<VersionProvider>();
+ if (!version) {
+ SetError(result, version.takeError());
return false;
}
-
- // Return the version string.
- StringRef version = (*buffer)->getBuffer();
- result.AppendMessage(version.str());
+ result.AppendMessage(*version);
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
OpenPOWER on IntegriCloud