[Lldb-commits] [lldb] r169032 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Core/Debugger.h include/lldb/Host/Terminal.h source/API/SBDebugger.cpp source/Core/Debugger.cpp source/Host/common/Terminal.cpp tools/driver/Driver.cpp

Jim Ingham jingham at apple.com
Fri Nov 30 12:23:19 PST 2012


Author: jingham
Date: Fri Nov 30 14:23:19 2012
New Revision: 169032

URL: http://llvm.org/viewvc/llvm-project?rev=169032&view=rev
Log:
Save and restore terminal state when lldb is suspended with SIGTSTP and resumed with SIGCONT.
Readline & gdb have a bunch of code to handle older UNIX'es with other job control mechanisms.
I didn't try to replicate that.

Modified:
    lldb/trunk/include/lldb/API/SBDebugger.h
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Host/Terminal.h
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Host/common/Terminal.cpp
    lldb/trunk/tools/driver/Driver.cpp

Modified: lldb/trunk/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDebugger.h (original)
+++ lldb/trunk/include/lldb/API/SBDebugger.h Fri Nov 30 14:23:19 2012
@@ -78,7 +78,7 @@
 
     void
     SetErrorFileHandle (FILE *f, bool transfer_ownership);
-
+    
     FILE *
     GetInputFileHandle ();
 
@@ -88,6 +88,12 @@
     FILE *
     GetErrorFileHandle ();
 
+    void
+    SaveInputTerminalState();
+    
+    void
+    RestoreInputTerminalState();
+
     lldb::SBCommandInterpreter
     GetCommandInterpreter ();
 

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Fri Nov 30 14:23:19 2012
@@ -116,6 +116,12 @@
 
     void
     SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
+    
+    void
+    SaveInputTerminalState();
+    
+    void
+    RestoreInputTerminalState();
 
     Stream&
     GetOutputStream ()
@@ -351,6 +357,7 @@
     StreamFile m_input_file;
     StreamFile m_output_file;
     StreamFile m_error_file;
+    TerminalState m_terminal_state;
     TargetList m_target_list;
     PlatformList m_platform_list;
     Listener m_listener;

Modified: lldb/trunk/include/lldb/Host/Terminal.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Terminal.h?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Terminal.h (original)
+++ lldb/trunk/include/lldb/Host/Terminal.h Fri Nov 30 14:23:19 2012
@@ -132,6 +132,9 @@
     //------------------------------------------------------------------
     bool
     IsValid() const;
+    
+    void
+    Clear ();
 
 protected:
 

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Fri Nov 30 14:23:19 2012
@@ -291,6 +291,20 @@
     return NULL;
 }
 
+void
+SBDebugger::SaveInputTerminalState()
+{
+    if (m_opaque_sp)
+        m_opaque_sp->SaveInputTerminalState();
+}
+
+void
+SBDebugger::RestoreInputTerminalState()
+{
+    if (m_opaque_sp)
+        m_opaque_sp->RestoreInputTerminalState();
+
+}
 SBCommandInterpreter
 SBDebugger::GetCommandInterpreter ()
 {

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Fri Nov 30 14:23:19 2012
@@ -548,6 +548,7 @@
     m_input_file (),
     m_output_file (),
     m_error_file (),
+    m_terminal_state (),
     m_target_list (*this),
     m_platform_list (),
     m_listener ("lldb.Debugger"),
@@ -615,6 +616,7 @@
     
     // Close the input file _before_ we close the input read communications class
     // as it does NOT own the input file, our m_input_file does.
+    m_terminal_state.Clear();
     GetInputFile().Close ();
     // Now that we have closed m_input_file, we can now tell our input communication
     // class to close down. Its read thread should quickly exit after we close
@@ -662,7 +664,10 @@
     // want to objects trying to own and close a file descriptor.
     m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
     m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
-
+    
+    // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
+    SaveInputTerminalState ();
+    
     Error error;
     if (m_input_comm.StartReadThread (&error) == false)
     {
@@ -698,6 +703,20 @@
         err_file.SetStream (stderr, false);
 }
 
+void
+Debugger::SaveInputTerminalState ()
+{
+    File &in_file = GetInputFile();
+    if (in_file.GetDescriptor() != File::kInvalidDescriptor)
+        m_terminal_state.Save(in_file.GetDescriptor(), true);
+}
+
+void
+Debugger::RestoreInputTerminalState ()
+{
+    m_terminal_state.Restore();
+}
+
 ExecutionContext
 Debugger::GetSelectedExecutionContext ()
 {

Modified: lldb/trunk/source/Host/common/Terminal.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Terminal.cpp?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Terminal.cpp (original)
+++ lldb/trunk/source/Host/common/Terminal.cpp Fri Nov 30 14:23:19 2012
@@ -120,6 +120,15 @@
 {
 }
 
+void
+TerminalState::Clear ()
+{
+    m_tty.Clear();
+    m_tflags = -1;
+    m_termios_ap.reset();
+    m_process_group = -1;
+}
+
 //----------------------------------------------------------------------
 // Save the current state of the TTY for the file descriptor "fd"
 // and if "save_process_group" is true, attempt to save the process

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=169032&r1=169031&r2=169032&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Fri Nov 30 14:23:19 2012
@@ -1579,6 +1579,24 @@
 	exit (signo);
 }
 
+void
+sigtstp_handler (int signo)
+{
+    g_driver->GetDebugger().SaveInputTerminalState();
+    signal (signo, SIG_DFL);
+    kill (getpid(), signo);
+    signal (signo, sigtstp_handler);
+}
+
+void
+sigcont_handler (int signo)
+{
+    g_driver->GetDebugger().RestoreInputTerminalState();
+    signal (signo, SIG_DFL);
+    kill (getpid(), signo);
+    signal (signo, sigcont_handler);
+}
+
 int
 main (int argc, char const *argv[], const char *envp[])
 {
@@ -1589,6 +1607,8 @@
     signal (SIGPIPE, SIG_IGN);
     signal (SIGWINCH, sigwinch_handler);
     signal (SIGINT, sigint_handler);
+    signal (SIGTSTP, sigtstp_handler);
+    signal (SIGCONT, sigcont_handler);
 
     // Create a scope for driver so that the driver object will destroy itself
     // before SBDebugger::Terminate() is called.





More information about the lldb-commits mailing list