9#ifndef LLDB_HOST_FILE_H
10#define LLDB_HOST_FILE_H
17#include "llvm/ADT/BitmaskEnum.h"
72 static llvm::Expected<const char *>
90 Status Read(
void *buf,
size_t &num_bytes)
override;
105 Status Write(
const void *buf,
size_t &num_bytes)
override;
240 virtual Status Read(
void *dst,
size_t &num_bytes, off_t &offset);
265 virtual Status Write(
const void *src,
size_t &num_bytes, off_t &offset);
294 size_t Printf(
const char *format, ...) __attribute__((format(printf, 2, 3)));
306 virtual
size_t PrintfVarArg(const
char *format, va_list args);
323 return opts.takeError();
363 virtual bool isA(
const void *classID)
const {
return classID == &
ID; }
394 Status Read(
void *buf,
size_t &num_bytes)
override;
395 Status Write(
const void *buf,
size_t &num_bytes)
override;
404 Status Read(
void *dst,
size_t &num_bytes, off_t &offset)
override;
405 Status Write(
const void *src,
size_t &num_bytes, off_t &offset)
override;
408 size_t PrintfVarArg(
const char *format, va_list args)
override;
409 llvm::Expected<OpenOptions>
GetOptions()
const override;
412 bool isA(
const void *classID)
const override {
469 static llvm::Expected<Options>
OptionsFromURL(llvm::StringRef urlqs);
471 static llvm::Expected<std::unique_ptr<SerialPort>>
473 bool transfer_ownership);
482 bool isA(
const void *classID)
const override {
489 bool transfer_ownership);
static llvm::raw_ostream & error(Stream &strm)
An abstract base class for files.
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
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.
void CalculateInteractiveAndTerminal()
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.
bool DescriptorIsValidUnlocked() const
off_t SeekFromStart(off_t offset, Status *error_ptr=nullptr) override
Seek to an offset relative to the beginning of the file.
const NativeFile & operator=(const NativeFile &)=delete
Status GetFileSpec(FileSpec &file_spec) const override
Get the file specification for this file, if possible.
FILE * GetStream() override
Get the underlying libc stream for this file, or NULL.
Status Sync() override
Sync to disk.
std::mutex offset_access_mutex
Status Close() override
Flush any buffers and release any resources owned by the file.
WaitableHandle GetWaitableHandle() override
Get a handle that can be used for OS polling interfaces, such as WaitForMultipleObjects,...
Status Flush() override
Flush the current stream.
bool StreamIsValidUnlocked() const
ValueGuard DescriptorIsValid() const
llvm::Expected< OpenOptions > GetOptions() const override
Return the OpenOptions for this file.
static bool classof(const File *file)
NativeFile(int fd, OpenOptions options, bool transfer_ownership)
off_t SeekFromCurrent(off_t offset, Status *error_ptr=nullptr) override
Seek to an offset relative to the current file position.
size_t PrintfVarArg(const char *format, va_list args) override
Output printf formatted output to the stream.
Status Write(const void *buf, size_t &num_bytes) override
Write bytes from buf to a file at the current file position.
int GetDescriptor() const override
Get underlying OS file descriptor for this file, or kInvalidDescriptor.
Status Read(void *buf, size_t &num_bytes) override
Read bytes from a file from the current file position into buf.
bool IsValid() const override
IsValid.
NativeFile(const NativeFile &)=delete
std::mutex m_descriptor_mutex
std::mutex m_stream_mutex
ValueGuard StreamIsValid() const
NativeFile(FILE *fh, bool transfer_ownership)
off_t SeekFromEnd(off_t offset, Status *error_ptr=nullptr) override
Seek to an offset relative to the end of the file.
bool isA(const void *classID) const override
A command line option parsing protocol class.
SerialPort(const SerialPort &)=delete
static llvm::Expected< std::unique_ptr< SerialPort > > Create(int fd, OpenOptions options, Options serial_options, bool transfer_ownership)
const SerialPort & operator=(const SerialPort &)=delete
Status Close() override
Flush any buffers and release any resources owned by the file.
bool IsValid() const override
IsValid.
static bool classof(const File *file)
bool isA(const void *classID) const override
static llvm::Expected< Options > OptionsFromURL(llvm::StringRef urlqs)
A RAII-friendly terminal state saving/restoring class.
A class that represents a running process on the host machine.
@ LLVM_MARK_AS_BITMASK_ENUM
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
std::lock_guard< std::mutex > guard
ValueGuard(std::mutex &m, bool b)
std::optional< Terminal::ParityCheck > ParityCheck
std::optional< unsigned int > StopBits
std::optional< Terminal::Parity > Parity
std::optional< unsigned int > BaudRate