[Lldb-commits] [lldb] r125057 - in /lldb/trunk: include/lldb/Core/TTYState.h include/lldb/Host/Terminal.h include/lldb/Interpreter/ScriptInterpreterPython.h lldb.xcodeproj/project.pbxproj source/Core/Debugger.cpp source/Core/TTYState.cpp source/Host/common/Terminal.cpp source/Interpreter/ScriptInterpreterPython.cpp

Greg Clayton gclayton at apple.com
Mon Feb 7 15:24:47 PST 2011


Author: gclayton
Date: Mon Feb  7 17:24:47 2011
New Revision: 125057

URL: http://llvm.org/viewvc/llvm-project?rev=125057&view=rev
Log:
Abtract terminal stuff into a new lldb_private::Terminal class
where the implementation is hidden in the host layer. This avoids
a slew of "#if LLDB_CONFIG_TERMIOS_SUPPORTED" statements in the
code and keeps things cleaner.


Added:
    lldb/trunk/include/lldb/Host/Terminal.h
    lldb/trunk/source/Host/common/Terminal.cpp
Removed:
    lldb/trunk/include/lldb/Core/TTYState.h
    lldb/trunk/source/Core/TTYState.cpp
Modified:
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp

Removed: lldb/trunk/include/lldb/Core/TTYState.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/TTYState.h?rev=125056&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Core/TTYState.h (original)
+++ lldb/trunk/include/lldb/Core/TTYState.h (removed)
@@ -1,207 +0,0 @@
-//===-- TTYState.h ----------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_TTYState_h_
-#define liblldb_TTYState_h_
-#if defined(__cplusplus)
-
-#include "lldb/Host/Config.h"
-
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-#include <termios.h>
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
-
-#include "lldb/lldb-private.h"
-
-namespace lldb_private {
-
-//----------------------------------------------------------------------
-/// @class TTYState TTYState.h "lldb/Core/TTYState.h"
-/// @brief A TTY state managment class.
-///
-/// This class can be used to remember the TTY state for a file
-/// descriptor and later restore that state as it originally was.
-//----------------------------------------------------------------------
-class TTYState
-{
-public:
-    //------------------------------------------------------------------
-    /// Default constructor
-    //------------------------------------------------------------------
-    TTYState();
-
-    //------------------------------------------------------------------
-    /// Destructor
-    //------------------------------------------------------------------
-    ~TTYState();
-
-    //------------------------------------------------------------------
-    /// Save the TTY state for \a 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.
-    ///
-    /// @param[in] fd
-    ///     The file descriptor to save the state of.
-    ///
-    /// @param[in] save_process_group
-    ///     If \b true, save the process group settings, else do not
-    ///     save the process group setttings for a TTY.
-    ///
-    /// @return
-    ///     Returns \b true if \a fd describes a TTY and if the state
-    ///     was able to be saved, \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    Save (int fd, bool save_process_group);
-
-    //------------------------------------------------------------------
-    /// Restore the TTY state to the cached state.
-    ///
-    /// Restore the state of the TTY using the cached values from a
-    /// previous call to TTYState::Save(int,bool).
-    ///
-    /// @return
-    ///     Returns \b true if the TTY state was successfully restored,
-    ///     \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    Restore () const;
-
-    //------------------------------------------------------------------
-    /// Test for valid cached TTY state information.
-    ///
-    /// @return
-    ///     Returns \b true if this object has valid saved TTY state
-    ///     settings that can be used to restore a previous state,
-    ///     \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    IsValid() const;
-
-protected:
-
-    //------------------------------------------------------------------
-    /// Test if tflags is valid.
-    ///
-    /// @return
-    ///     Returns \b true if \a m_tflags is valid and can be restored,
-    ///     \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    TFlagsIsValid() const;
-
-    //------------------------------------------------------------------
-    /// Test if ttystate is valid.
-    ///
-    /// @return
-    ///     Returns \b true if \a m_ttystate is valid and can be
-    ///     restored, \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    TTYStateIsValid() const;
-
-    //------------------------------------------------------------------
-    /// Test if the process group information is valid.
-    ///
-    /// @return
-    ///     Returns \b true if \a m_process_group is valid and can be
-    ///     restored, \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    ProcessGroupIsValid() const;
-
-    //------------------------------------------------------------------
-    // Member variables
-    //------------------------------------------------------------------
-    int             m_fd;           ///< File descriptor of the TTY.
-    int             m_tflags;       ///< Cached tflags information.
-    int             m_ttystate_err; ///< Error value from call to save tflags.
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-    struct termios  m_ttystate;     ///< Cached ttystate information.
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
-    lldb::pid_t     m_process_group;///< Cached process group information.
-
-};
-
-//----------------------------------------------------------------------
-/// @class TTYStateSwitcher TTYState.h "lldb/Core/TTYState.h"
-/// @brief A TTY state switching class.
-///
-/// This class can be used to remember 2 TTY states for a given file
-/// descriptor and switch between the two states.
-//----------------------------------------------------------------------
-class TTYStateSwitcher
-{
-public:
-    //------------------------------------------------------------------
-    /// Constructor
-    //------------------------------------------------------------------
-    TTYStateSwitcher();
-
-    //------------------------------------------------------------------
-    /// Destructor
-    //------------------------------------------------------------------
-    ~TTYStateSwitcher();
-
-    //------------------------------------------------------------------
-    /// Get the number of possible states to save.
-    ///
-    /// @return
-    ///     The number of states that this TTY switcher object contains.
-    //------------------------------------------------------------------
-    uint32_t
-    GetNumberOfStates() const;
-
-    //------------------------------------------------------------------
-    /// Restore the TTY state for state at index \a idx.
-    ///
-    /// @return
-    ///     Returns \b true if the TTY state was successfully restored,
-    ///     \b false otherwise.
-    //------------------------------------------------------------------
-    bool
-    Restore (uint32_t idx) const;
-
-    //------------------------------------------------------------------
-    /// Save the TTY state information for the state at index \a idx.
-    /// The TTY state is saved for the file descriptor \a fd and
-    /// the process group information will also be saved if requested
-    /// by \a save_process_group.
-    ///
-    /// @param[in] idx
-    ///     The index into the state array where the state should be
-    ///     saved.
-    ///
-    /// @param[in] fd
-    ///     The file descriptor for which to save the settings.
-    ///
-    /// @param[in] save_process_group
-    ///     If \b true, save the process group information for the TTY.
-    ///
-    /// @return
-    ///     Returns \b true if the save was successful, \b false
-    ///     otherwise.
-    //------------------------------------------------------------------
-    bool
-    Save (uint32_t idx, int fd, bool save_process_group);
-
-protected:
-    //------------------------------------------------------------------
-    // Member variables
-    //------------------------------------------------------------------
-    mutable uint32_t m_currentState; ///< The currently active TTY state index.
-    TTYState m_ttystates[2]; ///< The array of TTY states that holds saved TTY info.
-};
-
-} // namespace lldb_private
-
-#endif  // #if defined(__cplusplus)
-#endif  // #ifndef liblldb_TTYState_h_

