LLDB mainline
lldb_private::NativeFilePosix Class Reference

POSIX implementation of NativeFile. More...

#include "lldb/Host/posix/FilePosix.h"

Inheritance diagram for lldb_private::NativeFilePosix:
[legend]

Public Member Functions

 NativeFilePosix ()=default
 NativeFilePosix (FILE *fh, OpenOptions options, bool transfer_ownership)
 NativeFilePosix (int fd, OpenOptions options, bool transfer_ownership)
Status GetFileSpec (FileSpec &file_spec) const override
 Get the file specification for this file, if possible.
WaitableHandle GetWaitableHandle () override
 Get a handle that can be used for OS polling interfaces, such as WaitForMultipleObjects, select, or epoll.
Status Sync () override
 Sync to disk.
Status Read (void *dst, size_t &num_bytes, off_t &offset) override
 Read bytes from a file from the specified file offset.
Status Write (const void *src, size_t &num_bytes, off_t &offset) override
 Write bytes to a file at the specified file offset.
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.
Status Write (const void *buf, size_t &num_bytes) override
 Write bytes from buf to a file at the current file position.
Public Member Functions inherited from lldb_private::NativeFileBase
bool IsValid () const override
 IsValid.
Status Close () override
 Flush any buffers and release any resources owned by the file.
int GetDescriptor () const override
 Get underlying OS file descriptor for this file, or kInvalidDescriptor.
FILE * GetStream () override
 Get the underlying libc stream for this file, or NULL.
off_t SeekFromStart (off_t offset, Status *error_ptr=nullptr) override
 Seek to an offset relative to the beginning of the file.
off_t SeekFromCurrent (off_t offset, Status *error_ptr=nullptr) override
 Seek to an offset relative to the current file position.
off_t SeekFromEnd (off_t offset, Status *error_ptr=nullptr) override
 Seek to an offset relative to the end of the file.
Status Flush () override
 Flush the current stream.
size_t PrintfVarArg (const char *format, va_list args) override
 Output printf formatted output to the stream.
llvm::Expected< OpenOptionsGetOptions () const override
 Return the OpenOptions for this file.
Public Member Functions inherited from lldb_private::File
 File ()
