LLDB mainline
lldb_private::NativeFileWindows Class Reference

Windows implementation of NativeFile. More...

#include "lldb/Host/windows/FileWindows.h"

Inheritance diagram for lldb_private::NativeFileWindows:
[legend]

Public Member Functions

 NativeFileWindows ()=default
 NativeFileWindows (FILE *fh, OpenOptions options, bool transfer_ownership)
 NativeFileWindows (int fd, OpenOptions options, bool transfer_ownership)
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.
Status GetFileSpec (FileSpec &file_spec) const override
 Get the file specification for this file, if possible.
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.
int Fileno (FILE *fh) const override
 Map a stream to its underlying file descriptor.
int Dup (int fd) const override
 Duplicate a file descriptor.
bool TryWriteStreamUnlocked (const void *buf, size_t &num_bytes, Status &error) override
 Hook for stream writes that bypass the default fwrite path.
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

Private Member Functions

 NativeFileWindows (const NativeFileWindows &)=delete
const NativeFileWindowsoperator= (const NativeFileWindows &)=delete

Private Attributes

bool m_is_windows_console = false
 Set when this file wraps stdin/stdout/stderr connected to a console; triggers the raw_fd_ostream path for correct non-ASCII output.

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

Windows implementation of NativeFile.

Definition at line 18 of file FileWindows.h.

Constructor & Destructor Documentation

◆ NativeFileWindows() [1/4]

lldb_private::NativeFileWindows::NativeFileWindows ( )
default

◆ NativeFileWindows() [2/4]

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

◆ NativeFileWindows() [3/4]

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

◆ NativeFileWindows() [4/4]

lldb_private::NativeFileWindows::NativeFileWindows ( const NativeFileWindows & )
privatedelete

References NativeFileWindows().

Member Function Documentation

◆ CalculateInteractiveAndTerminal()

void NativeFileWindows::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 51 of file FileWindows.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::NativeFileWindows::classof ( const File * file)
inlinestatic

Definition at line 40 of file FileWindows.h.

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

◆ Dup()

int NativeFileWindows::Dup ( int fd) const
overrideprotectedvirtual

Duplicate a file descriptor.

Reimplemented from lldb_private::NativeFileBase.

Definition at line 72 of file FileWindows.cpp.

◆ Fileno()

int NativeFileWindows::Fileno ( FILE * fh) const
overrideprotectedvirtual

Map a stream to its underlying file descriptor.

Reimplemented from lldb_private::NativeFileBase.

Definition at line 70 of file FileWindows.cpp.

◆ GetWaitableHandle()

IOObject::WaitableHandle NativeFileWindows::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 74 of file FileWindows.cpp.

References lldb_private::NativeFileBase::GetDescriptor().

◆ isA()

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

Reimplemented from lldb_private::NativeFileBase.

Definition at line 37 of file FileWindows.h.

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

◆ operator=()

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

References NativeFileWindows().

◆ 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 NativeFileWindows::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 101 of file FileWindows.cpp.

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

◆ Sync()

Status NativeFileWindows::Sync ( )
overridevirtual

Sync to disk.

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

Implements lldb_private::NativeFileBase.

Definition at line 78 of file FileWindows.cpp.

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

◆ TryWriteStreamUnlocked()

bool NativeFileWindows::TryWriteStreamUnlocked ( const void * buf,
size_t & num_bytes,
Status & error )
overrideprotectedvirtual

Hook for stream writes that bypass the default fwrite path.

Returns true if the bytes were consumed.

Reimplemented from lldb_private::NativeFileBase.

Definition at line 89 of file FileWindows.cpp.

References error(), m_is_windows_console, and lldb_private::NativeFileBase::m_stream.

◆ 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 NativeFileWindows::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 121 of file FileWindows.cpp.

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

Member Data Documentation

◆ ID

char NativeFileWindows::ID = 0
static

Definition at line 36 of file FileWindows.h.

Referenced by classof(), and isA().

◆ m_is_windows_console

bool lldb_private::NativeFileWindows::m_is_windows_console = false
private

Set when this file wraps stdin/stdout/stderr connected to a console; triggers the raw_fd_ostream path for correct non-ASCII output.

Definition at line 54 of file FileWindows.h.

Referenced by NativeFileWindows(), NativeFileWindows(), and TryWriteStreamUnlocked().


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