Added: lldb/trunk/include/lldb/Host/Terminal.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Terminal.h?rev=125057&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Host/Terminal.h (added)
+++ lldb/trunk/include/lldb/Host/Terminal.h Mon Feb  7 17:24:47 2011
@@ -0,0 +1,251 @@
+//===-- Terminal.h ----------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_Terminal_h_
+#define liblldb_Terminal_h_
+#if defined(__cplusplus)
+
+#include "lldb/lldb-private.h"
+
+struct termios;
+
+namespace lldb_private {
+
+class Terminal
+{
+public:
+
+    Terminal (int fd = -1) :
+        m_fd (fd)
+    {
+    }
+    
+    ~Terminal ()
+    {
+    }
+
+    bool
+    IsATerminal () const;
+
+    int
+    GetFileDescriptor () const
+    {
+        return m_fd;
+    }
+
+    void
+    SetFileDescriptor (int fd)
+    {
+        m_fd = fd;
+    }
+
+    bool
+    FileDescriptorIsValid () const
+    {
+        return m_fd != -1;
+    }
+
+    void
+    Clear ()
+    {
+        m_fd = -1;
+    }
+
+    bool
+    SetEcho (bool enabled);
+
+    bool
+    SetCanonical (bool enabled);
+
+protected:
+    int m_fd;   // This may or may not be a terminal file descriptor
+};
+
+
+//----------------------------------------------------------------------
+/// @class State Terminal.h "lldb/Host/Terminal.h"
+/// @brief A 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.
+//----------------------------------------------------------------------
+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 "save_process_group" is true, attempt to save the process
+    /// group info for the TTY.
+    ///
+    /// @param[in] fd
+    ///     The file descriptor to save the state of.
+    ///
+    /// @param[in] save_process_group
+    ///     If \b true, save the process group settings, else do not
+    ///     save the process group setttings for a TTY.
+    ///
+    /// @return
+    ///     Returns \b true if \a fd describes a TTY and if the state
+    ///     was able to be saved, \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    Save (int fd, bool save_process_group);
+
+    //------------------------------------------------------------------
+    /// 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).
+    ///
+    /// @return
+    ///     Returns \b true if the TTY state was successfully restored,
+    ///     \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    Restore () const;
+
+    //------------------------------------------------------------------
+    /// Test for valid cached TTY state information.
+    ///
+    /// @return
+    ///     Returns \b true if this object has valid saved TTY state
+    ///     settings that can be used to restore a previous state,
+    ///     \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    IsValid() const;
+
+protected:
+
+    //------------------------------------------------------------------
+    /// Test if tflags is valid.
+    ///
+    /// @return
+    ///     Returns \b true if \a m_tflags is valid and can be restored,
+    ///     \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    TFlagsIsValid() const;
+
+    //------------------------------------------------------------------
+    /// Test if ttystate is valid.
+    ///
+    /// @return
+    ///     Returns \b true if \a m_ttystate is valid and can be
+    ///     restored, \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    TTYStateIsValid() const;
+
+    //------------------------------------------------------------------
+    /// Test if the process group information is valid.
+    ///
+    /// @return
+    ///     Returns \b true if \a m_process_group is valid and can be
+    ///     restored, \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    ProcessGroupIsValid() const;
+
+    //------------------------------------------------------------------
+    // Member variables
+    //------------------------------------------------------------------
+    Terminal        m_tty;          ///< A terminal
+    int             m_tflags;       ///< Cached tflags information.
+    std::auto_ptr<struct termios> m_termios_ap; ///< Cached terminal state information.
+    lldb::pid_t     m_process_group;///< Cached process group information.
+
+};
+
+//----------------------------------------------------------------------
+/// @class TerminalStateSwitcher Terminal.h "lldb/Host/Terminal.h"
+/// @brief A TTY state switching class.
+///
+/// This class can be used to remember 2 TTY states for a given file
+/// descriptor and switch between the two states.
+//----------------------------------------------------------------------
+class TerminalStateSwitcher
+{
+public:
+    //------------------------------------------------------------------
+    /// Constructor
+    //------------------------------------------------------------------
+    TerminalStateSwitcher();
+
+    //------------------------------------------------------------------
+    /// Destructor
+    //------------------------------------------------------------------
+    ~TerminalStateSwitcher();
+
+    //------------------------------------------------------------------
+    /// Get the number of possible states to save.
+    ///
+    /// @return
+    ///     The number of states that this TTY switcher object contains.
+    //------------------------------------------------------------------
+    uint32_t
+    GetNumberOfStates() const;
+
+    //------------------------------------------------------------------
+    /// Restore the TTY state for state at index \a idx.
+    ///
+    /// @return
+    ///     Returns \b true if the TTY state was successfully restored,
+    ///     \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    Restore (uint32_t idx) const;
+
+    //------------------------------------------------------------------
+    /// Save the TTY state information for the state at index \a idx.
+    /// The TTY state is saved for the file descriptor \a fd and
+    /// the process group information will also be saved if requested
+    /// by \a save_process_group.
+    ///
+    /// @param[in] idx
+    ///     The index into the state array where the state should be
+    ///     saved.
+    ///
+    /// @param[in] fd
+    ///     The file descriptor for which to save the settings.
+    ///
+    /// @param[in] save_process_group
+    ///     If \b true, save the process group information for the TTY.
+    ///
+    /// @return
+    ///     Returns \b true if the save was successful, \b false
+    ///     otherwise.
+    //------------------------------------------------------------------
+    bool
+    Save (uint32_t idx, int fd, bool save_process_group);
+
+protected:
+    //------------------------------------------------------------------
+    // Member variables
+    //------------------------------------------------------------------
+    mutable uint32_t m_currentState; ///< The currently active TTY state index.
+    TerminalState m_ttystates[2]; ///< The array of TTY states that holds saved TTY info.
+};
+
+} // namespace lldb_private
+
+#endif  // #if defined(__cplusplus)
+#endif  // #ifndef liblldb_Terminal_h_

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=125057&r1=125056&r2=125057&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Mon Feb  7 17:24:47 2011
@@ -17,15 +17,10 @@
 #include <Python.h>
 #endif
 
