diff options
author | emaste <emaste@FreeBSD.org> | 2015-07-04 01:02:43 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-07-04 01:02:43 +0000 |
commit | cea4c167517a0678c7dbf92a0324088dcbac1035 (patch) | |
tree | 02de7f7c9d5a08ae1c4d3b4c98a565ff96cd52e6 /contrib/llvm/tools/lldb/source/Host/common/File.cpp | |
parent | 1756896fd2b99ede7ebeb8019d4004bdfeed3bbe (diff) | |
parent | 8037fa4ee916fa20b3c63cbf531f4ee7e1c76138 (diff) | |
download | FreeBSD-src-cea4c167517a0678c7dbf92a0324088dcbac1035.zip FreeBSD-src-cea4c167517a0678c7dbf92a0324088dcbac1035.tar.gz |
Update LLDB snapshot to upstream r241361
Notable upstream commits (upstream revision in parens):
- Add a JSON producer to LLDB (228636)
- Don't crash on bad DWARF expression (228729)
- Add support of DWARFv3 DW_OP_form_tls_address (231342)
- Assembly profiler for MIPS64 (232619)
- Handle FreeBSD/arm64 core files (233273)
- Read/Write register for MIPS64 (233685)
- Rework LLDB system initialization (233758)
- SysV ABI for aarch64 (236098)
- MIPS software single stepping (236696)
- FreeBSD/arm live debugging support (237303)
- Assembly profiler for mips32 (237420)
- Parse function name from DWARF DW_AT_abstract_origin (238307)
- Improve LLDB prompt handling (238313)
- Add real time signals support to FreeBSDSignals (238316)
- Fix race in IOHandlerProcessSTDIO (238423)
- MIPS64 Branch instruction emulation for SW single stepping (238820)
- Improve OSType initialization in elf object file's arch_spec (239148)
- Emulation of MIPS64 floating-point branch instructions (239996)
- ABI Plugin for MIPS32 (239997)
- ABI Plugin for MIPS64 (240123)
- MIPS32 branch emulation and single stepping (240373)
- Improve instruction emulation based stack unwinding on ARM (240533)
- Add branch emulation to aarch64 instruction emulator (240769)
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Host/common/File.cpp')
-rw-r--r-- | contrib/llvm/tools/lldb/source/Host/common/File.cpp | 169 |
1 files changed, 152 insertions, 17 deletions
diff --git a/contrib/llvm/tools/lldb/source/Host/common/File.cpp b/contrib/llvm/tools/lldb/source/Host/common/File.cpp index c3c7783..a3420bf 100644 --- a/contrib/llvm/tools/lldb/source/Host/common/File.cpp +++ b/contrib/llvm/tools/lldb/source/Host/common/File.cpp @@ -288,6 +288,8 @@ File::Open (const char *path, uint32_t options, uint32_t permissions) #ifndef _WIN32 if (options & eOpenOptionNonBlocking) oflag |= O_NONBLOCK; + if (options & eOpenOptionCloseOnExec) + oflag |= O_CLOEXEC; #else oflag |= O_BINARY; #endif @@ -323,12 +325,12 @@ File::Open (const char *path, uint32_t options, uint32_t permissions) } uint32_t -File::GetPermissions (const char *path, Error &error) +File::GetPermissions(const FileSpec &file_spec, Error &error) { - if (path && path[0]) + if (file_spec) { struct stat file_stats; - if (::stat (path, &file_stats) == -1) + if (::stat(file_spec.GetCString(), &file_stats) == -1) error.SetErrorToErrno(); else { @@ -337,12 +339,7 @@ File::GetPermissions (const char *path, Error &error) } } else - { - if (path) - error.SetErrorString ("invalid path"); - else - error.SetErrorString ("empty path"); - } + error.SetErrorString ("empty file spec"); return 0; } @@ -593,10 +590,49 @@ File::Sync () return error; } +#if defined (__APPLE__) +// Darwin kernels only can read/write <= INT_MAX bytes +#define MAX_READ_SIZE INT_MAX +#define MAX_WRITE_SIZE INT_MAX +#endif + Error File::Read (void *buf, size_t &num_bytes) { Error error; + +#if defined (MAX_READ_SIZE) + if (num_bytes > MAX_READ_SIZE) + { + uint8_t *p = (uint8_t *)buf; + size_t bytes_left = num_bytes; + // Init the num_bytes read to zero + num_bytes = 0; + + while (bytes_left > 0) + { + size_t curr_num_bytes; + if (bytes_left > MAX_READ_SIZE) + curr_num_bytes = MAX_READ_SIZE; + else + curr_num_bytes = bytes_left; + + error = Read (p + num_bytes, curr_num_bytes); + + // Update how many bytes were read + num_bytes += curr_num_bytes; + if (bytes_left < curr_num_bytes) + bytes_left = 0; + else + bytes_left -= curr_num_bytes; + + if (error.Fail()) + break; + } + return error; + } +#endif + ssize_t bytes_read = -1; if (DescriptorIsValid()) { @@ -640,6 +676,39 @@ Error File::Write (const void *buf, size_t &num_bytes) { Error error; + +#if defined (MAX_WRITE_SIZE) + if (num_bytes > MAX_WRITE_SIZE) + { + const uint8_t *p = (const uint8_t *)buf; + size_t bytes_left = num_bytes; + // Init the num_bytes written to zero + num_bytes = 0; + + while (bytes_left > 0) + { + size_t curr_num_bytes; + if (bytes_left > MAX_WRITE_SIZE) + curr_num_bytes = MAX_WRITE_SIZE; + else + curr_num_bytes = bytes_left; + + error = Write (p + num_bytes, curr_num_bytes); + + // Update how many bytes were read + num_bytes += curr_num_bytes; + if (bytes_left < curr_num_bytes) + bytes_left = 0; + else + bytes_left -= curr_num_bytes; + + if (error.Fail()) + break; + } + return error; + } +#endif + ssize_t bytes_written = -1; if (DescriptorIsValid()) { @@ -685,8 +754,41 @@ File::Write (const void *buf, size_t &num_bytes) Error File::Read (void *buf, size_t &num_bytes, off_t &offset) { -#ifndef _WIN32 Error error; + +#if defined (MAX_READ_SIZE) + if (num_bytes > MAX_READ_SIZE) + { + uint8_t *p = (uint8_t *)buf; + size_t bytes_left = num_bytes; + // Init the num_bytes read to zero + num_bytes = 0; + + while (bytes_left > 0) + { + size_t curr_num_bytes; + if (bytes_left > MAX_READ_SIZE) + curr_num_bytes = MAX_READ_SIZE; + else + curr_num_bytes = bytes_left; + + error = Read (p + num_bytes, curr_num_bytes, offset); + + // Update how many bytes were read + num_bytes += curr_num_bytes; + if (bytes_left < curr_num_bytes) + bytes_left = 0; + else + bytes_left -= curr_num_bytes; + + if (error.Fail()) + break; + } + return error; + } +#endif + +#ifndef _WIN32 int fd = GetDescriptor(); if (fd != kInvalidDescriptor) { @@ -712,15 +814,14 @@ File::Read (void *buf, size_t &num_bytes, off_t &offset) num_bytes = 0; error.SetErrorString("invalid file handle"); } - return error; #else long cur = ::lseek(m_descriptor, 0, SEEK_CUR); SeekFromStart(offset); - Error error = Read(buf, num_bytes); + error = Read(buf, num_bytes); if (!error.Fail()) SeekFromStart(cur); - return error; #endif + return error; } Error @@ -742,8 +843,10 @@ File::Read (size_t &num_bytes, off_t &offset, bool null_terminate, DataBufferSP if (num_bytes > bytes_left) num_bytes = bytes_left; + size_t num_bytes_plus_nul_char = num_bytes + (null_terminate ? 1 : 0); std::unique_ptr<DataBufferHeap> data_heap_ap; - data_heap_ap.reset(new DataBufferHeap(num_bytes + (null_terminate ? 1 : 0), '\0')); + data_heap_ap.reset(new DataBufferHeap()); + data_heap_ap->SetByteSize(num_bytes_plus_nul_char); if (data_heap_ap.get()) { @@ -752,8 +855,8 @@ File::Read (size_t &num_bytes, off_t &offset, bool null_terminate, DataBufferSP { // Make sure we read exactly what we asked for and if we got // less, adjust the array - if (num_bytes < data_heap_ap->GetByteSize()) - data_heap_ap->SetByteSize(num_bytes); + if (num_bytes_plus_nul_char < data_heap_ap->GetByteSize()) + data_heap_ap->SetByteSize(num_bytes_plus_nul_char); data_buffer_sp.reset(data_heap_ap.release()); return error; } @@ -780,6 +883,39 @@ Error File::Write (const void *buf, size_t &num_bytes, off_t &offset) { Error error; + +#if defined (MAX_WRITE_SIZE) + if (num_bytes > MAX_WRITE_SIZE) + { + const uint8_t *p = (const uint8_t *)buf; + size_t bytes_left = num_bytes; + // Init the num_bytes written to zero + num_bytes = 0; + + while (bytes_left > 0) + { + size_t curr_num_bytes; + if (bytes_left > MAX_WRITE_SIZE) + curr_num_bytes = MAX_WRITE_SIZE; + else + curr_num_bytes = bytes_left; + + error = Write (p + num_bytes, curr_num_bytes, offset); + + // Update how many bytes were read + num_bytes += curr_num_bytes; + if (bytes_left < curr_num_bytes) + bytes_left = 0; + else + bytes_left -= curr_num_bytes; + + if (error.Fail()) + break; + } + return error; + } +#endif + int fd = GetDescriptor(); if (fd != kInvalidDescriptor) { @@ -808,7 +944,6 @@ File::Write (const void *buf, size_t &num_bytes, off_t &offset) if (!error.Fail()) SeekFromStart(cur); - ssize_t bytes_written = after - cur; offset = after; #endif } |