Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Standalone View
lldb/include/lldb/Host/File.h
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | enum OpenOptions : uint32_t { | ||||
eOpenOptionCloseOnExec = | 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) | LLVM_MARK_AS_BITMASK_ENUM(/* largest_value= */ eOpenOptionCloseOnExec) | ||||
}; | }; | ||||
static mode_t ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options); | static mode_t ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options); | ||||
static llvm::Expected<OpenOptions> GetOptionsFromMode(llvm::StringRef mode); | static llvm::Expected<OpenOptions> GetOptionsFromMode(llvm::StringRef mode); | ||||
static bool DescriptorIsValid(int descriptor) { return descriptor >= 0; }; | static bool DescriptorIsValid(int descriptor) { return descriptor >= 0; }; | ||||
static llvm::Expected<const char *> | |||||
labath: change the argument type to OpenOptions. For some reason, lldb has historically used integer… | |||||
Are you sure that's the right thing to do? eOpenOptionRead | eOpenOptionWrite has type unsigned int, not OpenOptions. lawrence_danna: Are you sure that's the right thing to do? `eOpenOptionRead | eOpenOptionWrite` has type… | |||||
Ah, right, that was the reason... Regardless, I do thing that's right -- I'll continue the discussion on the other patch. labath: Ah, right, that was the reason... Regardless, I do thing that's right -- I'll continue the… | |||||
GetStreamOpenModeFromOptions(OpenOptions options); | |||||
File() | File() | ||||
: IOObject(eFDTypeFile), m_is_interactive(eLazyBoolCalculate), | : IOObject(eFDTypeFile), m_is_interactive(eLazyBoolCalculate), | ||||
m_is_real_terminal(eLazyBoolCalculate), | m_is_real_terminal(eLazyBoolCalculate), | ||||
m_supports_colors(eLazyBoolCalculate){}; | m_supports_colors(eLazyBoolCalculate){}; | ||||
/// Read bytes from a file from the current file position into buf. | /// Read bytes from a file from the current file position into buf. | ||||
/// | /// | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | public: | ||||
/// \param[in] format | /// \param[in] format | ||||
/// A printf style format string. | /// A printf style format string. | ||||
/// | /// | ||||
/// \param[in] args | /// \param[in] args | ||||
/// Variable arguments that are needed for the printf style | /// Variable arguments that are needed for the printf style | ||||
/// format string \a format. | /// format string \a format. | ||||
virtual size_t PrintfVarArg(const char *format, va_list args); | virtual size_t PrintfVarArg(const char *format, va_list args); | ||||
/// Return the OpenOptions for this file. | |||||
/// | |||||
/// 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 | |||||
We've spend a lot of time removing python from the lowest layers, and this let's it back in through the back door. It would be way better to add support for llvm-style rtti to this class, so that the python code can dyn_cast to a PythonFile when it needs to (re)construct the python object. You can take a look at CPPLanguageRuntime::classof (and friend) for how to implement this in a plugin-friendly manner. labath: We've spend a lot of time removing python from the lowest layers, and this let's it back in… | |||||
Ah, thanks. I orginally wrote this using dyn_cast but I found myself putting classnames of python things in an enum in File.h, so I thought "what's the point?" -- and I converted it to just using the virtual method. The static char ID trick is nice. lawrence_danna: Ah, thanks. I orginally wrote this using `dyn_cast` but I found myself putting classnames of… | |||||
/// File should return either or both of eOpenOptionRead and | |||||
/// eOpenOptionWrite here. | |||||
/// | |||||
/// \return | |||||
/// OpenOptions flags for this file, or an error. | |||||
virtual llvm::Expected<OpenOptions> GetOptions() const; | |||||
llvm::Expected<const char *> GetOpenMode() const { | |||||
auto opts = GetOptions(); | |||||
if (!opts) | |||||
return opts.takeError(); | |||||
return GetStreamOpenModeFromOptions(opts.get()); | |||||
How about returning Expected<OpenOptions> from here? labath: How about returning Expected<OpenOptions> from here? | |||||
Please move this somewhere else -- somewhere near the top or bottom of the class maybe.. It does not make sense to have it in the middle of the open options stuff. labath: Please move this somewhere else -- somewhere near the top or bottom of the class maybe.. It… | |||||
} | |||||
and Expected<const char*> from here? labath: and Expected<const char*> from here? | |||||
/// Get the permissions for a this file. | /// Get the permissions for a this file. | ||||
/// | /// | ||||
/// \return | /// \return | ||||
/// Bits logical OR'ed together from the permission bits defined | /// Bits logical OR'ed together from the permission bits defined | ||||
/// in lldb_private::File::Permissions. | /// in lldb_private::File::Permissions. | ||||
uint32_t GetPermissions(Status &error) const; | uint32_t GetPermissions(Status &error) const; | ||||
/// Return true if this file is interactive. | /// Return true if this file is interactive. | ||||
Show All 19 Lines | public: | ||||
/// \return | /// \return | ||||
/// True iff this is a terminal and it supports colors. | /// True iff this is a terminal and it supports colors. | ||||
bool GetIsTerminalWithColors(); | bool GetIsTerminalWithColors(); | ||||
operator bool() const { return IsValid(); }; | operator bool() const { return IsValid(); }; | ||||
bool operator!() const { return !IsValid(); }; | bool operator!() const { return !IsValid(); }; | ||||
static char ID; | |||||
virtual bool isA(const void *classID) const { return classID == &ID; } | |||||
static bool classof(const File *file) { return file->isA(&ID); } | |||||
protected: | protected: | ||||
LazyBool m_is_interactive; | LazyBool m_is_interactive; | ||||
LazyBool m_is_real_terminal; | LazyBool m_is_real_terminal; | ||||
LazyBool m_supports_colors; | LazyBool m_supports_colors; | ||||
void CalculateInteractiveAndTerminal(); | void CalculateInteractiveAndTerminal(); | ||||
private: | private: | ||||
Show All 31 Lines | public: | ||||
off_t SeekFromStart(off_t offset, Status *error_ptr = nullptr) override; | off_t SeekFromStart(off_t offset, Status *error_ptr = nullptr) override; | ||||
off_t SeekFromCurrent(off_t offset, Status *error_ptr = nullptr) override; | off_t SeekFromCurrent(off_t offset, Status *error_ptr = nullptr) override; | ||||
off_t SeekFromEnd(off_t offset, Status *error_ptr = nullptr) override; | off_t SeekFromEnd(off_t offset, Status *error_ptr = nullptr) override; | ||||
Status Read(void *dst, size_t &num_bytes, off_t &offset) override; | Status Read(void *dst, size_t &num_bytes, off_t &offset) override; | ||||
Status Write(const void *src, size_t &num_bytes, off_t &offset) override; | Status Write(const void *src, size_t &num_bytes, off_t &offset) override; | ||||
Status Flush() override; | Status Flush() override; | ||||
Status Sync() override; | Status Sync() override; | ||||
size_t PrintfVarArg(const char *format, va_list args) override; | size_t PrintfVarArg(const char *format, va_list args) override; | ||||
llvm::Expected<OpenOptions> GetOptions() const override; | |||||
static char ID; | |||||
virtual bool isA(const void *classID) const override { | |||||
return classID == &ID || File::isA(classID); | |||||
} | |||||
static bool classof(const File *file) { return file->isA(&ID); } | |||||
protected: | protected: | ||||
bool DescriptorIsValid() const { | bool DescriptorIsValid() const { | ||||
return File::DescriptorIsValid(m_descriptor); | return File::DescriptorIsValid(m_descriptor); | ||||
} | } | ||||
bool StreamIsValid() const { return m_stream != kInvalidStream; } | bool StreamIsValid() const { return m_stream != kInvalidStream; } | ||||
// Member variables | // Member variables | ||||
Show All 14 Lines |
change the argument type to OpenOptions. For some reason, lldb has historically used integer types for passing enumerations around, but we're now slowly changing that..