LLDB mainline
|
A pseudo terminal helper class. More...
#include "lldb/Host/PseudoTerminal.h"
Public Types | |
enum | { invalid_fd = -1 } |
Public Member Functions | |
PseudoTerminal () | |
Default constructor. | |
~PseudoTerminal () | |
Destructor. | |
void | ClosePrimaryFileDescriptor () |
Close the primary file descriptor if it is valid. | |
void | CloseSecondaryFileDescriptor () |
Close the secondary file descriptor if it is valid. | |
llvm::Expected< lldb::pid_t > | Fork () |
Fork a child process that uses pseudo terminals for its stdio. | |
int | GetPrimaryFileDescriptor () const |
The primary file descriptor accessor. | |
int | GetSecondaryFileDescriptor () const |
The secondary file descriptor accessor. | |
std::string | GetSecondaryName () const |
Get the name of the secondary pseudo terminal. | |
llvm::Error | OpenFirstAvailablePrimary (int oflag) |
Open the first available pseudo terminal. | |
llvm::Error | OpenSecondary (int oflag) |
Open the secondary for the current primary pseudo terminal. | |
int | ReleasePrimaryFileDescriptor () |
Release the primary file descriptor. | |
int | ReleaseSecondaryFileDescriptor () |
Release the secondary file descriptor. | |
Protected Attributes | |
int | m_primary_fd = invalid_fd |
The file descriptor for the primary. | |
int | m_secondary_fd = invalid_fd |
The file descriptor for the secondary. | |
Private Member Functions | |
PseudoTerminal (const PseudoTerminal &)=delete | |
const PseudoTerminal & | operator= (const PseudoTerminal &)=delete |
A pseudo terminal helper class.
The pseudo terminal class abstracts the use of pseudo terminals on the host system.
Definition at line 24 of file PseudoTerminal.h.
anonymous enum |
Enumerator | |
---|---|
invalid_fd | Invalid file descriptor value. |
Definition at line 26 of file PseudoTerminal.h.
|
default |
Default constructor.
Constructs this object with invalid primary and secondary file descriptors.
PseudoTerminal::~PseudoTerminal | ( | ) |
Destructor.
The destructor will close the primary and secondary file descriptors if they are valid and ownership has not been released using one of:
Definition at line 45 of file PseudoTerminal.cpp.
References ClosePrimaryFileDescriptor(), and CloseSecondaryFileDescriptor().
|
privatedelete |
void PseudoTerminal::ClosePrimaryFileDescriptor | ( | ) |
Close the primary file descriptor if it is valid.
Definition at line 51 of file PseudoTerminal.cpp.
References invalid_fd, and m_primary_fd.
Referenced by Fork(), OpenFirstAvailablePrimary(), and ~PseudoTerminal().
void PseudoTerminal::CloseSecondaryFileDescriptor | ( | ) |
Close the secondary file descriptor if it is valid.
Definition at line 59 of file PseudoTerminal.cpp.
References invalid_fd, and m_secondary_fd.
Referenced by OpenSecondary(), and ~PseudoTerminal().
llvm::Expected< lldb::pid_t > PseudoTerminal::Fork | ( | ) |
Fork a child process that uses pseudo terminals for its stdio.
In the parent process, a call to this function results in a pid being returned. If the pid is valid, the primary file descriptor can be used for read/write access to stdio of the child process.
In the child process the stdin/stdout/stderr will already be routed to the secondary pseudo terminal and the primary file descriptor will be closed as it is no longer needed by the child process.
This class will close the file descriptors for the primary/secondary when the destructor is called. The file handles can be released using either:
Definition at line 139 of file PseudoTerminal.cpp.
References ClosePrimaryFileDescriptor(), fork(), m_secondary_fd, OpenFirstAvailablePrimary(), OpenSecondary(), and setsid().
int PseudoTerminal::GetPrimaryFileDescriptor | ( | ) | const |
The primary file descriptor accessor.
This object retains ownership of the primary file descriptor when this accessor is used. Users can call the member function PseudoTerminal::ReleasePrimaryFileDescriptor() if this object should release ownership of the secondary file descriptor.
Definition at line 189 of file PseudoTerminal.cpp.
References m_primary_fd.
Referenced by lldb_private::PlatformQemuUser::DebugProcess(), lldb_private::process_gdb_remote::ProcessGDBRemote::DoLaunch(), and HandleFileAction().
int PseudoTerminal::GetSecondaryFileDescriptor | ( | ) | const |
The secondary file descriptor accessor.
This object retains ownership of the secondary file descriptor when this accessor is used. Users can call the member function PseudoTerminal::ReleaseSecondaryFileDescriptor() if this object should release ownership of the secondary file descriptor.
Definition at line 195 of file PseudoTerminal.cpp.
References m_secondary_fd.
Referenced by HandleFileAction().
std::string PseudoTerminal::GetSecondaryName | ( | ) | const |
Get the name of the secondary pseudo terminal.
A primary pseudo terminal should already be valid prior to calling this function.
Definition at line 117 of file PseudoTerminal.cpp.
References m_primary_fd, PATH_MAX, UNUSED_IF_ASSERT_DISABLED, and use_ptsname().
Referenced by lldb_private::process_gdb_remote::ProcessGDBRemote::DoLaunch(), HandleFileAction(), and OpenSecondary().
llvm::Error PseudoTerminal::OpenFirstAvailablePrimary | ( | int | oflag | ) |
Open the first available pseudo terminal.
Opens the first available pseudo terminal with oflag as the permissions. The opened primary file descriptor is stored in this object and can be accessed by calling the PseudoTerminal::GetPrimaryFileDescriptor() accessor. Clients can call the PseudoTerminal::ReleasePrimaryFileDescriptor() accessor function if they wish to use the primary file descriptor beyond the lifespan of this object.
If this object still has a valid primary file descriptor when its destructor is called, it will close it.
[in] | oflag | Flags to use when calling posix_openpt (oflag). A value of "O_RDWR|O_NOCTTY" is suggested. |
Definition at line 66 of file PseudoTerminal.cpp.
References ClosePrimaryFileDescriptor(), grantpt(), m_primary_fd, posix_openpt(), and unlockpt().
Referenced by lldb_private::process_gdb_remote::ProcessGDBRemote::DoLaunch(), and Fork().
llvm::Error PseudoTerminal::OpenSecondary | ( | int | oflag | ) |
Open the secondary for the current primary pseudo terminal.
A primary pseudo terminal should already be valid prior to calling this function. The opened secondary file descriptor is stored in this object and can be accessed by calling the PseudoTerminal::GetSecondaryFileDescriptor() accessor. Clients can call the PseudoTerminal::ReleaseSecondaryFileDescriptor() accessor function if they wish to use the secondary file descriptor beyond the lifespan of this object.
If this object still has a valid secondary file descriptor when its destructor is called, it will close it.
[in] | oflag | Flags to use when calling open (oflag). |
Definition at line 95 of file PseudoTerminal.cpp.
References CloseSecondaryFileDescriptor(), GetSecondaryName(), lldb_private::FileSystem::Instance(), m_secondary_fd, and lldb_private::FileSystem::Open().
Referenced by Fork(), and HandleFileAction().
|
privatedelete |
int PseudoTerminal::ReleasePrimaryFileDescriptor | ( | ) |
Release the primary file descriptor.
Releases ownership of the primary pseudo terminal file descriptor without closing it. The destructor for this class will close the primary file descriptor if the ownership isn't released using this call and the primary file descriptor has been opened.
Definition at line 203 of file PseudoTerminal.cpp.
References invalid_fd, and m_primary_fd.
Referenced by PlatformPOSIX::DebugProcess(), lldb_private::Platform::DebugProcess(), lldb_private::PlatformAppleSimulator::DebugProcess(), lldb_private::PlatformQemuUser::DebugProcess(), lldb_private::process_gdb_remote::ProcessGDBRemote::DoLaunch(), lldb_private::process_freebsd::NativeProcessFreeBSD::Manager::Launch(), lldb_private::process_linux::NativeProcessLinux::Manager::Launch(), and lldb_private::process_netbsd::NativeProcessNetBSD::Manager::Launch().
int PseudoTerminal::ReleaseSecondaryFileDescriptor | ( | ) |
Release the secondary file descriptor.
Release ownership of the secondary pseudo terminal file descriptor without closing it. The destructor for this class will close the secondary file descriptor if the ownership isn't released using this call and the secondary file descriptor has been opened.
Definition at line 215 of file PseudoTerminal.cpp.
References invalid_fd, and m_secondary_fd.
|
protected |
The file descriptor for the primary.
Definition at line 178 of file PseudoTerminal.h.
Referenced by ClosePrimaryFileDescriptor(), GetPrimaryFileDescriptor(), GetSecondaryName(), OpenFirstAvailablePrimary(), and ReleasePrimaryFileDescriptor().
|
protected |
The file descriptor for the secondary.
Definition at line 179 of file PseudoTerminal.h.
Referenced by CloseSecondaryFileDescriptor(), Fork(), GetSecondaryFileDescriptor(), OpenSecondary(), and ReleaseSecondaryFileDescriptor().