-#include "lldb/Host/Config.h"
-
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-#include <termios.h>
-#endif
-
 #include "lldb/lldb-private.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
 #include "lldb/Core/InputReader.h"
+#include "lldb/Host/Terminal.h"
 
 namespace lldb_private {
 
@@ -102,6 +97,12 @@
     void
     LeaveSession ();
     
+    void
+    SaveTerminalState (int fd);
+
+    void
+    RestoreTerminalState ();
+    
 private:
 
     static size_t
@@ -117,10 +118,7 @@
     FILE *m_dbg_stdout;
     PyObject *m_new_sysout;
     std::string m_dictionary_name;
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-    struct termios m_termios;
-    bool m_termios_valid;
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+    TerminalState m_terminal_state;
     bool m_session_is_active;
     bool m_pty_slave_is_open;
     bool m_valid_session;

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=125057&r1=125056&r2=125057&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Feb  7 17:24:47 2011
@@ -66,6 +66,8 @@
 		266A42D6128E3FFB0090CF7C /* ClangNamespaceDecl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266A42D5128E3FFB0090CF7C /* ClangNamespaceDecl.cpp */; };
 		266A42D8128E40040090CF7C /* ClangNamespaceDecl.h in Headers */ = {isa = PBXBuildFile; fileRef = 266A42D7128E40040090CF7C /* ClangNamespaceDecl.h */; };
 		266F5CBC12FC846200DFCE33 /* Config.h in Headers */ = {isa = PBXBuildFile; fileRef = 266F5CBB12FC846200DFCE33 /* Config.h */; };
+		268DA872130095D000C9483A /* Terminal.h in Headers */ = {isa = PBXBuildFile; fileRef = 268DA871130095D000C9483A /* Terminal.h */; };
+		268DA874130095ED00C9483A /* Terminal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268DA873130095ED00C9483A /* Terminal.cpp */; };
 		268F9D53123AA15200B91E9B /* SBSymbolContextList.h in Headers */ = {isa = PBXBuildFile; fileRef = 268F9D52123AA15200B91E9B /* SBSymbolContextList.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		268F9D55123AA16600B91E9B /* SBSymbolContextList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */; };
 		26B42B1F1187A92B0079C8C8 /* lldb-include.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42B1E1187A92B0079C8C8 /* lldb-include.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -143,7 +145,6 @@
 		26D5B0B211B07550009A862E /* StreamString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9310F1B85900F91463 /* StreamString.cpp */; };
 		26D5B0B311B07550009A862E /* ConstString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9410F1B85900F91463 /* ConstString.cpp */; };
 		26D5B0B411B07550009A862E /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9610F1B85900F91463 /* Timer.cpp */; };