size_t Printf (const char *format,...) __attribute__((format(printf
 Output printf formatted output to the stream.
llvm::Expected< const char * > GetOpenMode () const
uint32_t GetPermissions (Status &error) const
 Get the permissions for a this file.
bool GetIsInteractive ()
 Return true if this file is interactive.
bool GetIsRealTerminal ()
 Return true if this file from a real terminal.
bool GetIsTerminalWithColors ()
 Return true if this file is a terminal which supports colors.
 operator bool () const
bool operator! () const
Public Member Functions inherited from lldb_private::IOObject
 IOObject (FDType type)
virtual ~IOObject ()
FDType GetFdType () const

Static Public Member Functions

static bool classof (const File *file)
Static Public Member Functions inherited from lldb_private::NativeFileBase
static bool classof (const File *file)
Static Public Member Functions inherited from lldb_private::File
static mode_t ConvertOpenOptionsForPOSIXOpen (OpenOptions open_options)
static llvm::Expected< OpenOptionsGetOptionsFromMode (llvm::StringRef mode)
static bool DescriptorIsValid (int descriptor)
static llvm::Expected< const char * > GetStreamOpenModeFromOptions (OpenOptions options)
static bool classof (const File *file)

Static Public Attributes

static char ID = 0
Static Public Attributes inherited from lldb_private::NativeFileBase
static char ID = 0
Static Public Attributes inherited from lldb_private::File
static int kInvalidDescriptor = -1
static FILE * kInvalidStream = nullptr
static constexpr OpenOptions OpenOptionsModeMask
static char ID = 0
Static Public Attributes inherited from lldb_private::IOObject
static const WaitableHandle kInvalidHandleValue = -1

Protected Member Functions

void CalculateInteractiveAndTerminal () override
 Refresh the cached interactive / terminal / color flags by inspecting the underlying descriptor.
Protected Member Functions inherited from lldb_private::NativeFileBase
 NativeFileBase ()
 NativeFileBase (FILE *fh, OpenOptions options, bool transfer_ownership)
 NativeFileBase (int fd, OpenOptions options, bool transfer_ownership)
 ~NativeFileBase () override
bool DescriptorIsValidUnlocked () const
bool StreamIsValidUnlocked () const
ValueGuard DescriptorIsValid () const
ValueGuard StreamIsValid () const
virtual int Fileno (FILE *fh) const
 Map a stream to its underlying file descriptor.
virtual int Dup (int fd) const
 Duplicate a file descriptor.
virtual bool TryWriteStreamUnlocked (const void *buf, size_t &num_bytes, Status &error)
 Hook for stream writes that bypass the default fwrite path.

Private Member Functions

 NativeFilePosix (const NativeFilePosix &)=delete
const NativeFilePosixoperator= (const NativeFilePosix &)=delete

Additional Inherited Members

Public Types inherited from lldb_private::NativeFileBase
enum  TransferOwnership : bool { Owned = true , Unowned = false }
Public Types inherited from lldb_private::File
enum  OpenOptions : uint32_t {
  eOpenOptionReadOnly = 0x0 , eOpenOptionWriteOnly = 0x1 , eOpenOptionReadWrite = 0x2 , eOpenOptionAppend ,
  eOpenOptionCanCreate = 0x200 , eOpenOptionTruncate = 0x400 , eOpenOptionCanCreateNewOnly , eOpenOptionNonBlocking = (1u << 28) ,
  eOpenOptionDontFollowSymlinks = (1u << 29) , eOpenOptionCloseOnExec , eOpenOptionInvalid = (1u << 31)
}
Public Types inherited from lldb_private::IOObject
enum  FDType { eFDTypeFile , eFDTypeSocket }
using WaitableHandle = lldb::file_t
Protected Attributes inherited from lldb_private::NativeFileBase
int m_descriptor = kInvalidDescriptor
bool m_own_descriptor = false
std::mutex m_descriptor_mutex
FILE * m_stream = kInvalidStream
std::mutex m_stream_mutex
OpenOptions m_options {}
bool m_own_stream = false
std::mutex offset_access_mutex
Protected Attributes inherited from lldb_private::File
LazyBool m_is_interactive = eLazyBoolCalculate
LazyBool m_is_real_terminal = eLazyBoolCalculate
LazyBool m_supports_colors = eLazyBoolCalculate
Protected Attributes inherited from lldb_private::IOObject
FDType m_fd_type

Detailed Description

POSIX implementation of NativeFile.

Definition at line 18 of file FilePosix.h.

Constructor & Destructor Documentation

◆ NativeFilePosix() [1/4]

lldb_private::NativeFilePosix::NativeFilePosix ( )
default

◆ NativeFilePosix() [2/4]

NativeFilePosix::NativeFilePosix ( FILE * fh,
OpenOptions options,
bool transfer_ownership )

◆ NativeFilePosix() [3/4]

NativeFilePosix::NativeFilePosix ( int fd,
OpenOptions options,
bool transfer_ownership )

Definition at line 56 of file FilePosix.cpp.

References lldb_private::NativeFileBase::NativeFileBase().

◆ NativeFilePosix() [4/4]

lldb_private::NativeFilePosix::NativeFilePosix ( const NativeFilePosix & )
privatedelete

References NativeFilePosix().

Member Function Documentation

◆ CalculateInteractiveAndTerminal()

void NativeFilePosix::CalculateInteractiveAndTerminal ( )
overrideprotectedvirtual

Refresh the cached interactive / terminal / color flags by inspecting the underlying descriptor.

The default implementation leaves the flags set to "no"; concrete subclasses override this with the appropriate platform-specific terminal probing.

Reimplemented from lldb_private::File.

Definition at line 76 of file FilePosix.cpp.

References lldb_private::File::DescriptorIsValid(), lldb_private::eLazyBoolNo, lldb_private::eLazyBoolYes, lldb_private::NativeFileBase::GetDescriptor(), lldb_private::File::m_is_interactive, lldb_private::File::m_is_real_terminal, and lldb_private::File::m_supports_colors.

◆ classof()

bool lldb_private::NativeFilePosix::classof ( const File * file)
inlinestatic

Definition at line 41 of file FilePosix.h.

References ID, and lldb_private::File::isA().

◆ GetFileSpec()

Status NativeFilePosix::GetFileSpec ( FileSpec & file_spec) const
overridevirtual

Get the file specification for this file, if possible.

Parameters
[out]file_specthe file specification.
Returns
ENOTSUP, success, or another error.

Reimplemented from lldb_private::NativeFileBase.

Definition at line 99 of file FilePosix.cpp.

References lldb_private::FileSpec::Clear(), error(), lldb_private::Status::FromErrno(), lldb_private::Status::FromErrorString(), lldb_private::NativeFileBase::GetDescriptor(), lldb_private::NativeFileBase::IsValid(), PATH_MAX, and lldb_private::FileSpec::SetFile().

◆ GetWaitableHandle()

IOObject::WaitableHandle NativeFilePosix::GetWaitableHandle ( )
overridevirtual

Get a handle that can be used for OS polling interfaces, such as WaitForMultipleObjects, select, or epoll.

This may return IOObject::kInvalidHandleValue if none is available. This will generally be the same as the file descriptor, this function is not interchangeable with GetDescriptor(). A WaitableHandle must only be used for polling, not actual I/O.

Returns
a valid handle or IOObject::kInvalidHandleValue

Reimplemented from lldb_private::NativeFileBase.

Definition at line 60 of file FilePosix.cpp.

References lldb_private::NativeFileBase::GetDescriptor().

◆ isA()

bool lldb_private::NativeFilePosix::isA ( const void * classID) const
inlineoverridevirtual

Reimplemented from lldb_private::NativeFileBase.

Reimplemented in lldb_private::SerialPort.

Definition at line 38 of file FilePosix.h.

References ID, and lldb_private::NativeFileBase::isA().

Referenced by lldb_private::SerialPort::isA().

◆ operator=()

const NativeFilePosix & lldb_private::NativeFilePosix::operator= ( const NativeFilePosix & )
privatedelete

References NativeFilePosix().

◆ Read() [1/2]

Status NativeFileBase::Read ( void * buf,
size_t & num_bytes )
overridevirtual

Read bytes from a file from the current file position into buf.

NOTE: This function is NOT thread safe. Use the read function that takes an "off_t &offset" to ensure correct operation in multi- threaded environments.

Parameters
[in,out]num_bytesPass in the size of buf. Read will pass out the number of bytes read. Zero bytes read with no error indicates EOF.
Returns
success, ENOTSUP, or another error.

Reimplemented from lldb_private::NativeFileBase.

Definition at line 396 of file File.cpp.

◆ Read() [2/2]

Status NativeFilePosix::Read ( void * dst,
size_t & num_bytes,
off_t & offset )
overridevirtual

Read bytes from a file from the specified file offset.

NOTE: This function is thread safe in that clients manager their own file position markers and reads on other threads won't mess up the current read.

Parameters
[in]dstA buffer where to put the bytes that are read.
[in,out]num_bytesThe number of bytes to read from the current file position which gets modified with the number of bytes that were read.
[in,out]offsetThe offset within the file from which to read num_bytes bytes. This offset gets incremented by the number of bytes that were read.
Returns
An error object that indicates success or the reason for failure.

Implements lldb_private::NativeFileBase.

Definition at line 135 of file FilePosix.cpp.

References error(), lldb_private::Status::FromErrno(), lldb_private::Status::FromErrorString(), lldb_private::NativeFileBase::GetDescriptor(), lldb_private::File::kInvalidDescriptor, and Read().

Referenced by lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pRead(), and Read().

◆ Sync()

Status NativeFilePosix::Sync ( )
overridevirtual

Sync to disk.

Returns
An error object that indicates success or the reason for failure.

Implements lldb_private::NativeFileBase.

Definition at line 65 of file FilePosix.cpp.

References lldb_private::NativeFileBase::DescriptorIsValid(), error(), lldb_private::Status::FromErrno(), lldb_private::Status::FromErrorString(), and lldb_private::NativeFileBase::m_descriptor.

◆ Write() [1/2]

Status NativeFileBase::Write ( const void * buf,
size_t & num_bytes )
overridevirtual

Write bytes from buf to a file at the current file position.

NOTE: This function is NOT thread safe. Use the write function that takes an "off_t &offset" to ensure correct operation in multi- threaded environments.

Parameters
[in,out]num_bytesPass in the size of buf. Write will pass out the number of bytes written. Write will attempt write the full number of bytes and will not return early except on error.
Returns
success, ENOTSUP, or another error.

Reimplemented from lldb_private::NativeFileBase.

Definition at line 397 of file File.cpp.

◆ Write() [2/2]

Status NativeFilePosix::Write ( const void * src,
size_t & num_bytes,
off_t & offset )
overridevirtual

Write bytes to a file at the specified file offset.

NOTE: This function is thread safe in that clients manager their own file position markers, though clients will need to implement their own locking externally to avoid multiple people writing to the file at the same time.

Parameters
[in]srcA buffer containing the bytes to write.
[in,out]num_bytesThe number of bytes to write to the file at offset offset. num_bytes gets modified with the number of bytes that were read.
[in,out]offsetThe offset within the file at which to write num_bytes bytes. This offset gets incremented by the number of bytes that were written.
Returns
An error object that indicates success or the reason for failure.

Implements lldb_private::NativeFileBase.

Definition at line 186 of file FilePosix.cpp.

References error(), lldb_private::Status::FromErrno(), lldb_private::Status::FromErrorString(), lldb_private::NativeFileBase::GetDescriptor(), lldb_private::File::kInvalidDescriptor, lldb_private::NativeFileBase::m_descriptor, and Write().

Referenced by lldb_private::ClangUtilityFunction::ClangUtilityFunction(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite(), lldb_private::ClangExpressionParser::ParseInternal(), and Write().

Member Data Documentation

◆ ID

char NativeFilePosix::ID = 0
static

Definition at line 37 of file FilePosix.h.

Referenced by classof(), and isA().


The documentation for this class was generated from the following files: