LLDB mainline
|
#include <File.h>
Classes | |
struct | ValueGuard |
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. | |
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. | |
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, select, or epoll. | |
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 | 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. | |
Status | Flush () override |
Flush the current stream. | |
Status | Sync () override |
Sync to disk. | |
size_t | PrintfVarArg (const char *format, va_list args) override |
Output printf formatted output to the stream. | |
llvm::Expected< OpenOptions > | GetOptions () const override |
Return the OpenOptions for this file. | |
bool | isA (const void *classID) const override |
Public Member Functions inherited from lldb_private::File | |
File () | |
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. | |
bool | IsValid () const override |
IsValid. | |
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, select, or epoll. | |
virtual Status | GetFileSpec (FileSpec &file_spec) const |
Get the file specification for this file, if possible. | |
virtual int | GetDescriptor () const |
Get underlying OS file descriptor for this file, or kInvalidDescriptor. | |
virtual FILE * | GetStream () |
Get the underlying libc stream for this file, or NULL. | |
virtual off_t | SeekFromStart (off_t offset, Status *error_ptr=nullptr) |
Seek to an offset relative to the beginning of the file. | |
virtual off_t | SeekFromCurrent (off_t offset, Status *error_ptr=nullptr) |
Seek to an offset relative to the current file position. | |
virtual off_t | SeekFromEnd (off_t offset, Status *error_ptr=nullptr) |
Seek to an offset relative to the end of the file. | |
virtual Status | Read (void *dst, size_t &num_bytes, off_t &offset) |
Read bytes from a file from the specified file offset. | |
virtual Status | Write (const void *src, size_t &num_bytes, off_t &offset) |
Write bytes to a file at the specified file offset. | |
virtual Status | Flush () |
Flush the current stream. | |
virtual Status | Sync () |
Sync to disk. | |
size_t | Printf (const char *format,...) __attribute__((format(printf |
Output printf formatted output to the stream. | |
size_t virtual size_t | PrintfVarArg (const char *format, va_list args) |
Output printf formatted output to the stream. | |
virtual llvm::Expected< OpenOptions > | GetOptions () const |
Return the OpenOptions for this file. | |
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 |
virtual bool | isA (const void *classID) const |
Public Member Functions inherited from lldb_private::IOObject | |
IOObject (FDType type) | |
virtual | ~IOObject () |
virtual Status | Read (void *buf, size_t &num_bytes)=0 |
virtual Status | Write (const void *buf, size_t &num_bytes)=0 |
virtual bool | IsValid () const =0 |
virtual Status | Close ()=0 |
FDType | GetFdType () const |
virtual WaitableHandle | GetWaitableHandle ()=0 |
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< OpenOptions > | GetOptionsFromMode (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 | DescriptorIsValidUnlocked () const |
bool | StreamIsValidUnlocked () const |
ValueGuard | DescriptorIsValid () const |
ValueGuard | StreamIsValid () const |
Protected Member Functions inherited from lldb_private::File | |
void | CalculateInteractiveAndTerminal () |
Protected Attributes | |
int | m_descriptor |
bool | m_own_descriptor = false |
std::mutex | m_descriptor_mutex |
FILE * | m_stream |
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 |
Private Member Functions | |
NativeFile (const NativeFile &)=delete | |
const NativeFile & | operator= (const NativeFile &)=delete |
Additional Inherited Members | |
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 } |
typedef int | WaitableHandle |
|
inline |
|
inline |
|
inlineoverride |
|
privatedelete |
|
inlinestatic |
Definition at line 415 of file File.h.
References ID, and lldb_private::File::isA().
|
overridevirtual |
Flush any buffers and release any resources owned by the file.
After Close() the file will be invalid.
Reimplemented from lldb_private::File.
Reimplemented in lldb_private::SerialPort.
Definition at line 315 of file File.cpp.
References DescriptorIsValidUnlocked(), lldb_private::eLazyBoolCalculate, lldb_private::File::eOpenOptionReadOnly, lldb_private::File::eOpenOptionReadWrite, lldb_private::File::eOpenOptionWriteOnly, error(), lldb_private::File::kInvalidDescriptor, lldb_private::File::kInvalidStream, m_descriptor, m_descriptor_mutex, lldb_private::File::m_is_interactive, lldb_private::File::m_is_real_terminal, m_options, m_own_descriptor, m_own_stream, m_stream, m_stream_mutex, and StreamIsValidUnlocked().
Referenced by lldb_private::ClangUtilityFunction::ClangUtilityFunction(), lldb_private::SerialPort::Close(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Close(), lldb_private::ClangExpressionParser::ParseInternal(), and ~NativeFile().
|
inlineprotected |
Definition at line 432 of file File.h.
References DescriptorIsValidUnlocked(), and m_descriptor_mutex.
Referenced by Flush(), GetDescriptor(), GetStream(), Read(), SeekFromCurrent(), SeekFromEnd(), SeekFromStart(), Sync(), and Write().
|
inlineprotected |
Definition at line 425 of file File.h.
References lldb_private::File::DescriptorIsValid(), and m_descriptor.
Referenced by Close(), DescriptorIsValid(), and IsValid().
|
overridevirtual |
Flush the current stream.
Reimplemented from lldb_private::File.
Definition at line 479 of file File.cpp.
References DescriptorIsValid(), error(), m_stream, and StreamIsValid().
|
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.
Reimplemented from lldb_private::File.
Definition at line 257 of file File.cpp.
References DescriptorIsValid(), lldb_private::File::kInvalidDescriptor, m_descriptor, m_stream, and StreamIsValid().
Referenced by GetFileSpec(), GetWaitableHandle(), Read(), and Write().
Get the file specification for this file, if possible.
[out] | file_spec | the file specification. |
Reimplemented from lldb_private::File.
Definition at line 351 of file File.cpp.
References lldb_private::FileSpec::Clear(), error(), GetDescriptor(), IsValid(), PATH_MAX, and lldb_private::FileSpec::SetFile().
|
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 eOpenOptionReadOnly, eOpenOptionWriteOnly or eOpenOptionReadWrite here.
Reimplemented from lldb_private::File.
Definition at line 255 of file File.cpp.
References m_options.
|
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.
Reimplemented from lldb_private::File.
Definition at line 280 of file File.cpp.
References DescriptorIsValid(), lldb_private::File::GetStreamOpenModeFromOptions(), m_descriptor, m_options, m_own_descriptor, m_own_stream, m_stream, and StreamIsValid().
|
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.
Reimplemented from lldb_private::File.
Definition at line 276 of file File.cpp.
References GetDescriptor().
|
inlineoverridevirtual |
Reimplemented from lldb_private::File.
Reimplemented in lldb_private::SerialPort.
Definition at line 412 of file File.h.
References ID, and lldb_private::File::isA().
|
overridevirtual |
IsValid.
Reimplemented from lldb_private::File.
Reimplemented in lldb_private::SerialPort.
Definition at line 250 of file File.cpp.
References DescriptorIsValidUnlocked(), m_descriptor_mutex, m_stream_mutex, and StreamIsValidUnlocked().
Referenced by GetFileSpec(), and lldb_private::SerialPort::IsValid().
|
privatedelete |
|
overridevirtual |
Output printf formatted output to the stream.
Print some formatted output to the stream.
[in] | format | A printf style format string. |
[in] | args | Variable arguments that are needed for the printf style format string format. |
Reimplemented from lldb_private::File.
Definition at line 770 of file File.cpp.
References m_stream, lldb_private::File::PrintfVarArg(), and StreamIsValid().
|
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.
[in,out] | num_bytes | Pass in the size of buf. Read will pass out the number of bytes read. Zero bytes read with no error indicates EOF. |
Reimplemented from lldb_private::File.
Definition at line 518 of file File.cpp.
References DescriptorIsValid(), error(), m_descriptor, m_stream, Read(), and StreamIsValid().
Referenced by lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pRead(), and Read().
|
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.
[in] | dst | A buffer where to put the bytes that are read. |
[in,out] | num_bytes | The number of bytes to read from the current file position which gets modified with the number of bytes that were read. |
[in,out] | offset | The offset within the file from which to read num_bytes bytes. This offset gets incremented by the number of bytes that were read. |
Reimplemented from lldb_private::File.
Definition at line 646 of file File.cpp.
References error(), GetDescriptor(), lldb_private::File::kInvalidDescriptor, m_descriptor, offset_access_mutex, Read(), and SeekFromStart().
|
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:
[in] | offset | The offset to seek to within the file relative to the current file position. |
[in] | error_ptr | A pointer to a lldb_private::Status object that will be filled in if non-nullptr. |
Reimplemented from lldb_private::File.
Definition at line 418 of file File.cpp.
References lldb_private::Status::Clear(), DescriptorIsValid(), m_descriptor, m_stream, lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorToErrno(), and StreamIsValid().
|
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:
[in,out] | offset | The 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_ptr | A pointer to a lldb_private::Status object that will be filled in if non-nullptr. |
Reimplemented from lldb_private::File.
Definition at line 449 of file File.cpp.
References lldb_private::Status::Clear(), DescriptorIsValid(), m_descriptor, m_stream, lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorToErrno(), and StreamIsValid().
|
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:
[in] | offset | The offset to seek to within the file relative to the beginning of the file. |
[in] | error_ptr | A pointer to a lldb_private::Status object that will be filled in if non-nullptr. |
Reimplemented from lldb_private::File.
Definition at line 387 of file File.cpp.
References lldb_private::Status::Clear(), DescriptorIsValid(), m_descriptor, m_stream, lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorToErrno(), and StreamIsValid().
|
inlineprotected |
Definition at line 437 of file File.h.
References m_stream_mutex, and StreamIsValidUnlocked().
Referenced by Flush(), GetDescriptor(), GetStream(), PrintfVarArg(), Read(), SeekFromCurrent(), SeekFromEnd(), SeekFromStart(), and Write().
|
inlineprotected |
Definition at line 430 of file File.h.
References lldb_private::File::kInvalidStream, and m_stream.
Referenced by Close(), IsValid(), and StreamIsValid().
|
overridevirtual |
Sync to disk.
Reimplemented from lldb_private::File.
Definition at line 495 of file File.cpp.
References DescriptorIsValid(), error(), and m_descriptor.
|
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.
[in,out] | num_bytes | Pass 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. |
Reimplemented from lldb_private::File.
Definition at line 582 of file File.cpp.
References DescriptorIsValid(), error(), m_descriptor, m_stream, StreamIsValid(), and Write().
Referenced by lldb_private::ClangUtilityFunction::ClangUtilityFunction(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite(), lldb_private::ClangExpressionParser::ParseInternal(), and Write().
|
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.
[in] | src | A buffer containing the bytes to write. |
[in,out] | num_bytes | The 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] | offset | The offset within the file at which to write num_bytes bytes. This offset gets incremented by the number of bytes that were written. |
Reimplemented from lldb_private::File.
Definition at line 706 of file File.cpp.
References error(), GetDescriptor(), lldb_private::File::kInvalidDescriptor, m_descriptor, offset_access_mutex, SeekFromStart(), and Write().
|
static |
|
protected |
Definition at line 442 of file File.h.
Referenced by Close(), DescriptorIsValidUnlocked(), GetDescriptor(), GetStream(), Read(), SeekFromCurrent(), SeekFromEnd(), SeekFromStart(), Sync(), and Write().
|
mutableprotected |
Definition at line 444 of file File.h.
Referenced by Close(), DescriptorIsValid(), and IsValid().
|
protected |
Definition at line 449 of file File.h.
Referenced by Close(), GetOptions(), and GetStream().
|
protected |
Definition at line 443 of file File.h.
Referenced by Close(), and GetStream().
|
protected |
Definition at line 450 of file File.h.
Referenced by Close(), and GetStream().
|
protected |
Definition at line 446 of file File.h.
Referenced by Close(), Flush(), GetDescriptor(), GetStream(), PrintfVarArg(), Read(), SeekFromCurrent(), SeekFromEnd(), SeekFromStart(), StreamIsValidUnlocked(), and Write().
|
mutableprotected |
Definition at line 447 of file File.h.
Referenced by Close(), IsValid(), and StreamIsValid().
|
protected |