mirror of
https://github.com/intel/llvm.git
synced 2026-01-18 07:57:36 +08:00
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
This commit is contained in:
@@ -6271,22 +6271,23 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
buffer.PutHex32(segment.flags);
|
||||
}
|
||||
|
||||
File core_file;
|
||||
std::string core_file_path(outfile.GetPath());
|
||||
error = FileSystem::Instance().Open(core_file, outfile,
|
||||
File::eOpenOptionWrite |
|
||||
File::eOpenOptionTruncate |
|
||||
File::eOpenOptionCanCreate);
|
||||
if (error.Success()) {
|
||||
auto core_file = FileSystem::Instance().Open(
|
||||
outfile, File::eOpenOptionWrite | File::eOpenOptionTruncate |
|
||||
File::eOpenOptionCanCreate);
|
||||
if (!core_file) {
|
||||
error = core_file.takeError();
|
||||
} else {
|
||||
// Read 1 page at a time
|
||||
uint8_t bytes[0x1000];
|
||||
// Write the mach header and load commands out to the core file
|
||||
size_t bytes_written = buffer.GetString().size();
|
||||
error = core_file.Write(buffer.GetString().data(), bytes_written);
|
||||
error = core_file.get()->Write(buffer.GetString().data(),
|
||||
bytes_written);
|
||||
if (error.Success()) {
|
||||
// Now write the file data for all memory segments in the process
|
||||
for (const auto &segment : segment_load_commands) {
|
||||
if (core_file.SeekFromStart(segment.fileoff) == -1) {
|
||||
if (core_file.get()->SeekFromStart(segment.fileoff) == -1) {
|
||||
error.SetErrorStringWithFormat(
|
||||
"unable to seek to offset 0x%" PRIx64 " in '%s'",
|
||||
segment.fileoff, core_file_path.c_str());
|
||||
@@ -6311,7 +6312,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
|
||||
if (bytes_read == bytes_to_read) {
|
||||
size_t bytes_written = bytes_read;
|
||||
error = core_file.Write(bytes, bytes_written);
|
||||
error = core_file.get()->Write(bytes, bytes_written);
|
||||
bytes_left -= bytes_read;
|
||||
addr += bytes_read;
|
||||
} else {
|
||||
@@ -6319,7 +6320,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
// be zero filled
|
||||
memset(bytes, 0, bytes_to_read);
|
||||
size_t bytes_written = bytes_to_read;
|
||||
error = core_file.Write(bytes, bytes_written);
|
||||
error = core_file.get()->Write(bytes, bytes_written);
|
||||
bytes_left -= bytes_to_read;
|
||||
addr += bytes_to_read;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user