LLDB  mainline
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
lldb_private::NativeFile Class Reference

#include <File.h>

Inheritance diagram for lldb_private::NativeFile:
Inheritance graph
[legend]
Collaboration diagram for lldb_private::NativeFile:
Collaboration graph
[legend]

Public Member Functions

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

Protected Member Functions

bool DescriptorIsValid () const
 
bool StreamIsValid () const
 
- Protected Member Functions inherited from lldb_private::File
void CalculateInteractiveAndTerminal ()
 

Protected Attributes

int m_descriptor
 
bool m_own_descriptor = false
 
FILE * m_stream
 
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
 

Private Member Functions

 NativeFile (const NativeFile &)=delete
 
const NativeFileoperator= (const NativeFile &)=delete
 

Additional Inherited Members

- Public Types inherited from lldb_private::File
enum  OpenOptions : uint32_t {
  eOpenOptionRead = (1u << 0), eOpenOptionWrite = (1u << 1), eOpenOptionAppend, eOpenOptionTruncate = (1u << 3),
  eOpenOptionNonBlocking = (1u << 4), eOpenOptionCanCreate = (1u << 5), eOpenOptionCanCreateNewOnly, eOpenOptionDontFollowSymlinks = (1u << 7),
  eOpenOptionCloseOnExec
}
 
- Public Types inherited from lldb_private::IOObject
enum  FDType { eFDTypeFile, eFDTypeSocket }
 
typedef int WaitableHandle
 

Detailed Description

Definition at line 371 of file File.h.

Constructor & Destructor Documentation

◆ NativeFile() [1/4]

lldb_private::NativeFile::NativeFile ( )
inline

Definition at line 373 of file File.h.

◆ NativeFile() [2/4]

lldb_private::NativeFile::NativeFile ( FILE *  fh,
bool  transfer_ownership 
)
inline

Definition at line 375 of file File.h.

◆ NativeFile() [3/4]

lldb_private::NativeFile::NativeFile ( int  fd,
OpenOptions  options,
bool  transfer_ownership 
)
inline

Definition at line 379 of file File.h.

◆ ~NativeFile()

lldb_private::NativeFile::~NativeFile ( )
inlineoverride

Definition at line 383 of file File.h.

References Close().

◆ NativeFile() [4/4]

lldb_private::NativeFile::NativeFile ( const NativeFile )
privatedelete

Member Function Documentation

◆ classof()

static bool lldb_private::NativeFile::classof ( const File file)
inlinestatic

Definition at line 410 of file File.h.

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

◆ Close()

Status NativeFile::Close ( )
overridevirtual

Flush any buffers and release any resources owned by the file.

After Close() the file will be invalid.

Returns
success or an error.

Reimplemented from lldb_private::File.

Definition at line 307 of file File.cpp.

References lldb_private::eLazyBoolCalculate, and error().

