summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/StreamFile.cpp
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-09-26 17:54:59 +0000
committerLawrence D'Anna <lawrence_danna@apple.com>2019-09-26 17:54:59 +0000
commit2fce1137c7c227f40edbb657c484797addba38ca (patch)
tree1aca86d16d377f546f54a9b2c4782e51f113008c /lldb/source/Core/StreamFile.cpp
parent875d20bcde2e2b1990f3a4bdfc800959e8a72ed6 (diff)
downloadbcm5719-llvm-2fce1137c7c227f40edbb657c484797addba38ca.tar.gz
bcm5719-llvm-2fce1137c7c227f40edbb657c484797addba38ca.zip
Convert FileSystem::Open() to return Expected<FileUP>
Summary: This patch converts FileSystem::Open from this prototype: Status Open(File &File, const FileSpec &file_spec, ...); to this one: llvm::Expected<std::unique_ptr<File>> Open(const FileSpec &file_spec, ...); This is beneficial on its own, as llvm::Expected is a more modern and recommended error type than Status. It is also a necessary step towards https://reviews.llvm.org/D67891, and further developments for lldb_private::File. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67996 llvm-svn: 373003
Diffstat (limited to 'lldb/source/Core/StreamFile.cpp')
-rw-r--r--lldb/source/Core/StreamFile.cpp52
1 files changed, 36 insertions, 16 deletions
diff --git a/lldb/source/Core/StreamFile.cpp b/lldb/source/Core/StreamFile.cpp
index 17662a43604..fe5d7413114 100644
--- a/lldb/source/Core/StreamFile.cpp
+++ b/lldb/source/Core/StreamFile.cpp
@@ -8,6 +8,7 @@
#include "lldb/Core/StreamFile.h"
#include "lldb/Host/FileSystem.h"
+#include "lldb/Utility/Log.h"
#include <stdio.h>
@@ -15,35 +16,54 @@ using namespace lldb;
using namespace lldb_private;
// StreamFile constructor
-StreamFile::StreamFile() : Stream(), m_file() {}
+StreamFile::StreamFile() : Stream() { m_file_sp = std::make_shared<File>(); }
StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
- : Stream(flags, addr_size, byte_order), m_file() {}
+ : Stream(flags, addr_size, byte_order) {
+ m_file_sp = std::make_shared<File>();
+}
-StreamFile::StreamFile(int fd, bool transfer_ownership)
- : Stream(), m_file(fd, File::eOpenOptionWrite, transfer_ownership) {}
+StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() {
+ m_file_sp =
+ std::make_shared<File>(fd, File::eOpenOptionWrite, transfer_ownership);
+}
-StreamFile::StreamFile(FILE *fh, bool transfer_ownership)
- : Stream(), m_file(fh, transfer_ownership) {}
+StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() {
+ m_file_sp = std::make_shared<File>(fh, transfer_ownership);
+}
-StreamFile::StreamFile(const char *path) : Stream(), m_file() {
- FileSystem::Instance().Open(m_file, FileSpec(path),
- File::eOpenOptionWrite |
- File::eOpenOptionCanCreate |
- File::eOpenOptionCloseOnExec);
+StreamFile::StreamFile(const char *path) : Stream() {
+ auto file = FileSystem::Instance().Open(
+ FileSpec(path), File::eOpenOptionWrite | File::eOpenOptionCanCreate |
+ File::eOpenOptionCloseOnExec);
+ if (file)
+ m_file_sp = std::move(file.get());
+ else {
+ // TODO refactor this so the error gets popagated up instead of logged here.
+ LLDB_LOG_ERROR(GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST), file.takeError(),
+ "Cannot open {1}: {0}", path);
+ m_file_sp = std::make_shared<File>();
+ }
}
StreamFile::StreamFile(const char *path, uint32_t options, uint32_t permissions)
- : Stream(), m_file() {
-
- FileSystem::Instance().Open(m_file, FileSpec(path), options, permissions);
+ : Stream() {
+ auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions);
+ if (file)
+ m_file_sp = std::move(file.get());
+ else {
+ // TODO refactor this so the error gets popagated up instead of logged here.
+ LLDB_LOG_ERROR(GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST), file.takeError(),
+ "Cannot open {1}: {0}", path);
+ m_file_sp = std::make_shared<File>();
+ }
}
StreamFile::~StreamFile() {}
-void StreamFile::Flush() { m_file.Flush(); }
+void StreamFile::Flush() { m_file_sp->Flush(); }
size_t StreamFile::WriteImpl(const void *s, size_t length) {
- m_file.Write(s, length);
+ m_file_sp->Write(s, length);
return length;
}
OpenPOWER on IntegriCloud