[Lldb-commits] [lldb] r120723 - in /lldb/trunk: include/lldb/API/SBCommunication.h include/lldb/Core/Communication.h source/API/SBCommunication.cpp source/Core/Communication.cpp source/Core/ConnectionFileDescriptor.cpp source/Core/Debugger.cpp source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp source/Target/Process.cpp tools/driver/Driver.cpp

Caroline Tice ctice at apple.com
Thu Dec 2 10:31:56 PST 2010


Author: ctice
Date: Thu Dec  2 12:31:56 2010
New Revision: 120723

URL: http://llvm.org/viewvc/llvm-project?rev=120723&view=rev
Log:

Add proper EOF handling to Communication & Connection classes:

Add bool member to Communication class indicating whether the
Connection should be closed on receiving an EOF or not.  Update the
Connection read to return an EOF status when appropriate.  Modify the
Communication class to pass the EOF along or not, and to close the
Connection or not, as appropriate.



Modified:
    lldb/trunk/include/lldb/API/SBCommunication.h
    lldb/trunk/include/lldb/Core/Communication.h
    lldb/trunk/source/API/SBCommunication.cpp
    lldb/trunk/source/Core/Communication.cpp
    lldb/trunk/source/Core/ConnectionFileDescriptor.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/tools/driver/Driver.cpp

Modified: lldb/trunk/include/lldb/API/SBCommunication.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommunication.h?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBCommunication.h (original)
+++ lldb/trunk/include/lldb/API/SBCommunication.h Thu Dec  2 12:31:56 2010
@@ -30,7 +30,7 @@
     typedef void (*ReadThreadBytesReceived) (void *baton, const void *src, size_t src_len);
 
     SBCommunication ();
-    SBCommunication (const char * broadcaster_name);
+    SBCommunication (const char * broadcaster_name, bool close_on_eof);
    ~SBCommunication ();
 
 

Modified: lldb/trunk/include/lldb/Core/Communication.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Communication.h?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Communication.h (original)
+++ lldb/trunk/include/lldb/Core/Communication.h Thu Dec  2 12:31:56 2010
@@ -109,7 +109,7 @@
     ///     broadcaster name can be updated after the connect function
     ///     is called.
     //------------------------------------------------------------------
-    Communication(const char * broadcaster_name);
+    Communication(const char * broadcaster_name, bool close_on_eof);
 
     //------------------------------------------------------------------
     /// Destructor.
@@ -340,6 +340,9 @@
     //------------------------------------------------------------------
     DISALLOW_COPY_AND_ASSIGN (Communication);
 
+    bool
+    CloseOnEOF ();
+
 protected:
     std::auto_ptr<Connection> m_connection_ap; ///< The connection that is current in use by this communications class.
     lldb::thread_t m_read_thread; ///< The read thread handle in case we need to cancel the thread.
@@ -348,6 +351,7 @@
     Mutex m_bytes_mutex; ///< A mutex to protect multi-threaded access to the cached bytes.
     ReadThreadBytesReceived m_callback;
     void *m_callback_baton;
