9#ifndef LLDB_HOST_FILEBASE_H
10#define LLDB_HOST_FILEBASE_H
16#include "llvm/ADT/BitmaskEnum.h"
73 static llvm::Expected<const char *>
91 Status Read(
void *buf,
size_t &num_bytes)
override;
106 Status Write(
const void *buf,
size_t &num_bytes)
override;
241 virtual Status Read(
void *dst,
size_t &num_bytes, off_t &offset);
266 virtual Status Write(
const void *src,
size_t &num_bytes, off_t &offset);
295 size_t Printf(
const char *format, ...) __attribute__((format(printf, 2, 3)));
307 virtual
size_t PrintfVarArg(const
char *format, va_list args);
324 return opts.takeError();
363 virtual bool isA(
const void *classID)
const {
return classID == &
ID; }
396 Status Read(
void *buf,
size_t &num_bytes)
override;
397 Status Write(
const void *buf,
size_t &num_bytes)
override;
406 virtual Status Read(
void *dst,
size_t &num_bytes, off_t &offset)
override = 0;
408 off_t &offset)
override = 0;
411 size_t PrintfVarArg(
const char *format, va_list args)
override;
412 llvm::Expected<OpenOptions>
GetOptions()
const override;
415 bool isA(
const void *classID)
const override {
453 virtual int Fileno(FILE *fh)
const;
456 virtual int Dup(
int fd)
const;
static llvm::raw_ostream & error(Stream &strm)
virtual llvm::Expected< OpenOptions > GetOptions() const
Return the OpenOptions for this file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
virtual bool isA(const void *classID) const
WaitableHandle GetWaitableHandle() override
Get a handle that can be used for OS polling interfaces, such as WaitForMultipleObjects,...
bool GetIsRealTerminal()
Return true if this file from a real terminal.
File(const File &)=delete
static constexpr OpenOptions OpenOptionsModeMask
const File & operator=(const File &)=delete
virtual FILE * GetStream()
Get the underlying libc stream for this file, or NULL.
Status Read(void *buf, size_t &num_bytes) override
Read bytes from a file from the current file position into buf.
virtual off_t SeekFromStart(off_t offset, Status *error_ptr=nullptr)
Seek to an offset relative to the beginning of the file.
static int kInvalidDescriptor
static FILE * kInvalidStream
virtual Status GetFileSpec(FileSpec &file_spec) const
Get the file specification for this file, if possible.
LazyBool m_is_real_terminal
virtual off_t SeekFromCurrent(off_t offset, Status *error_ptr=nullptr)
Seek to an offset relative to the current file position.
LazyBool m_is_interactive
static bool DescriptorIsValid(int descriptor)
static mode_t ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options)
virtual int GetDescriptor() const
Get underlying OS file descriptor for this file, or kInvalidDescriptor.
static llvm::Expected< const char * > GetStreamOpenModeFromOptions(OpenOptions options)
bool GetIsTerminalWithColors()
Return true if this file is a terminal which supports colors.
Status Close() override
Flush any buffers and release any resources owned by the file.
Status Write(const void *buf, size_t &num_bytes) override
Write bytes from buf to a file at the current file position.
@ eOpenOptionCanCreateNewOnly
@ eOpenOptionDontFollowSymlinks
uint32_t GetPermissions(Status &error) const
Get the permissions for a this file.
llvm::Expected< const char * > GetOpenMode() const
bool IsValid() const override
IsValid.
virtual Status Flush()
Flush the current stream.
static llvm::Expected< OpenOptions > GetOptionsFromMode(llvm::StringRef mode)
size_t virtual size_t PrintfVarArg(const char *format, va_list args)
Output printf formatted output to the stream.
virtual Status Sync()
Sync to disk.
LazyBool m_supports_colors
bool GetIsInteractive()
Return true if this file is interactive.
virtual void CalculateInteractiveAndTerminal()
Refresh the cached interactive / terminal / color flags by inspecting the underlying descriptor.
static bool classof(const File *file)
virtual off_t SeekFromEnd(off_t offset, Status *error_ptr=nullptr)
Seek to an offset relative to the end of the file.
lldb::file_t WaitableHandle
bool DescriptorIsValidUnlocked() const
std::mutex m_stream_mutex
WaitableHandle GetWaitableHandle() override
Get a handle that can be used for OS polling interfaces, such as WaitForMultipleObjects,...
bool StreamIsValidUnlocked() const
Status Flush() override
Flush the current stream.
virtual Status Read(void *dst, size_t &num_bytes, off_t &offset) override=0
Read bytes from a file from the specified file offset.
std::mutex offset_access_mutex
llvm::Expected< OpenOptions > GetOptions() const override
Return the OpenOptions for this file.
off_t SeekFromCurrent(off_t offset, Status *error_ptr=nullptr) override
Seek to an offset relative to the current file position.
Status Write(const void *buf, size_t &num_bytes) override
Write bytes from buf to a file at the current file position.
NativeFileBase(const NativeFileBase &)=delete
const NativeFileBase & operator=(const NativeFileBase &)=delete
virtual bool TryWriteStreamUnlocked(const void *buf, size_t &num_bytes, Status &error)
Hook for stream writes that bypass the default fwrite path.
virtual Status Write(const void *src, size_t &num_bytes, off_t &offset) override=0
Write bytes to a file at the specified file offset.
virtual int Fileno(FILE *fh) const
Map a stream to its underlying file descriptor.
int GetDescriptor() const override
Get underlying OS file descriptor for this file, or kInvalidDescriptor.
virtual int Dup(int fd) const
Duplicate a file descriptor.
static bool classof(const File *file)
virtual Status Sync() override=0
Sync to disk.
off_t SeekFromEnd(off_t offset, Status *error_ptr=nullptr) override
Seek to an offset relative to the end of the file.
~NativeFileBase() override
ValueGuard StreamIsValid() const
ValueGuard DescriptorIsValid() const
bool IsValid() const override
IsValid.
std::mutex m_descriptor_mutex
size_t PrintfVarArg(const char *format, va_list args) override
Output printf formatted output to the stream.
FILE * GetStream() override
Get the underlying libc stream for this file, or NULL.
Status GetFileSpec(FileSpec &file_spec) const override
Get the file specification for this file, if possible.
off_t SeekFromStart(off_t offset, Status *error_ptr=nullptr) override
Seek to an offset relative to the beginning of the file.
Status Close() override
Flush any buffers and release any resources owned by the file.
bool isA(const void *classID) const override
Status Read(void *buf, size_t &num_bytes) override
Read bytes from a file from the current file position into buf.
A class that represents a running process on the host machine.
@ LLVM_MARK_AS_BITMASK_ENUM
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
ValueGuard(std::mutex &m, bool b)
std::lock_guard< std::mutex > guard