-		26D5B0B511B07550009A862E /* TTYState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9710F1B85900F91463 /* TTYState.cpp */; };
 		26D5B0B611B07550009A862E /* UserID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9810F1B85900F91463 /* UserID.cpp */; };
 		26D5B0B711B07550009A862E /* Value.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9910F1B85900F91463 /* Value.cpp */; };
 		26D5B0B811B07550009A862E /* ValueObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E9A10F1B85900F91463 /* ValueObject.cpp */; };
@@ -592,6 +593,8 @@
 		2689B0A4113EE3CD00A4AEDB /* Symbols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Symbols.h; path = include/lldb/Host/Symbols.h; sourceTree = "<group>"; };
 		2689B0B5113EE47E00A4AEDB /* Symbols.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Symbols.cpp; path = source/Host/macosx/Symbols.cpp; sourceTree = "<group>"; };
 		268A813F115B19D000F645B0 /* UniqueCStringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UniqueCStringMap.h; path = include/lldb/Core/UniqueCStringMap.h; sourceTree = "<group>"; };
+		268DA871130095D000C9483A /* Terminal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Terminal.h; path = include/lldb/Host/Terminal.h; sourceTree = "<group>"; };
+		268DA873130095ED00C9483A /* Terminal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Terminal.cpp; sourceTree = "<group>"; };
 		268F9D52123AA15200B91E9B /* SBSymbolContextList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBSymbolContextList.h; path = include/lldb/API/SBSymbolContextList.h; sourceTree = "<group>"; };
 		268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBSymbolContextList.cpp; path = source/API/SBSymbolContextList.cpp; sourceTree = "<group>"; };
 		269416AD119A024800FF2715 /* CommandObjectTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectTarget.cpp; path = source/Commands/CommandObjectTarget.cpp; sourceTree = "<group>"; };
@@ -709,7 +712,6 @@
 		26BC7D7B10F1B77400F91463 /* StreamString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StreamString.h; path = include/lldb/Core/StreamString.h; sourceTree = "<group>"; };
 		26BC7D7C10F1B77400F91463 /* ConstString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConstString.h; path = include/lldb/Core/ConstString.h; sourceTree = "<group>"; };
 		26BC7D7E10F1B77400F91463 /* Timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Timer.h; path = include/lldb/Core/Timer.h; sourceTree = "<group>"; };
-		26BC7D7F10F1B77400F91463 /* TTYState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTYState.h; path = include/lldb/Core/TTYState.h; sourceTree = "<group>"; };
 		26BC7D8010F1B77400F91463 /* UserID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserID.h; path = include/lldb/Core/UserID.h; sourceTree = "<group>"; };
 		26BC7D8110F1B77400F91463 /* Value.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Value.h; path = include/lldb/Core/Value.h; sourceTree = "<group>"; };
 		26BC7D8210F1B77400F91463 /* ValueObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ValueObject.h; path = include/lldb/Core/ValueObject.h; sourceTree = "<group>"; };
@@ -811,7 +813,6 @@
 		26BC7E9310F1B85900F91463 /* StreamString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StreamString.cpp; path = source/Core/StreamString.cpp; sourceTree = "<group>"; };
 		26BC7E9410F1B85900F91463 /* ConstString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConstString.cpp; path = source/Core/ConstString.cpp; sourceTree = "<group>"; };
 		26BC7E9610F1B85900F91463 /* Timer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Timer.cpp; path = source/Core/Timer.cpp; sourceTree = "<group>"; };
-		26BC7E9710F1B85900F91463 /* TTYState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TTYState.cpp; path = source/Core/TTYState.cpp; sourceTree = "<group>"; };
 		26BC7E9810F1B85900F91463 /* UserID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UserID.cpp; path = source/Core/UserID.cpp; sourceTree = "<group>"; };
 		26BC7E9910F1B85900F91463 /* Value.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Value.cpp; path = source/Core/Value.cpp; sourceTree = "<group>"; };
 		26BC7E9A10F1B85900F91463 /* ValueObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ValueObject.cpp; path = source/Core/ValueObject.cpp; sourceTree = "<group>"; };
@@ -1743,8 +1744,6 @@
 				263FEDA5112CC1DA00E4C208 /* ThreadSafeSTLMap.h */,
 				26BC7D7E10F1B77400F91463 /* Timer.h */,
 				26BC7E9610F1B85900F91463 /* Timer.cpp */,
-				26BC7D7F10F1B77400F91463 /* TTYState.h */,
-				26BC7E9710F1B85900F91463 /* TTYState.cpp */,
 				268A813F115B19D000F645B0 /* UniqueCStringMap.h */,
 				26BC7D8010F1B77400F91463 /* UserID.h */,
 				26BC7E9810F1B85900F91463 /* UserID.cpp */,
@@ -1978,6 +1977,7 @@
 				26BC7DD510F1B7D500F91463 /* Mutex.h */,
 				26BC7DD610F1B7D500F91463 /* Predicate.h */,
 				2689B0A4113EE3CD00A4AEDB /* Symbols.h */,
+				268DA871130095D000C9483A /* Terminal.h */,
 				26B4E26E112F35F700AB3F64 /* TimeValue.h */,
 			);
 			name = Host;
