From 14735cab655441ba45c4b88ad82f11267e5fe916 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 28 Jul 2021 20:07:03 +0200 Subject: [PATCH] [lldb] [gdb-remote] Add eOpenOptionReadWrite for future gdb compat Modify OpenOptions enum to open the future path into synchronizing vFile:open bits with GDB. Currently, LLDB and GDB use different flag models effectively making it impossible to match bits. Notably, LLDB uses two bits to indicate read and write status, and uses union of both for read/write. GDB uses a value of 0 for read-only, 1 for write-only and 2 for read/write. In order to future-proof the code for the GDB variant: 1. Add a distinct eOpenOptionReadWrite constant to be used instead of (eOpenOptionRead | eOpenOptionWrite) when R/W access is required. 2. Rename eOpenOptionRead and eOpenOptionWrite to eOpenOptionReadOnly and eOpenOptionWriteOnly respectively, to make it clear that they do not mean to be combined and require update to all call sites. 3. Use the intersection of all three flags when matching against the three possible values. This commit does not change the actual bits used by LLDB. Differential Revision: https://reviews.llvm.org/D106984 --- lldb/docs/lldb-platform-packets.txt | 2 +- lldb/include/lldb/Host/File.h | 11 +++-- lldb/source/API/SBStream.cpp | 2 +- lldb/source/Commands/CommandObjectMemory.cpp | 2 +- lldb/source/Commands/CommandObjectPlatform.cpp | 4 +- lldb/source/Commands/CommandObjectSettings.cpp | 2 +- lldb/source/Commands/CommandObjectTarget.cpp | 4 +- lldb/source/Core/Debugger.cpp | 2 +- lldb/source/Core/StreamFile.cpp | 4 +- lldb/source/Expression/REPL.cpp | 2 +- lldb/source/Host/common/File.cpp | 53 ++++++++++++++-------- lldb/source/Host/common/FileSystem.cpp | 14 +++--- .../Host/posix/ConnectionFileDescriptorPosix.cpp | 20 ++++---- lldb/source/Host/windows/Host.cpp | 2 +- lldb/source/Interpreter/CommandInterpreter.cpp | 4 +- lldb/source/Interpreter/ScriptInterpreter.cpp | 4 +- .../Clang/ClangExpressionParser.cpp | 2 +- .../Clang/ClangUtilityFunction.cpp | 2 +- .../RenderScriptRuntime/RenderScriptRuntime.cpp | 7 +-- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 2 +- .../Plugins/Platform/POSIX/PlatformPOSIX.cpp | 4 +- .../GDBRemoteCommunicationServerCommon.cpp | 4 +- .../Process/gdb-remote/ProcessGDBRemote.cpp | 2 +- .../ScriptInterpreter/Python/PythonDataObjects.cpp | 15 ++++-- lldb/source/Target/ModuleCache.cpp | 2 +- lldb/source/Target/Platform.cpp | 6 +-- lldb/source/Target/Process.cpp | 4 +- lldb/source/Target/Target.cpp | 2 +- lldb/unittests/Host/FileSystemTest.cpp | 2 +- lldb/unittests/Host/FileTest.cpp | 2 +- .../Python/PythonDataObjectsTests.cpp | 4 +- 31 files changed, 110 insertions(+), 82 deletions(-) diff --git a/lldb/docs/lldb-platform-packets.txt b/lldb/docs/lldb-platform-packets.txt index 9a1444a..5d0a399 100644 --- a/lldb/docs/lldb-platform-packets.txt +++ b/lldb/docs/lldb-platform-packets.txt @@ -375,7 +375,7 @@ incompatible with the flags that gdb specifies. // COMPATIBILITY // The gdb-remote serial protocol documentatio defines a vFile:open: // packet which uses incompatible flag values, e.g. 1 means O_WRONLY -// in gdb's vFile:open:, but it means eOpenOptionRead to lldb's +// in gdb's vFile:open:, but it means eOpenOptionReadOnly to lldb's // implementation. //---------------------------------------------------------------------- diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h index d364d95..b928222 100644 --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -44,8 +44,11 @@ public: // * https://sourceware.org/gdb/onlinedocs/gdb/Open-Flags.html#Open-Flags // * rdar://problem/46788934 enum OpenOptions : uint32_t { - eOpenOptionRead = (1u << 0), // Open file for reading - eOpenOptionWrite = (1u << 1), // Open file for writing + eOpenOptionReadOnly = (1u << 0), // Open file for reading (only) + eOpenOptionWriteOnly = (1u << 1), // Open file for writing (only) + eOpenOptionReadWrite = + eOpenOptionReadOnly | + eOpenOptionWriteOnly, // Open file for both reading and writing eOpenOptionAppend = (1u << 2), // Don't truncate file when opening, append to end of file eOpenOptionTruncate = (1u << 3), // Truncate file when opening @@ -303,8 +306,8 @@ public: /// Some options like eOpenOptionDontFollowSymlinks only make /// sense when a file is being opened (or not at all) /// and may not be preserved for this method. But any valid - /// File should return either or both of eOpenOptionRead and - /// eOpenOptionWrite here. + /// File should return either eOpenOptionReadOnly, eOpenOptionWriteOnly + /// or eOpenOptionReadWrite here. /// /// \return /// OpenOptions flags for this file, or an error. diff --git a/lldb/source/API/SBStream.cpp b/lldb/source/API/SBStream.cpp index 66172d2..190abd1 100644 --- a/lldb/source/API/SBStream.cpp +++ b/lldb/source/API/SBStream.cpp @@ -90,7 +90,7 @@ void SBStream::RedirectToFile(const char *path, bool append) { local_data = std::string( static_cast(m_opaque_up.get())->GetString()); } - auto open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate; + auto open_options = File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate; if (append) open_options |= File::eOpenOptionAppend; else diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 5487d94..f27d4bd 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -754,7 +754,7 @@ protected: if (outfile_spec) { File::OpenOptions open_options = - File::eOpenOptionWrite | File::eOpenOptionCanCreate; + File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate; const bool append = m_outfile_options.GetAppend().GetCurrentValue(); open_options |= append ? File::eOpenOptionAppend : File::eOpenOptionTruncate; diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index bf23c45..68e1fa6 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -498,8 +498,8 @@ public: lldb::eFilePermissionsWorldRead; lldb::user_id_t fd = platform_sp->OpenFile( FileSpec(cmd_line), - File::eOpenOptionRead | File::eOpenOptionWrite | - File::eOpenOptionAppend | File::eOpenOptionCanCreate, + File::eOpenOptionReadWrite | File::eOpenOptionAppend | + File::eOpenOptionCanCreate, perms, error); if (error.Success()) { result.AppendMessageWithFormat("File Descriptor = %" PRIu64 "\n", fd); diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index cd79680..13ff27c 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -369,7 +369,7 @@ protected: FileSpec file_spec(m_options.m_filename); FileSystem::Instance().Resolve(file_spec); std::string path(file_spec.GetPath()); - auto options = File::eOpenOptionWrite | File::eOpenOptionCanCreate; + auto options = File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate; if (m_options.m_append) options |= File::eOpenOptionAppend; else diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index ccac874..614ba5a 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -272,7 +272,7 @@ protected: if (core_file) { auto file = FileSystem::Instance().Open( - core_file, lldb_private::File::eOpenOptionRead); + core_file, lldb_private::File::eOpenOptionReadOnly); if (!file) { result.AppendErrorWithFormatv("Cannot open '{0}': {1}.", @@ -286,7 +286,7 @@ protected: FileSpec symfile(m_symbol_file.GetOptionValue().GetCurrentValue()); if (symfile) { auto file = FileSystem::Instance().Open( - symfile, lldb_private::File::eOpenOptionRead); + symfile, lldb_private::File::eOpenOptionReadOnly); if (!file) { result.AppendErrorWithFormatv("Cannot open '{0}': {1}.", diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 17c3ba4..eb092cc 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1243,7 +1243,7 @@ bool Debugger::EnableLog(llvm::StringRef channel, log_stream_sp = pos->second.lock(); if (!log_stream_sp) { File::OpenOptions flags = - File::eOpenOptionWrite | File::eOpenOptionCanCreate; + File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate; if (log_options & LLDB_LOG_OPTION_APPEND) flags |= File::eOpenOptionAppend; else diff --git a/lldb/source/Core/StreamFile.cpp b/lldb/source/Core/StreamFile.cpp index 2f922fe..7753397a 100644 --- a/lldb/source/Core/StreamFile.cpp +++ b/lldb/source/Core/StreamFile.cpp @@ -21,8 +21,8 @@ StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) } StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() { - m_file_sp = - std::make_shared(fd, File::eOpenOptionWrite, transfer_ownership); + m_file_sp = std::make_shared(fd, File::eOpenOptionWriteOnly, + transfer_ownership); } StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() { diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index c3d1496..9cd6129 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -445,7 +445,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { if (!m_repl_source_path.empty()) { auto file = FileSystem::Instance().Open( FileSpec(m_repl_source_path), - File::eOpenOptionWrite | File::eOpenOptionTruncate | + File::eOpenOptionWriteOnly | File::eOpenOptionTruncate | File::eOpenOptionCanCreate, lldb::eFilePermissionsFileDefault); if (file) { diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index e302e0a..b92b4c1 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -41,20 +41,23 @@ using llvm::Expected; Expected File::GetStreamOpenModeFromOptions(File::OpenOptions options) { + File::OpenOptions rw = + options & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly | + File::eOpenOptionReadWrite); + if (options & File::eOpenOptionAppend) { - if (options & File::eOpenOptionRead) { + if (rw == File::eOpenOptionReadWrite) { if (options & File::eOpenOptionCanCreateNewOnly) return "a+x"; else return "a+"; - } else if (options & File::eOpenOptionWrite) { + } else if (rw == File::eOpenOptionWriteOnly) { if (options & File::eOpenOptionCanCreateNewOnly) return "ax"; else return "a"; } - } else if (options & File::eOpenOptionRead && - options & File::eOpenOptionWrite) { + } else if (rw == File::eOpenOptionReadWrite) { if (options & File::eOpenOptionCanCreate) { if (options & File::eOpenOptionCanCreateNewOnly) return "w+x"; @@ -62,10 +65,10 @@ File::GetStreamOpenModeFromOptions(File::OpenOptions options) { return "w+"; } else return "r+"; - } else if (options & File::eOpenOptionRead) { - return "r"; - } else if (options & File::eOpenOptionWrite) { + } else if (rw == File::eOpenOptionWriteOnly) { return "w"; + } else if (rw == File::eOpenOptionReadOnly) { + return "r"; } return llvm::createStringError( llvm::inconvertibleErrorCode(), @@ -75,16 +78,17 @@ File::GetStreamOpenModeFromOptions(File::OpenOptions options) { Expected File::GetOptionsFromMode(llvm::StringRef mode) { OpenOptions opts = llvm::StringSwitch(mode) - .Cases("r", "rb", eOpenOptionRead) - .Cases("w", "wb", eOpenOptionWrite) + .Cases("r", "rb", eOpenOptionReadOnly) + .Cases("w", "wb", eOpenOptionWriteOnly) .Cases("a", "ab", - eOpenOptionWrite | eOpenOptionAppend | eOpenOptionCanCreate) - .Cases("r+", "rb+", "r+b", eOpenOptionRead | eOpenOptionWrite) + eOpenOptionWriteOnly | eOpenOptionAppend | + eOpenOptionCanCreate) + .Cases("r+", "rb+", "r+b", eOpenOptionReadWrite) .Cases("w+", "wb+", "w+b", - eOpenOptionRead | eOpenOptionWrite | eOpenOptionCanCreate | - eOpenOptionTruncate) + eOpenOptionReadWrite | eOpenOptionCanCreate | + eOpenOptionTruncate) .Cases("a+", "ab+", "a+b", - eOpenOptionRead | eOpenOptionWrite | eOpenOptionAppend | + eOpenOptionReadWrite | eOpenOptionAppend | eOpenOptionCanCreate) .Default(OpenOptions()); if (opts) @@ -310,9 +314,15 @@ Status NativeFile::Close() { if (m_own_stream) { if (::fclose(m_stream) == EOF) error.SetErrorToErrno(); - } else if (m_options & eOpenOptionWrite) { - if (::fflush(m_stream) == EOF) - error.SetErrorToErrno(); + } else { + File::OpenOptions rw = + m_options & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly | + File::eOpenOptionReadWrite); + + if (rw == eOpenOptionWriteOnly || rw == eOpenOptionReadWrite) { + if (::fflush(m_stream) == EOF) + error.SetErrorToErrno(); + } } } if (DescriptorIsValid() && m_own_descriptor) { @@ -732,10 +742,15 @@ size_t NativeFile::PrintfVarArg(const char *format, va_list args) { mode_t File::ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options) { mode_t mode = 0; - if (open_options & eOpenOptionRead && open_options & eOpenOptionWrite) + File::OpenOptions rw = + open_options & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly | + File::eOpenOptionReadWrite); + if (rw == eOpenOptionReadWrite) mode |= O_RDWR; - else if (open_options & eOpenOptionWrite) + else if (rw == eOpenOptionWriteOnly) mode |= O_WRONLY; + else if (rw == eOpenOptionReadOnly) + mode |= O_RDONLY; if (open_options & eOpenOptionAppend) mode |= O_APPEND; diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index a2c3b35..7687ad6 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -381,13 +381,13 @@ static int OpenWithFS(const FileSystem &fs, const char *path, int flags, return const_cast(fs).Open(path, flags, mode); } -static int GetOpenFlags(uint32_t options) { - const bool read = options & File::eOpenOptionRead; - const bool write = options & File::eOpenOptionWrite; - +static int GetOpenFlags(File::OpenOptions options) { int open_flags = 0; - if (write) { - if (read) + File::OpenOptions rw = + options & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly | + File::eOpenOptionReadWrite); + if (rw == File::eOpenOptionWriteOnly || rw == File::eOpenOptionReadWrite) { + if (rw == File::eOpenOptionReadWrite) open_flags |= O_RDWR; else open_flags |= O_WRONLY; @@ -403,7 +403,7 @@ static int GetOpenFlags(uint32_t options) { if (options & File::eOpenOptionCanCreateNewOnly) open_flags |= O_CREAT | O_EXCL; - } else if (read) { + } else if (rw == File::eOpenOptionReadOnly) { open_flags |= O_RDONLY; #ifndef _WIN32 diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index 2f4cc96..0a9c83d 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -87,8 +87,10 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit) ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd) : Connection(), m_pipe(), m_mutex(), m_shutting_down(false), m_waiting_for_accept(false), m_child_processes_inherit(false) { - m_write_sp = std::make_shared(fd, File::eOpenOptionWrite, owns_fd); - m_read_sp = std::make_shared(fd, File::eOpenOptionRead, false); + m_write_sp = + std::make_shared(fd, File::eOpenOptionWriteOnly, owns_fd); + m_read_sp = + std::make_shared(fd, File::eOpenOptionReadOnly, false); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); @@ -219,10 +221,10 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path, m_read_sp = std::move(tcp_socket); m_write_sp = m_read_sp; } else { - m_read_sp = - std::make_shared(fd, File::eOpenOptionRead, false); - m_write_sp = - std::make_shared(fd, File::eOpenOptionWrite, false); + m_read_sp = std::make_shared( + fd, File::eOpenOptionReadOnly, false); + m_write_sp = std::make_shared( + fd, File::eOpenOptionWriteOnly, false); } m_uri = std::string(*addr); return eConnectionStatusSuccess; @@ -271,8 +273,10 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path, ::fcntl(fd, F_SETFL, flags); } } - m_read_sp = std::make_shared(fd, File::eOpenOptionRead, true); - m_write_sp = std::make_shared(fd, File::eOpenOptionWrite, false); + m_read_sp = + std::make_shared(fd, File::eOpenOptionReadOnly, true); + m_write_sp = + std::make_shared(fd, File::eOpenOptionWriteOnly, false); return eConnectionStatusSuccess; } #endif diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index f663b35..fbfc535 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -35,7 +35,7 @@ bool GetTripleForProcess(const FileSpec &executable, llvm::Triple &triple) { // Open the PE File as a binary file, and parse just enough information to // determine the machine type. auto imageBinaryP = FileSystem::Instance().Open( - executable, File::eOpenOptionRead, lldb::eFilePermissionsUserRead); + executable, File::eOpenOptionReadOnly, lldb::eFilePermissionsUserRead); if (!imageBinaryP) return llvm::errorToBool(imageBinaryP.takeError()); File &imageBinary = *imageBinaryP.get(); diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 00e9ccb..5a9b7f0 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2433,7 +2433,7 @@ void CommandInterpreter::HandleCommandsFromFile(FileSpec &cmd_file, std::string cmd_file_path = cmd_file.GetPath(); auto input_file_up = - FileSystem::Instance().Open(cmd_file, File::eOpenOptionRead); + FileSystem::Instance().Open(cmd_file, File::eOpenOptionReadOnly); if (!input_file_up) { std::string error = llvm::toString(input_file_up.takeError()); result.AppendErrorWithFormatv( @@ -2954,7 +2954,7 @@ bool CommandInterpreter::SaveTranscript( return false; }; - File::OpenOptions flags = File::eOpenOptionWrite | + File::OpenOptions flags = File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate | File::eOpenOptionTruncate; diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index f264748..ac0a52d 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -141,12 +141,12 @@ ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger, new ScriptInterpreterIORedirect(debugger, result)); auto nullin = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL), - File::eOpenOptionRead); + File::eOpenOptionReadOnly); if (!nullin) return nullin.takeError(); auto nullout = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL), - File::eOpenOptionWrite); + File::eOpenOptionWriteOnly); if (!nullout) return nullin.takeError(); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index 0b5e1ab..d9ab17e 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -1069,7 +1069,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager, } if (temp_fd != -1) { - lldb_private::NativeFile file(temp_fd, File::eOpenOptionWrite, true); + lldb_private::NativeFile file(temp_fd, File::eOpenOptionWriteOnly, true); const size_t expr_text_len = strlen(expr_text); size_t bytes_written = expr_text_len; if (file.Write(expr_text, bytes_written).Success()) { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp index 363ca2e..3db3fce 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp @@ -45,7 +45,7 @@ ClangUtilityFunction::ClangUtilityFunction(ExecutionContextScope &exe_scope, llvm::SmallString<128> result_path; llvm::sys::fs::createTemporaryFile("lldb", "expr", temp_fd, result_path); if (temp_fd != -1) { - lldb_private::NativeFile file(temp_fd, File::eOpenOptionWrite, true); + lldb_private::NativeFile file(temp_fd, File::eOpenOptionWriteOnly, true); text = "#line 1 \"" + std::string(result_path) + "\"\n" + text; size_t bytes_written = text.size(); file.Write(text.c_str(), bytes_written); diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index 10ff5aa..4f47006 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -2660,7 +2660,7 @@ bool RenderScriptRuntime::SaveAllocation(Stream &strm, const uint32_t alloc_id, FileSpec file_spec(path); FileSystem::Instance().Resolve(file_spec); auto file = FileSystem::Instance().Open( - file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate | + file_spec, File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate | File::eOpenOptionTruncate); if (!file) { @@ -4585,8 +4585,9 @@ public: if (outfile_spec) { // Open output file std::string path = outfile_spec.GetPath(); - auto file = FileSystem::Instance().Open( - outfile_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate); + auto file = FileSystem::Instance().Open(outfile_spec, + File::eOpenOptionWriteOnly | + File::eOpenOptionCanCreate); if (file) { output_stream_storage = std::make_unique(std::move(file.get())); diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index e5ee132..ce53249 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -6825,7 +6825,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp, std::string core_file_path(outfile.GetPath()); auto core_file = FileSystem::Instance().Open( - outfile, File::eOpenOptionWrite | File::eOpenOptionTruncate | + outfile, File::eOpenOptionWriteOnly | File::eOpenOptionTruncate | File::eOpenOptionCanCreate); if (!core_file) { error = core_file.takeError(); diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index 7353132..71917af 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -205,7 +205,7 @@ lldb_private::Status PlatformPOSIX::GetFile( // close dst LLDB_LOGF(log, "[GetFile] Using block by block transfer....\n"); Status error; - user_id_t fd_src = OpenFile(source, File::eOpenOptionRead, + user_id_t fd_src = OpenFile(source, File::eOpenOptionReadOnly, lldb::eFilePermissionsFileDefault, error); if (fd_src == UINT64_MAX) @@ -218,7 +218,7 @@ lldb_private::Status PlatformPOSIX::GetFile( permissions = lldb::eFilePermissionsFileDefault; user_id_t fd_dst = FileCache::GetInstance().OpenFile( - destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | + destination, File::eOpenOptionCanCreate | File::eOpenOptionWriteOnly | File::eOpenOptionTruncate, permissions, error); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index b2b80255..b81b14f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -575,7 +575,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_pRead( } std::string buffer(count, 0); - NativeFile file(fd, File::eOpenOptionRead, false); + NativeFile file(fd, File::eOpenOptionReadOnly, false); Status error = file.Read(static_cast(&buffer[0]), count, offset); const ssize_t bytes_read = error.Success() ? count : -1; const int save_errno = error.GetError(); @@ -607,7 +607,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite( if (packet.GetChar() == ',') { std::string buffer; if (packet.GetEscapedBinaryData(buffer)) { - NativeFile file(fd, File::eOpenOptionWrite, false); + NativeFile file(fd, File::eOpenOptionWriteOnly, false); size_t count = buffer.size(); Status error = file.Write(static_cast(&buffer[0]), count, offset); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 6914b37..a2f0fd9 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -104,7 +104,7 @@ namespace lldb { // and get the packet history dumped to a file. void DumpProcessGDBRemotePacketHistory(void *p, const char *path) { auto file = FileSystem::Instance().Open( - FileSpec(path), File::eOpenOptionWrite | File::eOpenOptionCanCreate); + FileSpec(path), File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate); if (!file) { llvm::consumeError(file.takeError()); return; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index f51d9b3..9b75082 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -1114,10 +1114,12 @@ GetOptionsForPyObject(const PythonObject &obj) { auto writable = As(obj.CallMethod("writable")); if (!writable) return writable.takeError(); - if (readable.get()) - options |= File::eOpenOptionRead; - if (writable.get()) - options |= File::eOpenOptionWrite; + if (readable.get() && writable.get()) + options |= File::eOpenOptionReadWrite; + else if (writable.get()) + options |= File::eOpenOptionWriteOnly; + else if (readable.get()) + options |= File::eOpenOptionReadOnly; return options; #else PythonString py_mode = obj.GetAttributeValue("mode").AsType(); @@ -1413,7 +1415,10 @@ llvm::Expected PythonFile::ConvertToFile(bool borrowed) { if (!options) return options.takeError(); - if (options.get() & File::eOpenOptionWrite) { + File::OpenOptions rw = + options.get() & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly | + File::eOpenOptionReadWrite); + if (rw == File::eOpenOptionWriteOnly || rw == File::eOpenOptionReadWrite) { // LLDB and python will not share I/O buffers. We should probably // flush the python buffers now. auto r = CallMethod("flush"); diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp index dcdc077..7143fcd 100644 --- a/lldb/source/Target/ModuleCache.cpp +++ b/lldb/source/Target/ModuleCache.cpp @@ -159,7 +159,7 @@ ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid, m_file_spec = JoinPath(lock_dir_spec, uuid.GetAsString().c_str()); auto file = FileSystem::Instance().Open( - m_file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate | + m_file_spec, File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate | File::eOpenOptionCloseOnExec); if (file) m_file_up = std::move(file.get()); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index a77ecdd..23141c2 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1225,7 +1225,7 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination, LLDB_LOGF(log, "[PutFile] Using block by block transfer....\n"); auto source_open_options = - File::eOpenOptionRead | File::eOpenOptionCloseOnExec; + File::eOpenOptionReadOnly | File::eOpenOptionCloseOnExec; namespace fs = llvm::sys::fs; if (fs::is_symlink_file(source.GetPath())) source_open_options |= File::eOpenOptionDontFollowSymlinks; @@ -1240,7 +1240,7 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination, permissions = lldb::eFilePermissionsFileDefault; lldb::user_id_t dest_file = OpenFile( - destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | + destination, File::eOpenOptionCanCreate | File::eOpenOptionWriteOnly | File::eOpenOptionTruncate | File::eOpenOptionCloseOnExec, permissions, error); LLDB_LOGF(log, "dest_file = %" PRIu64 "\n", dest_file); @@ -1663,7 +1663,7 @@ Status Platform::DownloadModuleSlice(const FileSpec &src_file_spec, return error; } - auto src_fd = OpenFile(src_file_spec, File::eOpenOptionRead, + auto src_fd = OpenFile(src_file_spec, File::eOpenOptionReadOnly, lldb::eFilePermissionsFileDefault, error); if (error.Fail()) { diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 8ecc66b..267c3ee 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -4310,8 +4310,8 @@ public: : IOHandler(process->GetTarget().GetDebugger(), IOHandler::Type::ProcessIO), m_process(process), - m_read_file(GetInputFD(), File::eOpenOptionRead, false), - m_write_file(write_fd, File::eOpenOptionWrite, false) { + m_read_file(GetInputFD(), File::eOpenOptionReadOnly, false), + m_write_file(write_fd, File::eOpenOptionWriteOnly, false) { m_pipe.CreateNew(false); } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 1f8e8c5..d21935c 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1022,7 +1022,7 @@ Status Target::SerializeBreakpointsToFile(const FileSpec &file, } StreamFile out_file(path.c_str(), - File::eOpenOptionTruncate | File::eOpenOptionWrite | + File::eOpenOptionTruncate | File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate | File::eOpenOptionCloseOnExec, lldb::eFilePermissionsFileDefault); diff --git a/lldb/unittests/Host/FileSystemTest.cpp b/lldb/unittests/Host/FileSystemTest.cpp index f31c5c4..637e3b4 100644 --- a/lldb/unittests/Host/FileSystemTest.cpp +++ b/lldb/unittests/Host/FileSystemTest.cpp @@ -296,7 +296,7 @@ TEST(FileSystemTest, OpenErrno) { FileSpec spec("/file/that/does/not/exist.txt"); #endif FileSystem fs; - auto file = fs.Open(spec, File::eOpenOptionRead, 0, true); + auto file = fs.Open(spec, File::eOpenOptionReadOnly, 0, true); ASSERT_FALSE(file); std::error_code code = errorToErrorCode(file.takeError()); EXPECT_EQ(code.category(), std::system_category()); diff --git a/lldb/unittests/Host/FileTest.cpp b/lldb/unittests/Host/FileTest.cpp index 126d5e3..35c87bb 100644 --- a/lldb/unittests/Host/FileTest.cpp +++ b/lldb/unittests/Host/FileTest.cpp @@ -46,7 +46,7 @@ TEST(File, GetStreamFromDescriptor) { llvm::FileRemover remover(name); ASSERT_GE(fd, 0); - NativeFile file(fd, File::eOpenOptionWrite, true); + NativeFile file(fd, File::eOpenOptionWriteOnly, true); ASSERT_TRUE(file.IsValid()); FILE *stream = file.GetStream(); diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp index 75a1f5e..9bfbb37 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -583,7 +583,7 @@ TEST_F(PythonDataObjectsTest, TestPythonCallableInvoke) { TEST_F(PythonDataObjectsTest, TestPythonFile) { auto file = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL), - File::eOpenOptionRead); + File::eOpenOptionReadOnly); ASSERT_THAT_EXPECTED(file, llvm::Succeeded()); auto py_file = PythonFile::FromFile(*file.get(), "r"); ASSERT_THAT_EXPECTED(py_file, llvm::Succeeded()); @@ -858,4 +858,4 @@ g = foobar() ASSERT_THAT_EXPECTED(r, llvm::Succeeded()); auto g = As(globals.GetItem("g")); ASSERT_THAT_EXPECTED(g, llvm::HasValue("foobarbaz")); -} \ No newline at end of file +} -- 2.7.4