[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
This commit is contained in:
Michał Górny 2021-07-28 20:07:03 +02:00
parent 8a7c657c4d
commit 14735cab65
31 changed files with 110 additions and 82 deletions

View File

@ -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.
//----------------------------------------------------------------------

View File

@ -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.

View File

@ -90,7 +90,7 @@ void SBStream::RedirectToFile(const char *path, bool append) {
local_data = std::string(
static_cast<StreamString *>(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

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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}.",

View File

@ -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

View File

@ -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<NativeFile>(fd, File::eOpenOptionWrite, transfer_ownership);
m_file_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionWriteOnly,
transfer_ownership);
}
StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() {

View File

@ -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) {

View File

@ -41,20 +41,23 @@ using llvm::Expected;
Expected<const char *>
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::OpenOptions> File::GetOptionsFromMode(llvm::StringRef mode) {
OpenOptions opts =
llvm::StringSwitch<OpenOptions>(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;

View File

@ -381,13 +381,13 @@ static int OpenWithFS(const FileSystem &fs, const char *path, int flags,
return const_cast<FileSystem &>(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

View File

@ -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<NativeFile>(fd, File::eOpenOptionWrite, owns_fd);
m_read_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionRead, false);
m_write_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionWriteOnly, owns_fd);
m_read_sp =
std::make_shared<NativeFile>(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<NativeFile>(fd, File::eOpenOptionRead, false);
m_write_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionWrite, false);
m_read_sp = std::make_shared<NativeFile>(
fd, File::eOpenOptionReadOnly, false);
m_write_sp = std::make_shared<NativeFile>(
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<NativeFile>(fd, File::eOpenOptionRead, true);
m_write_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionWrite, false);
m_read_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionReadOnly, true);
m_write_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionWriteOnly, false);
return eConnectionStatusSuccess;
}
#endif

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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()) {

View File

@ -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);

View File

@ -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<StreamFile>(std::move(file.get()));

View File

@ -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();

View File

@ -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);

View File

@ -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<void *>(&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<const void *>(&buffer[0]), count, offset);

View File

@ -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;

View File

@ -1114,10 +1114,12 @@ GetOptionsForPyObject(const PythonObject &obj) {
auto writable = As<bool>(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<PythonString>();
@ -1413,7 +1415,10 @@ llvm::Expected<FileSP> 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");

View File

@ -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());

View File

@ -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()) {

View File

@ -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);
}

View File

@ -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);

View File

@ -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());

View File

@ -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();

View File

@ -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<std::string>(globals.GetItem("g"));
ASSERT_THAT_EXPECTED(g, llvm::HasValue("foobarbaz"));
}
}