@@ -2277,6 +2277,7 @@
 				69A01E1C1236C5D400C660B5 /* Host.cpp */,
 				69A01E1E1236C5D400C660B5 /* Mutex.cpp */,
 				69A01E1F1236C5D400C660B5 /* Symbols.cpp */,
+				268DA873130095ED00C9483A /* Terminal.cpp */,
 				69A01E201236C5D400C660B5 /* TimeValue.cpp */,
 			);
 			name = common;
@@ -2345,6 +2346,7 @@
 				26D9FDC712F784E60003F2EE /* EmulateInstruction.h in Headers */,
 				26D9FDCF12F7853F0003F2EE /* EmulateInstructionARM.h in Headers */,
 				266F5CBC12FC846200DFCE33 /* Config.h in Headers */,
+				268DA872130095D000C9483A /* Terminal.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2611,7 +2613,6 @@
 				26D5B0B211B07550009A862E /* StreamString.cpp in Sources */,
 				26D5B0B311B07550009A862E /* ConstString.cpp in Sources */,
 				26D5B0B411B07550009A862E /* Timer.cpp in Sources */,
-				26D5B0B511B07550009A862E /* TTYState.cpp in Sources */,
 				26D5B0B611B07550009A862E /* UserID.cpp in Sources */,
 				26D5B0B711B07550009A862E /* Value.cpp in Sources */,
 				26D5B0B811B07550009A862E /* ValueObject.cpp in Sources */,
@@ -2850,6 +2851,7 @@
 				26D9FDCE12F7853F0003F2EE /* EmulateInstructionARM.cpp in Sources */,
 				26B8B42512EEC52A00A831B2 /* UniqueDWARFASTType.cpp in Sources */,
 				4906FD4212F2255300A2A77C /* ASTDumper.cpp in Sources */,
