From 3a14249525235d9d2bcbc0e931759d083bcdb0d1 Mon Sep 17 00:00:00 2001 From: Aaron Smith Date: Thu, 7 Feb 2019 18:46:25 +0000 Subject: [lldb-server] Improve support on Windows Summary: This commit contains the following changes: - Rewrite vfile close/read/write packet handlers with portable routines from lldb. This removes #if(s) and allows the handlers to work on Windows. - Fix a bug in File::Write. This is intended to write data at an offset to a file but actually writes at the current position of the file. - Add a default boolean argument 'should_close_fd' to FileSystem::Open to let the user decide whether to close the fd or not. Reviewers: zturner, llvm-commits, labath Reviewed By: zturner Subscribers: Hui, labath, abidh, lldb-commits Differential Revision: https://reviews.llvm.org/D56231 llvm-svn: 353446 --- lldb/source/Host/common/File.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lldb/source/Host/common/File.cpp') diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index dba6e08acb3..512e7c58702 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -178,7 +178,7 @@ Status File::Close() { void File::Clear() { m_stream = nullptr; - m_descriptor = -1; + m_descriptor = kInvalidDescriptor; m_options = 0; m_own_stream = false; m_is_interactive = m_supports_colors = m_is_real_terminal = @@ -503,6 +503,7 @@ Status File::Read(void *buf, size_t &num_bytes, off_t &offset) { error.SetErrorString("invalid file handle"); } #else + std::lock_guard guard(offset_access_mutex); long cur = ::lseek(m_descriptor, 0, SEEK_CUR); SeekFromStart(offset); error = Read(buf, num_bytes); @@ -602,7 +603,9 @@ Status File::Write(const void *buf, size_t &num_bytes, off_t &offset) { num_bytes = bytes_written; } #else + std::lock_guard guard(offset_access_mutex); long cur = ::lseek(m_descriptor, 0, SEEK_CUR); + SeekFromStart(offset); error = Write(buf, num_bytes); long after = ::lseek(m_descriptor, 0, SEEK_CUR); -- cgit v1.2.3