[Lldb-commits] [lldb] r375060 - [Reproducer] Add LoadBuffer<> helper (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 16 17:01:57 PDT 2019
Author: jdevlieghere
Date: Wed Oct 16 17:01:57 2019
New Revision: 375060
URL: http://llvm.org/viewvc/llvm-project?rev=375060&view=rev
Log:
[Reproducer] Add LoadBuffer<> helper (NFC)
Introduce a helper method named LoadBuffer in the Loader to abstract
reading a reproducer file from disk.
Modified:
lldb/trunk/include/lldb/Utility/Reproducer.h
lldb/trunk/source/Commands/CommandObjectReproducer.cpp
Modified: lldb/trunk/include/lldb/Utility/Reproducer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Reproducer.h?rev=375060&r1=375059&r2=375060&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Reproducer.h (original)
+++ lldb/trunk/include/lldb/Utility/Reproducer.h Wed Oct 16 17:01:57 2019
@@ -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; }
Modified: lldb/trunk/source/Commands/CommandObjectReproducer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectReproducer.cpp?rev=375060&r1=375059&r2=375060&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectReproducer.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectReproducer.cpp Wed Oct 16 17:01:57 2019
@@ -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;
}
More information about the lldb-commits
mailing list