+				268DA874130095ED00C9483A /* Terminal.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=125057&r1=125056&r2=125057&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Mon Feb  7 17:24:47 2011
@@ -14,7 +14,7 @@
 #include "lldb/Core/State.h"
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
-#include "lldb/Host/Config.h"
+#include "lldb/Host/Terminal.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Target/TargetList.h"
 #include "lldb/Target/Process.h"
@@ -22,9 +22,6 @@
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/Thread.h"
 
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-#include <termios.h>
-#endif
 
 using namespace lldb;
 using namespace lldb_private;
@@ -550,39 +547,31 @@
 void
 Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
 {
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
     FILE *in_fh = GetInputFileHandle();
 
     if (in_fh)
     {
-        struct termios in_fh_termios;
         int in_fd = fileno (in_fh);
-        if (::tcgetattr(in_fd, &in_fh_termios) == 0)
-        {    
-            if (reader_sp->GetEcho())
-                in_fh_termios.c_lflag |= ECHO;  // Turn on echoing
-            else
-                in_fh_termios.c_lflag &= ~ECHO; // Turn off echoing
+        Terminal tty(in_fd);
+        
+        tty.SetEcho(reader_sp->GetEcho());
                 
-            switch (reader_sp->GetGranularity())
-            {
-            case eInputReaderGranularityByte:
-            case eInputReaderGranularityWord:
-                in_fh_termios.c_lflag &= ~ICANON;   // Get one char at a time
-                break;
+        switch (reader_sp->GetGranularity())
+        {
+        case eInputReaderGranularityByte:
+        case eInputReaderGranularityWord:
+            tty.SetCanonical (false);
+            break;
 
-            case eInputReaderGranularityLine:
-            case eInputReaderGranularityAll:
-                in_fh_termios.c_lflag |= ICANON;   // Get lines at a time
-                break;
+        case eInputReaderGranularityLine:
+        case eInputReaderGranularityAll:
+            tty.SetCanonical (true);
+            break;
 
-            default:
-                break;
-            }
-            ::tcsetattr (in_fd, TCSANOW, &in_fh_termios);
+        default:
+            break;
         }
     }
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
 }
 
 void

Removed: lldb/trunk/source/Core/TTYState.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/TTYState.cpp?rev=125056&view=auto
==============================================================================
--- lldb/trunk/source/Core/TTYState.cpp (original)
+++ lldb/trunk/source/Core/TTYState.cpp (removed)
@@ -1,209 +0,0 @@
-//===-- TTYState.cpp --------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Core/TTYState.h"
-#include <fcntl.h>
-#include <unistd.h>
-#include <signal.h>
-
-using namespace lldb_private;
-
-//----------------------------------------------------------------------
-// Default constructor
-//----------------------------------------------------------------------
-TTYState::TTYState() :
-    m_fd(-1),
-    m_tflags(-1),
-    m_ttystate_err(-1),
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-    m_ttystate(),
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
-    m_process_group(-1)
-{
-}
-
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-TTYState::~TTYState()
-{
-}
-
-//----------------------------------------------------------------------
-// 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.
-//----------------------------------------------------------------------
-bool
-TTYState::Save (int fd, bool save_process_group)
-{
-    if (fd >= 0 && ::isatty (fd))
-    {
-        m_fd = fd;
-        m_tflags = ::fcntl (fd, F_GETFL, 0);
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-        m_ttystate_err = ::tcgetattr (fd, &m_ttystate);
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
-        if (save_process_group)
-            m_process_group = ::tcgetpgrp (0);
-        else
-            m_process_group = -1;
-    }
-    else
-    {
-        m_fd = -1;
-        m_tflags = -1;
-        m_ttystate_err = -1;
-        m_process_group = -1;
-    }
-    return m_ttystate_err == 0;
-}
-
-//----------------------------------------------------------------------
-// Restore the state of the TTY using the cached values from a
-// previous call to Save().
-//----------------------------------------------------------------------
-bool
-TTYState::Restore () const
-{
-    int result = 0;
-    if (IsValid())
-    {
-        if (TFlagsIsValid())
-            result = fcntl (m_fd, F_SETFL, m_tflags);
-
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-        if (TTYStateIsValid())
-            result = tcsetattr (m_fd, TCSANOW, &m_ttystate);
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
-
-        if (ProcessGroupIsValid())
-        {
-            // Save the original signal handler.
-            void (*saved_sigttou_callback) (int) = NULL;
-            saved_sigttou_callback = (void (*)(int)) signal (SIGTTOU, SIG_IGN);
-            // Set the process group
-            result = tcsetpgrp (m_fd, m_process_group);
-            // Restore the original signal handler.
-            signal (SIGTTOU, saved_sigttou_callback);
-        }
-        return true;
-    }
-    return false;
-}
-
-
-
-
-//----------------------------------------------------------------------
-// Returns true if this object has valid saved TTY state settings
-// that can be used to restore a previous state.
-//----------------------------------------------------------------------
-bool
-TTYState::IsValid() const
-{
-    return (m_fd >= 0) && (TFlagsIsValid() || TTYStateIsValid());
-}
-
-//----------------------------------------------------------------------
-// Returns true if m_tflags is valid
-//----------------------------------------------------------------------
-bool
-TTYState::TFlagsIsValid() const
-{
-    return m_tflags != -1;
-}
-
-//----------------------------------------------------------------------
-// Returns true if m_ttystate is valid
-//----------------------------------------------------------------------
-bool
-TTYState::TTYStateIsValid() const
-{
-    return m_ttystate_err == 0;
-}
-
-//----------------------------------------------------------------------
-// Returns true if m_process_group is valid
-//----------------------------------------------------------------------
-bool
-TTYState::ProcessGroupIsValid() const
-{
-    return m_process_group != -1;
-}
-
-//------------------------------------------------------------------
-// Constructor
-//------------------------------------------------------------------
-TTYStateSwitcher::TTYStateSwitcher () :
-    m_currentState(UINT32_MAX)
-{
-}
-
-//------------------------------------------------------------------
-// Destructor
-//------------------------------------------------------------------
-TTYStateSwitcher::~TTYStateSwitcher ()
-{
-}
-
-//------------------------------------------------------------------
-// Returns the number of states that this switcher contains
-//------------------------------------------------------------------
-uint32_t
-TTYStateSwitcher::GetNumberOfStates() const
-{
-    return sizeof(m_ttystates)/sizeof(TTYState);
-}
-
-//------------------------------------------------------------------
-// Restore the state at index "idx".
-//
-// Returns true if the restore was successful, false otherwise.
-//------------------------------------------------------------------
-bool
-TTYStateSwitcher::Restore (uint32_t idx) const
-{
-    const uint32_t num_states = GetNumberOfStates();
-    if (idx >= num_states)
-        return false;
-
-    // See if we already are in this state?
-    if (m_currentState < num_states && (idx == m_currentState) && m_ttystates[idx].IsValid())
-        return true;
-
-    // Set the state to match the index passed in and only update the
-    // current state if there are no errors.
-    if (m_ttystates[idx].Restore())
-    {
-        m_currentState = idx;
-        return true;
-    }
-
-    // We failed to set the state. The tty state was invalid or not
-    // initialized.
-    return false;
-}
-
-//------------------------------------------------------------------
-// Save the state at index "idx" for file descriptor "fd" and
-// save the process group if requested.
-//
-// Returns true if the restore was successful, false otherwise.
-//------------------------------------------------------------------
-bool
-TTYStateSwitcher::Save (uint32_t idx, int fd, bool save_process_group)
-{
-    const uint32_t num_states = GetNumberOfStates();
-    if (idx < num_states)
-        return m_ttystates[idx].Save(fd, save_process_group);
-    return false;
-}
-
-

Added: lldb/trunk/source/Host/common/Terminal.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Terminal.cpp?rev=125057&view=auto
==============================================================================
--- lldb/trunk/source/Host/common/Terminal.cpp (added)
+++ lldb/trunk/source/Host/common/Terminal.cpp Mon Feb  7 17:24:47 2011
@@ -0,0 +1,299 @@
+//===-- Terminal.cpp --------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/Terminal.h"
+#include "lldb/Host/Config.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+
+#if LLDB_CONFIG_TERMIOS_SUPPORTED
+#include <termios.h>
+#endif
+
+
+using namespace lldb_private;
+
+bool
+Terminal::IsATerminal () const
+{
+    return m_fd >= 0 && ::isatty (m_fd);
+}
+    
+
+bool
+Terminal::SetEcho (bool enabled)
+{
+    if (FileDescriptorIsValid())
+    {
+#if LLDB_CONFIG_TERMIOS_SUPPORTED
+        if (IsATerminal ())
+        {
+            struct termios fd_termios;
+            if (::tcgetattr(m_fd, &fd_termios) == 0)
+            {    
+                bool set_corectly = false;
+                if (enabled)
+                {
+                    if (fd_termios.c_lflag & ECHO)
+                        set_corectly = true;
+                    else
+                        fd_termios.c_lflag |= ECHO;
+                }
+                else
+                {
+                    if (fd_termios.c_lflag & ECHO)
+                        fd_termios.c_lflag &= ~ECHO;
+                    else
+                        set_corectly = true;
+                }
+                
+                if (set_corectly)
+                    return true;
+                return ::tcsetattr (m_fd, TCSANOW, &fd_termios) == 0;
+            }
+        }
+#endif
+    }
+    return false;
+}
+
+bool
+Terminal::SetCanonical (bool enabled)
+{
+    if (FileDescriptorIsValid())
+    {
+#if LLDB_CONFIG_TERMIOS_SUPPORTED
+        if (IsATerminal ())
+        {
+            struct termios fd_termios;
+            if (::tcgetattr(m_fd, &fd_termios) == 0)
+            {    
+                bool set_corectly = false;
+                if (enabled)
+                {
+                    if (fd_termios.c_lflag & ICANON)
+                        set_corectly = true;
+                    else
+                        fd_termios.c_lflag |= ICANON;
+                }
+                else
+                {
+                    if (fd_termios.c_lflag & ICANON)
+                        fd_termios.c_lflag &= ~ICANON;
+                    else
+                        set_corectly = true;
+                }
+                
+                if (set_corectly)
+                    return true;
+                return ::tcsetattr (m_fd, TCSANOW, &fd_termios) == 0;
+            }
+        }
+#endif
+    }
+    return false;
+}
+
+//----------------------------------------------------------------------
+// Default constructor
+//----------------------------------------------------------------------
+TerminalState::TerminalState() :
+    m_tty(),
+    m_tflags(-1),
+    m_termios_ap(),
+    m_process_group(-1)
+{
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+TerminalState::~TerminalState()
+{
+}
+
+//----------------------------------------------------------------------
+// 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.
+//----------------------------------------------------------------------
+bool
+TerminalState::Save (int fd, bool save_process_group)
+{
+    m_tty.SetFileDescriptor(fd);
+    if (m_tty.IsATerminal())
+    {
+        m_tflags = ::fcntl (fd, F_GETFL, 0);
+#if LLDB_CONFIG_TERMIOS_SUPPORTED
+        if (m_termios_ap.get() == NULL)
+            m_termios_ap.reset (new struct termios);
+        int err = ::tcgetattr (fd, m_termios_ap.get());
+        if (err != 0)
+            m_termios_ap.reset();
+#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+        if (save_process_group)
+            m_process_group = ::tcgetpgrp (0);
+        else
+            m_process_group = -1;
+    }
+    else
+    {
+        m_tty.Clear();
+        m_tflags = -1;
+        m_termios_ap.reset();
+        m_process_group = -1;
+    }
+    return IsValid();
+}
+
+//----------------------------------------------------------------------
+// Restore the state of the TTY using the cached values from a
+// previous call to Save().
+//----------------------------------------------------------------------
+bool
+TerminalState::Restore () const
+{
+    int result = 0;
+    if (IsValid())
+    {
+        const int fd = m_tty.GetFileDescriptor();
+        if (TFlagsIsValid())
+            result = fcntl (fd, F_SETFL, m_tflags);
+
+#if LLDB_CONFIG_TERMIOS_SUPPORTED
+        if (TTYStateIsValid())
+            result = tcsetattr (fd, TCSANOW, m_termios_ap.get());
+#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+
+        if (ProcessGroupIsValid())
+        {
+            // Save the original signal handler.
+            void (*saved_sigttou_callback) (int) = NULL;
+            saved_sigttou_callback = (void (*)(int)) signal (SIGTTOU, SIG_IGN);
+            // Set the process group
+            result = tcsetpgrp (fd, m_process_group);
+            // Restore the original signal handler.
+            signal (SIGTTOU, saved_sigttou_callback);
+        }
+        return true;
+    }
+    return false;
+}
+
+
+
+
+//----------------------------------------------------------------------
+// Returns true if this object has valid saved TTY state settings
+// that can be used to restore a previous state.
+//----------------------------------------------------------------------
+bool
+TerminalState::IsValid() const
+{
+    return m_tty.FileDescriptorIsValid () && (TFlagsIsValid() || TTYStateIsValid());
+}
+
+//----------------------------------------------------------------------
+// Returns true if m_tflags is valid
+//----------------------------------------------------------------------
+bool
+TerminalState::TFlagsIsValid() const
+{
+    return m_tflags != -1;
+}
+
+//----------------------------------------------------------------------
+// Returns true if m_ttystate is valid
+//----------------------------------------------------------------------
+bool
+TerminalState::TTYStateIsValid() const
+{
+    return m_termios_ap.get() != 0;
+}
+
+//----------------------------------------------------------------------
+// Returns true if m_process_group is valid
+//----------------------------------------------------------------------
+bool
+TerminalState::ProcessGroupIsValid() const
+{
+    return m_process_group != -1;
+}
+
+//------------------------------------------------------------------
+// Constructor
+//------------------------------------------------------------------
+TerminalStateSwitcher::TerminalStateSwitcher () :
+    m_currentState(UINT32_MAX)
+{
+}
+
+//------------------------------------------------------------------
+// Destructor
+//------------------------------------------------------------------
+TerminalStateSwitcher::~TerminalStateSwitcher ()
+{
+}
+
+//------------------------------------------------------------------
+// Returns the number of states that this switcher contains
+//------------------------------------------------------------------
+uint32_t
+TerminalStateSwitcher::GetNumberOfStates() const
+{
+    return sizeof(m_ttystates)/sizeof(TerminalState);
+}
+
+//------------------------------------------------------------------
+// Restore the state at index "idx".
+//
+// Returns true if the restore was successful, false otherwise.
+//------------------------------------------------------------------
+bool
+TerminalStateSwitcher::Restore (uint32_t idx) const
+{
+    const uint32_t num_states = GetNumberOfStates();
+    if (idx >= num_states)
+        return false;
+
+    // See if we already are in this state?
+    if (m_currentState < num_states && (idx == m_currentState) && m_ttystates[idx].IsValid())
+        return true;
+
+    // Set the state to match the index passed in and only update the
+    // current state if there are no errors.
+    if (m_ttystates[idx].Restore())
+    {
+        m_currentState = idx;
+        return true;
+    }
+
+    // We failed to set the state. The tty state was invalid or not
+    // initialized.
+    return false;
+}
+
+//------------------------------------------------------------------
+// Save the state at index "idx" for file descriptor "fd" and
+// save the process group if requested.
+//
+// Returns true if the restore was successful, false otherwise.
+//------------------------------------------------------------------
+bool
+TerminalStateSwitcher::Save (uint32_t idx, int fd, bool save_process_group)
+{
+    const uint32_t num_states = GetNumberOfStates();
+    if (idx < num_states)
+        return m_ttystates[idx].Save(fd, save_process_group);
+    return false;
+}
+
+

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=125057&r1=125056&r2=125057&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Mon Feb  7 17:24:47 2011
@@ -201,10 +201,7 @@
     m_dbg_stdout (interpreter.GetDebugger().GetOutputFileHandle()),
     m_new_sysout (NULL),
     m_dictionary_name (interpreter.GetDebugger().GetInstanceName().AsCString()),
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-    m_termios (),
-    m_termios_valid (false),
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+    m_terminal_state (),
     m_session_is_active (false),
     m_pty_slave_is_open (false),
     m_valid_session (true)
@@ -346,6 +343,28 @@
 }
 
 void
+ScriptInterpreterPython::SaveTerminalState (int fd)
+{
+    // Python mucks with the terminal state of STDIN. If we can possibly avoid
+    // this by setting the file handles up correctly prior to entering the
+    // interpreter we should. For now we save and restore the terminal state
+    // on the input file handle.
+    m_terminal_state.Save (fd, false);
+}
+
+void
+ScriptInterpreterPython::RestoreTerminalState ()
+{
+    // Python mucks with the terminal state of STDIN. If we can possibly avoid
+    // this by setting the file handles up correctly prior to entering the
+    // interpreter we should. For now we save and restore the terminal state
+    // on the input file handle.
+    m_terminal_state.Restore();
+}
+
+
+
+void
 ScriptInterpreterPython::LeaveSession ()
 {
     m_session_is_active = false;
@@ -571,9 +590,7 @@
             else
                 input_fd = STDIN_FILENO;
 
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-            script_interpreter->m_termios_valid = ::tcgetattr (input_fd, &script_interpreter->m_termios) == 0;
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+            script_interpreter->SaveTerminalState(input_fd);
 
             if (!CurrentThreadHasPythonLock())
             {
@@ -678,19 +695,9 @@
         // Restore terminal settings if they were validly saved
         if (log)
             log->Printf ("ScriptInterpreterPython::InputReaderCallback, Done, closing down input reader.");
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-        if (script_interpreter->m_termios_valid)
-        {
-            int input_fd;
-            FILE *input_fh = reader.GetDebugger().GetInputFileHandle();
-            if (input_fh != NULL)
-                input_fd = ::fileno (input_fh);
-            else
-                input_fd = STDIN_FILENO;
             
-            ::tcsetattr (input_fd, TCSANOW, &script_interpreter->m_termios);
-        }
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+        script_interpreter->RestoreTerminalState ();
+
         script_interpreter->m_embedded_python_pty.CloseMasterFileDescriptor();
         break;
     }
@@ -1436,11 +1443,10 @@
 {
     Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
 
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-    int input_fd = STDIN_FILENO;
-    struct termios stdin_termios;
-    bool valid_termios = ::tcgetattr (input_fd, &stdin_termios) == 0;
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+    // Python will muck with STDIN terminal state, so save off any current TTY
+    // settings so we can restore them.
+    TerminalState stdin_tty_state;
+    stdin_tty_state.Save(STDIN_FILENO, false);
 
     // Find the module that owns this code and use that path we get to
     // set the PYTHONPATH appropriately.
@@ -1518,10 +1524,7 @@
         Py_DECREF (pmod);
     }
 
-#if LLDB_CONFIG_TERMIOS_SUPPORTED
-    if (valid_termios)
-        ::tcsetattr (input_fd, TCSANOW, &stdin_termios);
-#endif // #if LLDB_CONFIG_TERMIOS_SUPPORTED
+    stdin_tty_state.Restore();
 }
 
 void





More information about the lldb-commits mailing list