Index: lldb/include/lldb/Host/Terminal.h =================================================================== --- lldb/include/lldb/Host/Terminal.h +++ lldb/include/lldb/Host/Terminal.h @@ -13,6 +13,10 @@ #include "lldb/Host/Config.h" #include "lldb/lldb-private.h" +#if LLDB_ENABLE_TERMIOS +#include +#endif + struct termios; namespace lldb_private { @@ -48,12 +52,6 @@ /// descriptor and later restore that state as it originally was. class TerminalState { public: - /// Default constructor - TerminalState(); - - /// Destructor - ~TerminalState(); - /// Save the TTY state for \a fd. /// /// Save the current state of the TTY for the file descriptor "fd" and if @@ -115,11 +113,11 @@ bool ProcessGroupIsValid() const; // Member variables - Terminal m_tty; ///< A terminal - int m_tflags = -1; ///< Cached tflags information. + Terminal m_tty; ///< A terminal + int m_tflags = -1; ///< Cached tflags information. + bool m_termios_saved = false; ///< Indication whether termios was saved. #if LLDB_ENABLE_TERMIOS - std::unique_ptr - m_termios_up; ///< Cached terminal state information. + struct termios m_termios; ///< Cached terminal state information. #endif lldb::pid_t m_process_group = -1; ///< Cached process group information. }; Index: lldb/source/Host/common/Terminal.cpp =================================================================== --- lldb/source/Host/common/Terminal.cpp +++ lldb/source/Host/common/Terminal.cpp @@ -15,10 +15,6 @@ #include #include -#if LLDB_ENABLE_TERMIOS -#include -#endif - using namespace lldb_private; bool Terminal::IsATerminal() const { return m_fd >= 0 && ::isatty(m_fd); } @@ -81,25 +77,10 @@ return false; } -// Default constructor -TerminalState::TerminalState() - : m_tty() -#if LLDB_ENABLE_TERMIOS - , - m_termios_up() -#endif -{ -} - -// Destructor -TerminalState::~TerminalState() = default; - void TerminalState::Clear() { m_tty.Clear(); m_tflags = -1; -#if LLDB_ENABLE_TERMIOS - m_termios_up.reset(); -#endif + m_termios_saved = false; m_process_group = -1; } @@ -107,31 +88,18 @@ // "save_process_group" is true, attempt to save the process group info for the // TTY. bool TerminalState::Save(int fd, bool save_process_group) { + Clear(); m_tty.SetFileDescriptor(fd); if (m_tty.IsATerminal()) { #if LLDB_ENABLE_POSIX m_tflags = ::fcntl(fd, F_GETFL, 0); -#endif #if LLDB_ENABLE_TERMIOS - if (m_termios_up == nullptr) - m_termios_up.reset(new struct termios); - int err = ::tcgetattr(fd, m_termios_up.get()); - if (err != 0) - m_termios_up.reset(); -#endif // #if LLDB_ENABLE_TERMIOS -#if LLDB_ENABLE_POSIX + if (::tcgetattr(fd, &m_termios) == 0) + m_termios_saved = true; +#endif // LLDB_ENABLE_TERMIOS if (save_process_group) m_process_group = ::tcgetpgrp(0); - else - m_process_group = -1; -#endif - } else { - m_tty.Clear(); - m_tflags = -1; -#if LLDB_ENABLE_TERMIOS - m_termios_up.reset(); -#endif - m_process_group = -1; +#endif // LLDB_ENABLE_POSIX } return IsValid(); } @@ -147,8 +115,8 @@ #if LLDB_ENABLE_TERMIOS if (TTYStateIsValid()) - tcsetattr(fd, TCSANOW, m_termios_up.get()); -#endif // #if LLDB_ENABLE_TERMIOS + tcsetattr(fd, TCSANOW, &m_termios); +#endif // LLDB_ENABLE_TERMIOS if (ProcessGroupIsValid()) { // Save the original signal handler. @@ -161,7 +129,7 @@ } return true; } -#endif +#endif // LLDB_ENABLE_POSIX return false; } @@ -176,13 +144,7 @@ bool TerminalState::TFlagsIsValid() const { return m_tflags != -1; } // Returns true if m_ttystate is valid -bool TerminalState::TTYStateIsValid() const { -#if LLDB_ENABLE_TERMIOS - return m_termios_up != nullptr; -#else - return false; -#endif -} +bool TerminalState::TTYStateIsValid() const { return m_termios_saved; } // Returns true if m_process_group is valid bool TerminalState::ProcessGroupIsValid() const {