Referenced by lldb_private::ClangUtilityFunction::ClangUtilityFunction(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Close(), lldb_private::ClangExpressionParser::ParseInternal(), and ~NativeFile().

◆ DescriptorIsValid()

bool lldb_private::NativeFile::DescriptorIsValid ( ) const
inlineprotected

Definition at line 413 of file File.h.

References lldb_private::File::DescriptorIsValid(), and m_descriptor.

Referenced by IsValid().

◆ Flush()

Status NativeFile::Flush ( )
overridevirtual

Flush the current stream.

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

Reimplemented from lldb_private::File.

Definition at line 446 of file File.cpp.

References error().

◆ GetDescriptor()

int NativeFile::GetDescriptor ( ) const
overridevirtual

Get underlying OS file descriptor for this file, or kInvalidDescriptor.

If the descriptor is valid, then it may be used directly for I/O However, the File may also perform it's own buffering, so avoid using this if it is not necessary, or use Flush() appropriately.

Returns
a valid file descriptor for this file or kInvalidDescriptor

Reimplemented from lldb_private::File.

Definition at line 251 of file File.cpp.

◆ GetFileSpec()

Status NativeFile::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::File.

Definition at line 332 of file File.cpp.

References lldb_private::FileSpec::Clear(), error(), PATH_MAX, and lldb_private::FileSpec::SetFile().

◆ GetOptions()

Expected< File::OpenOptions > NativeFile::GetOptions ( ) const
overridevirtual

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 File should return either or both of eOpenOptionRead and eOpenOptionWrite here.

Returns
OpenOptions flags for this file, or an error.

Reimplemented from lldb_private::File.

Definition at line 249 of file File.cpp.

◆ GetStream()

FILE * NativeFile::GetStream ( )
overridevirtual

Get the underlying libc stream for this file, or NULL.

Not all valid files will have a FILE* stream. This should only be used if absolutely necessary, such as to interact with 3rd party libraries that need FILE* streams.

Returns
a valid stream or NULL;

Reimplemented from lldb_private::File.

Definition at line 273 of file File.cpp.

◆ GetWaitableHandle()

IOObject::WaitableHandle NativeFile::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::File.

Definition at line 269 of file File.cpp.

◆ isA()

virtual bool lldb_private::NativeFile::isA ( const void *  classID) const
inlineoverridevirtual

Reimplemented from lldb_private::File.

Definition at line 407 of file File.h.

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

◆ IsValid()

bool lldb_private::NativeFile::IsValid ( ) const
inlineoverridevirtual

IsValid.

Returns
true iff the file is valid.

Reimplemented from lldb_private::File.

Definition at line 385 of file File.h.

References DescriptorIsValid(), and StreamIsValid().

◆ operator=()

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

◆ PrintfVarArg()

size_t NativeFile::PrintfVarArg ( const char *  format,
va_list  args 
)
overridevirtual

Output printf formatted output to the stream.

Print some formatted output to the stream.

Parameters
[in]formatA printf style format string.
[in]argsVariable arguments that are needed for the printf style format string format.

Reimplemented from lldb_private::File.

Definition at line 725 of file File.cpp.

◆ Read() [1/2]

Status NativeFile::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::File.

Definition at line 480 of file File.cpp.

References error().

Referenced by lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pRead().

◆ Read() [2/2]

Status NativeFile::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 form 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.

Reimplemented from lldb_private::File.

Definition at line 601 of file File.cpp.

References error().

◆ SeekFromCurrent()

off_t NativeFile::SeekFromCurrent ( off_t  offset,
Status error_ptr = nullptr 
)
overridevirtual

Seek to an offset relative to the current file position.

NOTE: This function is NOT thread safe, other threads that access this object might also change the current file position. For thread safe reads and writes see the following functions:

See also
File::Read (void *, size_t, off_t &)
File::Write (const void *, size_t, off_t &)
Parameters
[in]offsetThe offset to seek to within the file relative to the current file position.
[in]error_ptrA pointer to a lldb_private::Status object that will be filled in if non-nullptr.
Returns
The resulting seek offset, or -1 on error.

Reimplemented from lldb_private::File.

Definition at line 394 of file File.cpp.

References lldb_private::Status::Clear(), lldb_private::Status::SetErrorString(), and lldb_private::Status::SetErrorToErrno().

◆ SeekFromEnd()

off_t NativeFile::SeekFromEnd ( off_t  offset,
Status error_ptr = nullptr 
)
overridevirtual

Seek to an offset relative to the end of the file.

NOTE: This function is NOT thread safe, other threads that access this object might also change the current file position. For thread safe reads and writes see the following functions:

See also
File::Read (void *, size_t, off_t &)
File::Write (const void *, size_t, off_t &)
Parameters
[in,out]offsetThe offset to seek to within the file relative to the end of the file which gets filled in with the resulting absolute file offset.
[in]error_ptrA pointer to a lldb_private::Status object that will be filled in if non-nullptr.
Returns
The resulting seek offset, or -1 on error.

Reimplemented from lldb_private::File.

Definition at line 420 of file File.cpp.

References lldb_private::Status::Clear(), lldb_private::Status::SetErrorString(), and lldb_private::Status::SetErrorToErrno().

◆ SeekFromStart()

off_t NativeFile::SeekFromStart ( off_t  offset,
Status error_ptr = nullptr 
)
overridevirtual

Seek to an offset relative to the beginning of the file.

NOTE: This function is NOT thread safe, other threads that access this object might also change the current file position. For thread safe reads and writes see the following functions:

See also
File::Read (void *, size_t, off_t &)
File::Write (const void *, size_t, off_t &)
Parameters
[in]offsetThe offset to seek to within the file relative to the beginning of the file.
[in]error_ptrA pointer to a lldb_private::Status object that will be filled in if non-nullptr.
Returns
The resulting seek offset, or -1 on error.

Reimplemented from lldb_private::File.

Definition at line 368 of file File.cpp.

References lldb_private::Status::Clear(), lldb_private::Status::SetErrorString(), and lldb_private::Status::SetErrorToErrno().

◆ StreamIsValid()

bool lldb_private::NativeFile::StreamIsValid ( ) const
inlineprotected

Definition at line 416 of file File.h.

References lldb_private::File::kInvalidStream, and m_stream.

Referenced by IsValid().

◆ Sync()

Status NativeFile::Sync ( )
overridevirtual

Sync to disk.

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

Reimplemented from lldb_private::File.

Definition at line 457 of file File.cpp.

References error().

◆ Write() [1/2]

Status NativeFile::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::File.

Definition at line 539 of file File.cpp.

References error().

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

◆ Write() [2/2]

Status NativeFile::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.

Reimplemented from lldb_private::File.

Definition at line 661 of file File.cpp.

References error().

Member Data Documentation

◆ ID

char NativeFile::ID = 0
static

Definition at line 406 of file File.h.

Referenced by classof(), and isA().

◆ m_descriptor

int lldb_private::NativeFile::m_descriptor
protected

Definition at line 419 of file File.h.

Referenced by DescriptorIsValid().

◆ m_options

OpenOptions lldb_private::NativeFile::m_options {}
protected

Definition at line 422 of file File.h.

◆ m_own_descriptor

bool lldb_private::NativeFile::m_own_descriptor = false
protected

Definition at line 420 of file File.h.

◆ m_own_stream

bool lldb_private::NativeFile::m_own_stream = false
protected

Definition at line 423 of file File.h.

◆ m_stream

FILE* lldb_private::NativeFile::m_stream
protected

Definition at line 421 of file File.h.

Referenced by StreamIsValid().

◆ offset_access_mutex

std::mutex lldb_private::NativeFile::offset_access_mutex
protected

Definition at line 424 of file File.h.


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