[Lldb-commits] [lldb] r374817 - uint32_t options -> File::OpenOptions options
Lawrence D'Anna via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 14 13:15:34 PDT 2019
Author: lawrence_danna
Date: Mon Oct 14 13:15:34 2019
New Revision: 374817
URL: http://llvm.org/viewvc/llvm-project?rev=374817&view=rev
Log:
uint32_t options -> File::OpenOptions options
Summary:
This patch re-types everywhere that passes a File::OpenOptions
as a uint32_t so it actually uses File::OpenOptions.
It also converts some OpenOptions related functions that fail
by returning 0 or NULL into llvm::Expected
split off from https://reviews.llvm.org/D68737
Reviewers: JDevlieghere, jasonmolenda, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D68853
Modified:
lldb/trunk/include/lldb/Core/StreamFile.h
lldb/trunk/include/lldb/Host/File.h
lldb/trunk/include/lldb/Host/FileCache.h
lldb/trunk/include/lldb/Host/FileSystem.h
lldb/trunk/include/lldb/Target/Platform.h
lldb/trunk/include/lldb/Target/RemoteAwarePlatform.h
lldb/trunk/source/API/SBFile.cpp
lldb/trunk/source/API/SBStream.cpp
lldb/trunk/source/Commands/CommandObjectMemory.cpp
lldb/trunk/source/Commands/CommandObjectSettings.cpp
lldb/trunk/source/Core/StreamFile.cpp
lldb/trunk/source/Host/common/File.cpp
lldb/trunk/source/Host/common/FileCache.cpp
lldb/trunk/source/Host/common/FileSystem.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/source/Target/RemoteAwarePlatform.cpp
lldb/trunk/source/Target/Target.cpp
Modified: lldb/trunk/include/lldb/Core/StreamFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StreamFile.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/StreamFile.h (original)
+++ lldb/trunk/include/lldb/Core/StreamFile.h Mon Oct 14 13:15:34 2019
@@ -30,7 +30,7 @@ public:
StreamFile(const char *path);
- StreamFile(const char *path, uint32_t options,
+ StreamFile(const char *path, File::OpenOptions options,
uint32_t permissions = lldb::eFilePermissionsFileDefault);
StreamFile(FILE *fh, bool transfer_ownership);
Modified: lldb/trunk/include/lldb/Host/File.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/File.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/File.h (original)
+++ lldb/trunk/include/lldb/Host/File.h Mon Oct 14 13:15:34 2019
@@ -13,6 +13,7 @@
#include "lldb/Utility/IOObject.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-private.h"
+#include "llvm/ADT/BitmaskEnum.h"
#include <mutex>
#include <stdarg.h>
@@ -21,6 +22,8 @@
namespace lldb_private {
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+
/// \class File File.h "lldb/Host/File.h"
/// An abstract base class for files.
///
@@ -35,7 +38,12 @@ public:
// NB this enum is used in the lldb platform gdb-remote packet
// vFile:open: and existing values cannot be modified.
- enum OpenOptions {
+ //
+ // FIXME
+ // These values do not match the values used by GDB
+ // * 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
eOpenOptionAppend =
@@ -47,11 +55,12 @@ public:
(1u << 6), // Can create file only if it doesn't already exist
eOpenOptionDontFollowSymlinks = (1u << 7),
eOpenOptionCloseOnExec =
- (1u << 8) // Close the file when executing a new process
+ (1u << 8), // Close the file when executing a new process
+ LLVM_MARK_AS_BITMASK_ENUM(/* largest_value= */ eOpenOptionCloseOnExec)
};
- static mode_t ConvertOpenOptionsForPOSIXOpen(uint32_t open_options);
- static uint32_t GetOptionsFromMode(llvm::StringRef mode);
+ static mode_t ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options);
+ static llvm::Expected<OpenOptions> GetOptionsFromMode(llvm::StringRef mode);
static bool DescriptorIsValid(int descriptor) { return descriptor >= 0; };
File()
@@ -358,13 +367,13 @@ class NativeFile : public File {
public:
NativeFile()
: m_descriptor(kInvalidDescriptor), m_own_descriptor(false),
- m_stream(kInvalidStream), m_options(0), m_own_stream(false) {}
+ m_stream(kInvalidStream), m_options(), m_own_stream(false) {}
NativeFile(FILE *fh, bool transfer_ownership)
: m_descriptor(kInvalidDescriptor), m_own_descriptor(false), m_stream(fh),
- m_options(0), m_own_stream(transfer_ownership) {}
+ m_options(), m_own_stream(transfer_ownership) {}
- NativeFile(int fd, uint32_t options, bool transfer_ownership)
+ NativeFile(int fd, OpenOptions options, bool transfer_ownership)
: m_descriptor(fd), m_own_descriptor(transfer_ownership),
m_stream(kInvalidStream), m_options(options), m_own_stream(false) {}
@@ -401,7 +410,7 @@ protected:
int m_descriptor;
bool m_own_descriptor;
FILE *m_stream;
- uint32_t m_options;
+ OpenOptions m_options;
bool m_own_stream;
std::mutex offset_access_mutex;
Modified: lldb/trunk/include/lldb/Host/FileCache.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileCache.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileCache.h (original)
+++ lldb/trunk/include/lldb/Host/FileCache.h Mon Oct 14 13:15:34 2019
@@ -14,6 +14,7 @@
#include "lldb/lldb-forward.h"
#include "lldb/lldb-types.h"
+#include "lldb/Host/File.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
@@ -27,7 +28,7 @@ private:
public:
static FileCache &GetInstance();
- lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
+ lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
uint32_t mode, Status &error);
bool CloseFile(lldb::user_id_t fd, Status &error);
Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Mon Oct 14 13:15:34 2019
@@ -64,7 +64,7 @@ public:
int Open(const char *path, int flags, int mode);
llvm::Expected<std::unique_ptr<File>>
- Open(const FileSpec &file_spec, uint32_t options,
+ Open(const FileSpec &file_spec, File::OpenOptions options,
uint32_t permissions = lldb::eFilePermissionsFileDefault,
bool should_close_fd = true);
Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Mon Oct 14 13:15:34 2019
@@ -18,6 +18,7 @@
#include "lldb/Core/PluginInterface.h"
#include "lldb/Core/UserSettingsController.h"
+#include "lldb/Host/File.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
@@ -505,8 +506,9 @@ public:
virtual Status SetFilePermissions(const FileSpec &file_spec,
uint32_t file_permissions);
- virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
- uint32_t mode, Status &error) {
+ virtual lldb::user_id_t OpenFile(const FileSpec &file_spec,
+ File::OpenOptions flags, uint32_t mode,
+ Status &error) {
return UINT64_MAX;
}
Modified: lldb/trunk/include/lldb/Target/RemoteAwarePlatform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/RemoteAwarePlatform.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/RemoteAwarePlatform.h (original)
+++ lldb/trunk/include/lldb/Target/RemoteAwarePlatform.h Mon Oct 14 13:15:34 2019
@@ -22,7 +22,7 @@ public:
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
ModuleSpec &module_spec) override;
- lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
+ lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
uint32_t mode, Status &error) override;
bool CloseFile(lldb::user_id_t fd, Status &error) override;
Modified: lldb/trunk/source/API/SBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFile.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFile.cpp (original)
+++ lldb/trunk/source/API/SBFile.cpp Mon Oct 14 13:15:34 2019
@@ -31,7 +31,12 @@ SBFile::SBFile(int fd, const char *mode,
LLDB_RECORD_DUMMY(void, SBFile, (int, const char *, bool), fd, mode,
transfer_owndership);
auto options = File::GetOptionsFromMode(mode);
- m_opaque_sp = std::make_shared<NativeFile>(fd, options, transfer_owndership);
+ if (!options) {
+ llvm::consumeError(options.takeError());
+ return;
+ }
+ m_opaque_sp =
+ std::make_shared<NativeFile>(fd, options.get(), transfer_owndership);
}
SBError SBFile::Read(uint8_t *buf, size_t num_bytes, size_t *bytes_read) {
Modified: lldb/trunk/source/API/SBStream.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStream.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/API/SBStream.cpp (original)
+++ lldb/trunk/source/API/SBStream.cpp Mon Oct 14 13:15:34 2019
@@ -82,7 +82,7 @@ void SBStream::RedirectToFile(const char
if (!m_is_file)
local_data = static_cast<StreamString *>(m_opaque_up.get())->GetString();
}
- uint32_t open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;
+ auto open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;
if (append)
open_options |= File::eOpenOptionAppend;
else
Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Mon Oct 14 13:15:34 2019
@@ -773,8 +773,7 @@ protected:
std::string path = outfile_spec.GetPath();
if (outfile_spec) {
- uint32_t open_options =
- File::eOpenOptionWrite | File::eOpenOptionCanCreate;
+ auto open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;
const bool append = m_outfile_options.GetAppend().GetCurrentValue();
if (append)
open_options |= File::eOpenOptionAppend;
Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Mon Oct 14 13:15:34 2019
@@ -375,12 +375,11 @@ protected:
FileSpec file_spec(m_options.m_filename);
FileSystem::Instance().Resolve(file_spec);
std::string path(file_spec.GetPath());
- uint32_t options = File::OpenOptions::eOpenOptionWrite |
- File::OpenOptions::eOpenOptionCanCreate;
+ auto options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;
if (m_options.m_append)
- options |= File::OpenOptions::eOpenOptionAppend;
+ options |= File::eOpenOptionAppend;
else
- options |= File::OpenOptions::eOpenOptionTruncate;
+ options |= File::eOpenOptionTruncate;
StreamFile out_file(path.c_str(), options,
lldb::eFilePermissionsFileDefault);
Modified: lldb/trunk/source/Core/StreamFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamFile.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamFile.cpp (original)
+++ lldb/trunk/source/Core/StreamFile.cpp Mon Oct 14 13:15:34 2019
@@ -46,7 +46,8 @@ StreamFile::StreamFile(const char *path)
}
}
-StreamFile::StreamFile(const char *path, uint32_t options, uint32_t permissions)
+StreamFile::StreamFile(const char *path, File::OpenOptions options,
+ uint32_t permissions)
: Stream() {
auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions);
if (file)
Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Mon Oct 14 13:15:34 2019
@@ -37,8 +37,9 @@
using namespace lldb;
using namespace lldb_private;
+using llvm::Expected;
-static const char *GetStreamOpenModeFromOptions(uint32_t options) {
+static Expected<const char *> GetStreamOpenModeFromOptions(uint32_t options) {
if (options & File::eOpenOptionAppend) {
if (options & File::eOpenOptionRead) {
if (options & File::eOpenOptionCanCreateNewOnly)
@@ -65,23 +66,31 @@ static const char *GetStreamOpenModeFrom
} else if (options & File::eOpenOptionWrite) {
return "w";
}
- return nullptr;
-}
-
-uint32_t File::GetOptionsFromMode(llvm::StringRef mode) {
- return llvm::StringSwitch<uint32_t>(mode)
- .Cases("r", "rb", eOpenOptionRead)
- .Cases("w", "wb", eOpenOptionWrite)
- .Cases("a", "ab",
- eOpenOptionWrite | eOpenOptionAppend | eOpenOptionCanCreate)
- .Cases("r+", "rb+", "r+b", eOpenOptionRead | eOpenOptionWrite)
- .Cases("w+", "wb+", "w+b",
- eOpenOptionRead | eOpenOptionWrite | eOpenOptionCanCreate |
- eOpenOptionTruncate)
- .Cases("a+", "ab+", "a+b",
- eOpenOptionRead | eOpenOptionWrite | eOpenOptionAppend |
- eOpenOptionCanCreate)
- .Default(0);
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "invalid options, cannot convert to mode string");
+}
+
+Expected<File::OpenOptions> File::GetOptionsFromMode(llvm::StringRef mode) {
+ OpenOptions opts =
+ llvm::StringSwitch<OpenOptions>(mode)
+ .Cases("r", "rb", eOpenOptionRead)
+ .Cases("w", "wb", eOpenOptionWrite)
+ .Cases("a", "ab",
+ eOpenOptionWrite | eOpenOptionAppend | eOpenOptionCanCreate)
+ .Cases("r+", "rb+", "r+b", eOpenOptionRead | eOpenOptionWrite)
+ .Cases("w+", "wb+", "w+b",
+ eOpenOptionRead | eOpenOptionWrite | eOpenOptionCanCreate |
+ eOpenOptionTruncate)
+ .Cases("a+", "ab+", "a+b",
+ eOpenOptionRead | eOpenOptionWrite | eOpenOptionAppend |
+ eOpenOptionCanCreate)
+ .Default(OpenOptions());
+ if (opts)
+ return opts;
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "invalid mode, cannot convert to File::OpenOptions");
}
int File::kInvalidDescriptor = -1;
@@ -257,8 +266,10 @@ IOObject::WaitableHandle NativeFile::Get
FILE *NativeFile::GetStream() {
if (!StreamIsValid()) {
if (DescriptorIsValid()) {
- const char *mode = GetStreamOpenModeFromOptions(m_options);
- if (mode) {
+ auto mode = GetStreamOpenModeFromOptions(m_options);
+ if (!mode)
+ llvm::consumeError(mode.takeError());
+ else {
if (!m_own_descriptor) {
// We must duplicate the file descriptor if we don't own it because when you
// call fdopen, the stream will own the fd
@@ -270,8 +281,8 @@ FILE *NativeFile::GetStream() {
m_own_descriptor = true;
}
- m_stream =
- llvm::sys::RetryAfterSignal(nullptr, ::fdopen, m_descriptor, mode);
+ m_stream = llvm::sys::RetryAfterSignal(nullptr, ::fdopen, m_descriptor,
+ mode.get());
// If we got a stream, then we own the stream and should no longer own
// the descriptor because fclose() will close it for us
@@ -303,7 +314,7 @@ Status NativeFile::Close() {
}
m_descriptor = kInvalidDescriptor;
m_stream = kInvalidStream;
- m_options = 0;
+ m_options = OpenOptions(0);
m_own_stream = false;
m_own_descriptor = false;
m_is_interactive = eLazyBoolCalculate;
@@ -315,7 +326,7 @@ FILE *NativeFile::TakeStreamAndClear() {
FILE *stream = GetStream();
m_stream = NULL;
m_descriptor = kInvalidDescriptor;
- m_options = 0;
+ m_options = OpenOptions();
m_own_stream = false;
m_own_descriptor = false;
m_is_interactive = m_supports_colors = m_is_real_terminal =
@@ -724,7 +735,7 @@ size_t NativeFile::PrintfVarArg(const ch
}
}
-mode_t File::ConvertOpenOptionsForPOSIXOpen(uint32_t open_options) {
+mode_t File::ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options) {
mode_t mode = 0;
if (open_options & eOpenOptionRead && open_options & eOpenOptionWrite)
mode |= O_RDWR;
@@ -747,4 +758,3 @@ mode_t File::ConvertOpenOptionsForPOSIXO
return mode;
}
-
Modified: lldb/trunk/source/Host/common/FileCache.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileCache.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileCache.cpp (original)
+++ lldb/trunk/source/Host/common/FileCache.cpp Mon Oct 14 13:15:34 2019
@@ -23,8 +23,9 @@ FileCache &FileCache::GetInstance() {
return *m_instance;
}
-lldb::user_id_t FileCache::OpenFile(const FileSpec &file_spec, uint32_t flags,
- uint32_t mode, Status &error) {
+lldb::user_id_t FileCache::OpenFile(const FileSpec &file_spec,
+ File::OpenOptions flags, uint32_t mode,
+ Status &error) {
if (!file_spec) {
error.SetErrorString("empty path");
return UINT64_MAX;
Modified: lldb/trunk/source/Host/common/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSystem.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/common/FileSystem.cpp Mon Oct 14 13:15:34 2019
@@ -415,7 +415,8 @@ static mode_t GetOpenMode(uint32_t permi
return mode;
}
-Expected<FileUP> FileSystem::Open(const FileSpec &file_spec, uint32_t options,
+Expected<FileUP> FileSystem::Open(const FileSpec &file_spec,
+ File::OpenOptions options,
uint32_t permissions, bool should_close_fd) {
if (m_collector)
m_collector->addFile(file_spec.GetPath());
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm Mon Oct 14 13:15:34 2019
@@ -429,7 +429,7 @@ static Status HandleFileAction(ProcessLa
int created_fd =
open(file_spec.GetPath().c_str(), oflag, S_IRUSR | S_IWUSR);
if (created_fd >= 0) {
- uint32_t file_options = 0;
+ auto file_options = File::OpenOptions(0);
if ((oflag & O_RDWR) || (oflag & O_RDONLY))
file_options |= File::eOpenOptionRead;
if ((oflag & O_RDWR) || (oflag & O_RDONLY))
Modified: lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp Mon Oct 14 13:15:34 2019
@@ -629,7 +629,8 @@ Status PlatformRemoteGDBServer::SetFileP
}
lldb::user_id_t PlatformRemoteGDBServer::OpenFile(const FileSpec &file_spec,
- uint32_t flags, uint32_t mode,
+ File::OpenOptions flags,
+ uint32_t mode,
Status &error) {
return m_gdb_client.OpenFile(file_spec, flags, mode, error);
}
Modified: lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h (original)
+++ lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h Mon Oct 14 13:15:34 2019
@@ -113,7 +113,7 @@ public:
Status SetFilePermissions(const FileSpec &file_spec,
uint32_t file_permissions) override;
- lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
+ lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
uint32_t mode, Status &error) override;
bool CloseFile(lldb::user_id_t fd, Status &error) override;
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Mon Oct 14 13:15:34 2019
@@ -2895,7 +2895,7 @@ static uint64_t ParseHostIOPacketRespons
}
lldb::user_id_t
GDBRemoteCommunicationClient::OpenFile(const lldb_private::FileSpec &file_spec,
- uint32_t flags, mode_t mode,
+ File::OpenOptions flags, mode_t mode,
Status &error) {
std::string path(file_spec.GetPath(false));
lldb_private::StreamString stream;
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Mon Oct 14 13:15:34 2019
@@ -17,6 +17,7 @@
#include <string>
#include <vector>
+#include "lldb/Host/File.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/StructuredData.h"
@@ -350,7 +351,7 @@ public:
size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids,
bool &sequence_mutex_unavailable);
- lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
+ lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
mode_t mode, Status &error);
bool CloseFile(lldb::user_id_t fd, Status &error);
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Mon Oct 14 13:15:34 2019
@@ -507,7 +507,11 @@ GDBRemoteCommunicationServerCommon::Hand
packet.GetHexByteStringTerminatedBy(path, ',');
if (!path.empty()) {
if (packet.GetChar() == ',') {
- uint32_t flags = packet.GetHexMaxU32(false, 0);
+ // FIXME
+ // The flag values for OpenOptions do not match the values used by GDB
+ // * https://sourceware.org/gdb/onlinedocs/gdb/Open-Flags.html#Open-Flags
+ // * rdar://problem/46788934
+ auto flags = File::OpenOptions(packet.GetHexMaxU32(false, 0));
if (packet.GetChar() == ',') {
mode_t mode = packet.GetHexMaxU32(false, 0600);
FileSpec path_spec(path);
@@ -546,7 +550,7 @@ GDBRemoteCommunicationServerCommon::Hand
int err = -1;
int save_errno = 0;
if (fd >= 0) {
- NativeFile file(fd, 0, true);
+ NativeFile file(fd, File::OpenOptions(0), true);
Status error = file.Close();
err = 0;
save_errno = error.GetError();
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Mon Oct 14 13:15:34 2019
@@ -1090,8 +1090,12 @@ FileUP PythonFile::GetUnderlyingFile() c
// File object knows about that.
PythonString py_mode = GetAttributeValue("mode").AsType<PythonString>();
auto options = File::GetOptionsFromMode(py_mode.GetString());
- auto file = std::unique_ptr<File>(
- new NativeFile(PyObject_AsFileDescriptor(m_py_obj), options, false));
+ if (!options) {
+ llvm::consumeError(options.takeError());
+ return nullptr;
+ }
+ auto file = std::unique_ptr<File>(new NativeFile(
+ PyObject_AsFileDescriptor(m_py_obj), options.get(), false));
if (!file->IsValid())
return nullptr;
return file;
@@ -1165,9 +1169,10 @@ std::error_code PythonException::convert
char PythonException::ID = 0;
-llvm::Expected<uint32_t> GetOptionsForPyObject(const PythonObject &obj) {
- uint32_t options = 0;
+llvm::Expected<File::OpenOptions>
+GetOptionsForPyObject(const PythonObject &obj) {
#if PY_MAJOR_VERSION >= 3
+ auto options = File::OpenOptions(0);
auto readable = As<bool>(obj.CallMethod("readable"));
if (!readable)
return readable.takeError();
@@ -1178,11 +1183,11 @@ llvm::Expected<uint32_t> GetOptionsForPy
options |= File::eOpenOptionRead;
if (writable.get())
options |= File::eOpenOptionWrite;
+ return options;
#else
PythonString py_mode = obj.GetAttributeValue("mode").AsType<PythonString>();
- options = File::GetOptionsFromMode(py_mode.GetString());
+ return File::GetOptionsFromMode(py_mode.GetString());
#endif
- return options;
}
// Base class template for python files. All it knows how to do
@@ -1245,7 +1250,7 @@ namespace {
class SimplePythonFile : public OwnedPythonFile<NativeFile> {
public:
SimplePythonFile(const PythonFile &file, bool borrowed, int fd,
- uint32_t options)
+ File::OpenOptions options)
: OwnedPythonFile(file, borrowed, fd, options, false) {}
};
} // namespace
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Mon Oct 14 13:15:34 2019
@@ -1220,7 +1220,7 @@ Status Platform::PutFile(const FileSpec
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
LLDB_LOGF(log, "[PutFile] Using block by block transfer....\n");
- uint32_t source_open_options =
+ auto source_open_options =
File::eOpenOptionRead | File::eOpenOptionCloseOnExec;
namespace fs = llvm::sys::fs;
if (fs::is_symlink_file(source.GetPath()))
Modified: lldb/trunk/source/Target/RemoteAwarePlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/RemoteAwarePlatform.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Target/RemoteAwarePlatform.cpp (original)
+++ lldb/trunk/source/Target/RemoteAwarePlatform.cpp Mon Oct 14 13:15:34 2019
@@ -61,8 +61,8 @@ Status RemoteAwarePlatform::SetFilePermi
}
lldb::user_id_t RemoteAwarePlatform::OpenFile(const FileSpec &file_spec,
- uint32_t flags, uint32_t mode,
- Status &error) {
+ File::OpenOptions flags,
+ uint32_t mode, Status &error) {
if (IsHost())
return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error);
if (m_remote_platform_sp)
Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=374817&r1=374816&r2=374817&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Oct 14 13:15:34 2019
@@ -996,10 +996,9 @@ Status Target::SerializeBreakpointsToFil
}
StreamFile out_file(path.c_str(),
- File::OpenOptions::eOpenOptionTruncate |
- File::OpenOptions::eOpenOptionWrite |
- File::OpenOptions::eOpenOptionCanCreate |
- File::OpenOptions::eOpenOptionCloseOnExec,
+ File::eOpenOptionTruncate | File::eOpenOptionWrite |
+ File::eOpenOptionCanCreate |
+ File::eOpenOptionCloseOnExec,
lldb::eFilePermissionsFileDefault);
if (!out_file.GetFile().IsValid()) {
error.SetErrorStringWithFormat("Unable to open output file: %s.",
More information about the lldb-commits
mailing list