+    bool m_close_on_eof;
 
     size_t
     ReadFromConnection (void *dst, 

Modified: lldb/trunk/source/API/SBCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommunication.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommunication.cpp (original)
+++ lldb/trunk/source/API/SBCommunication.cpp Thu Dec  2 12:31:56 2010
@@ -24,8 +24,8 @@
 {
 }
 
-SBCommunication::SBCommunication(const char * broadcaster_name) :
-    m_opaque (new Communication (broadcaster_name)),
+SBCommunication::SBCommunication(const char * broadcaster_name, bool close_on_eof) :
+    m_opaque (new Communication (broadcaster_name, close_on_eof)),
     m_opaque_owned (true)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

Modified: lldb/trunk/source/Core/Communication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Communication.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/source/Core/Communication.cpp (original)
+++ lldb/trunk/source/Core/Communication.cpp Thu Dec  2 12:31:56 2010
@@ -25,7 +25,7 @@
 //----------------------------------------------------------------------
 // Constructor
 //----------------------------------------------------------------------
-Communication::Communication(const char *name) :
+Communication::Communication(const char *name, bool close_on_eof) :
     Broadcaster (name),
     m_connection_ap (),
     m_read_thread (LLDB_INVALID_HOST_THREAD),
@@ -33,7 +33,8 @@
     m_bytes(),
     m_bytes_mutex (Mutex::eMutexTypeRecursive),
     m_callback (NULL),
-    m_callback_baton (NULL)
+    m_callback_baton (NULL),
+    m_close_on_eof (close_on_eof)
 
 {
     lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
@@ -265,7 +266,8 @@
     lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
                                  "%p Communication::AppendBytesToCache (src = %p, src_len = %zu, broadcast = %i)",
                                  this, bytes, len, broadcast);
-    if (bytes == NULL || len == 0)
+    if ((bytes == NULL || len == 0)
+        && (status != eConnectionStatusEndOfFile))
         return;
     if (m_callback)
     {
@@ -289,6 +291,11 @@
     return 0;
 }
 
+bool
+Communication::CloseOnEOF ()
+{
+    return m_close_on_eof;
+}
 
 bool
 Communication::ReadThreadIsRunning ()
@@ -320,14 +327,21 @@
             size_t bytes_read = comm->ReadFromConnection (buf, sizeof(buf), status, &error);
             if (bytes_read > 0)
                 comm->AppendBytesToCache (buf, bytes_read, true, status);
+            else if ((bytes_read == 0)
+                    && status == eConnectionStatusEndOfFile)
+            {
+                if (comm->CloseOnEOF ())
+                    comm->Disconnect ();
+                comm->AppendBytesToCache (buf, bytes_read, true, status);
+            }
         }
 
         switch (status)
         {
         case eConnectionStatusSuccess:
+        case eConnectionStatusEndOfFile:
             break;
 
-        case eConnectionStatusEndOfFile:
         case eConnectionStatusNoConnection:     // No connection
         case eConnectionStatusLostConnection:   // Lost connection while connected to a valid connection
             done = true;

Modified: lldb/trunk/source/Core/ConnectionFileDescriptor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConnectionFileDescriptor.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConnectionFileDescriptor.cpp (original)
+++ lldb/trunk/source/Core/ConnectionFileDescriptor.cpp Thu Dec  2 12:31:56 2010
@@ -156,8 +156,8 @@
     ssize_t bytes_read = ::read (m_fd, dst, dst_len);
     if (bytes_read == 0)
     {
-        error.SetErrorStringWithFormat("End-of-file.\n");
-        status = eConnectionStatusLostConnection;
+        error.Clear(); // End-of-file.  Do not automatically close; pass along for the end-of-file handlers.
+        status = eConnectionStatusEndOfFile;
     }
     else if (bytes_read < 0)
     {

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Thu Dec  2 12:31:56 2010
@@ -166,7 +166,7 @@
 Debugger::Debugger () :
     UserID (g_unique_id++),
     DebuggerInstanceSettings (*GetSettingsController()),
-    m_input_comm("debugger.input"),
+    m_input_comm("debugger.input", false),
     m_input_file (),
     m_output_file (),
     m_error_file (),

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Thu Dec  2 12:31:56 2010
@@ -32,7 +32,7 @@
 // GDBRemoteCommunication constructor
 //----------------------------------------------------------------------
 GDBRemoteCommunication::GDBRemoteCommunication() :
-    Communication("gdb-remote.packets"),
+    Communication("gdb-remote.packets", true),
     m_send_acks (true),
     m_rx_packet_listener ("gdbremote.rx_packet"),
     m_sequence_mutex (Mutex::eMutexTypeRecursive),

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Thu Dec  2 12:31:56 2010
@@ -96,7 +96,7 @@
     m_addr_byte_size (0),
     m_abi_sp (),
     m_process_input_reader (),
-    m_stdio_communication ("lldb.process.stdio"),
+    m_stdio_communication ("lldb.process.stdio", true),
     m_stdio_communication_mutex (Mutex::eMutexTypeRecursive),
     m_stdout_data ()
 {

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=120723&r1=120722&r2=120723&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Thu Dec  2 12:31:56 2010
@@ -1178,7 +1178,7 @@
     // However, you don't need to do anything with the characters, since editline will dump these
     // unconsumed characters after printing the prompt again in el_gets.
 
-    SBCommunication master_out_comm("driver.editline");
+    SBCommunication master_out_comm("driver.editline", false);
     master_out_comm.AdoptFileDesriptor(m_editline_pty.GetMasterFileDescriptor(), false);
     master_out_comm.SetReadThreadBytesReceivedCallback(Driver::MasterThreadBytesReceived, this);
 





More information about the lldb-commits mailing list