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

A RAII-friendly terminal state saving/restoring class. More...

#include "lldb/Host/Terminal.h"

Public Member Functions

 TerminalState (Terminal term=-1, bool save_process_group=false)
 Construct a new instance and optionally save terminal state.
 
 ~TerminalState ()
 Destroy the instance, restoring terminal state if saved.
 
bool Save (Terminal term, bool save_process_group)
 Save the TTY state for fd.
 
bool Restore () const
 Restore the TTY state to the cached state.
 
bool IsValid () const
 Test for valid cached TTY state information.
 
void Clear ()
 

Protected Member Functions

bool TFlagsIsValid () const
 Test if tflags is valid.
 
bool TTYStateIsValid () const
 Test if ttystate is valid.
 
bool ProcessGroupIsValid () const
 Test if the process group information is valid.
 

Protected Attributes

Terminal m_tty
 A terminal.
 
int m_tflags = -1
 Cached tflags information.
 
std::unique_ptr< Terminal::Datam_data
 Platform-specific implementation.
 
lldb::pid_t m_process_group = -1
 Cached process group information.
 

Detailed Description

A RAII-friendly terminal state saving/restoring class.

This class can be used to remember the terminal state for a file descriptor and later restore that state as it originally was.

Definition at line 87 of file Terminal.h.

Constructor & Destructor Documentation

◆ TerminalState()

TerminalState::TerminalState ( Terminal  term = -1,
bool  save_process_group = false 
)

Construct a new instance and optionally save terminal state.

Parameters
[in]termThe Terminal instance holding the file descriptor to save the state of. If the instance is not associated with a fd, no state will be saved.
[in]save_process_groupIf true, save the process group settings, else do not save the process group settings for a TTY.

Definition at line 403 of file Terminal.cpp.

References Save().

◆ ~TerminalState()

TerminalState::~TerminalState ( )

Destroy the instance, restoring terminal state if saved.

If restoring state is undesirable, the instance needs to be reset before destruction.

Definition at line 408 of file Terminal.cpp.

References Restore().

Member Function Documentation

◆ Clear()

void TerminalState::Clear ( )

Definition at line 410 of file Terminal.cpp.

References lldb_private::Terminal::Clear(), m_data, m_process_group, m_tflags, and m_tty.

Referenced by lldb_private::Debugger::Clear(), and Save().

◆ IsValid()

bool TerminalState::IsValid ( ) const

Test for valid cached TTY state information.

Returns
Returns true if this object has valid saved TTY state settings that can be used to restore a previous state, false otherwise.

Definition at line 463 of file Terminal.cpp.

References lldb_private::Terminal::FileDescriptorIsValid(), m_tty, ProcessGroupIsValid(), TFlagsIsValid(), and TTYStateIsValid().

Referenced by Restore(), and Save().

◆ ProcessGroupIsValid()

bool TerminalState::ProcessGroupIsValid ( ) const
protected

Test if the process group information is valid.

Returns
Returns true if m_process_group is valid and can be restored, false otherwise.

Definition at line 472 of file Terminal.cpp.

References m_process_group.

Referenced by IsValid(), and Restore().

◆ Restore()

bool TerminalState::Restore ( ) const

Restore the TTY state to the cached state.

Restore the state of the TTY using the cached values from a previous call to TerminalState::Save(int,bool).

Returns
Returns true if the TTY state was successfully restored, false otherwise.

Definition at line 436 of file Terminal.cpp.

References lldb_private::Terminal::GetFileDescriptor(), IsValid(), m_data, m_process_group, m_tflags, m_tty, ProcessGroupIsValid(), TFlagsIsValid(), and TTYStateIsValid().

Referenced by lldb_private::SerialPort::Close(), lldb_private::Debugger::RestoreInputTerminalState(), and ~TerminalState().

◆ Save()

bool TerminalState::Save ( Terminal  term,
bool  save_process_group 
)

Save the TTY state for fd.

Save the current state of the TTY for the file descriptor "fd" and if "save_process_group" is true, attempt to save the process group info for the TTY.

Parameters
[in]termThe Terminal instance holding fd to save.
[in]save_process_groupIf true, save the process group settings, else do not save the process group settings for a TTY.
Returns
Returns true if fd describes a TTY and if the state was able to be saved, false otherwise.

Definition at line 417 of file Terminal.cpp.

References Clear(), lldb_private::Terminal::GetFileDescriptor(), lldb_private::Terminal::IsATerminal(), IsValid(), m_data, m_process_group, m_tflags, and m_tty.

Referenced by lldb_private::Debugger::SaveInputTerminalState(), and TerminalState().

◆ TFlagsIsValid()

bool TerminalState::TFlagsIsValid ( ) const
protected

Test if tflags is valid.

Returns
Returns true if m_tflags is valid and can be restored, false otherwise.

Definition at line 468 of file Terminal.cpp.

References m_tflags.

Referenced by IsValid(), and Restore().

◆ TTYStateIsValid()

bool TerminalState::TTYStateIsValid ( ) const
protected

Test if ttystate is valid.

Returns
Returns true if m_ttystate is valid and can be restored, false otherwise.

Definition at line 470 of file Terminal.cpp.

References m_data.

Referenced by IsValid(), and Restore().

Member Data Documentation

◆ m_data

std::unique_ptr<Terminal::Data> lldb_private::TerminalState::m_data
protected

Platform-specific implementation.

Definition at line 168 of file Terminal.h.

Referenced by Clear(), Restore(), Save(), and TTYStateIsValid().

◆ m_process_group

lldb::pid_t lldb_private::TerminalState::m_process_group = -1
protected

Cached process group information.

Definition at line 169 of file Terminal.h.

Referenced by Clear(), ProcessGroupIsValid(), Restore(), and Save().

◆ m_tflags

int lldb_private::TerminalState::m_tflags = -1
protected

Cached tflags information.

Definition at line 167 of file Terminal.h.

Referenced by Clear(), Restore(), Save(), and TFlagsIsValid().

◆ m_tty

Terminal lldb_private::TerminalState::m_tty
protected

A terminal.

Definition at line 166 of file Terminal.h.

Referenced by Clear(), IsValid(), Restore(), and Save().


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