diff options
-rw-r--r-- | lldb/include/lldb/API/SBCommunication.h | 2 | ||||
-rw-r--r-- | lldb/include/lldb/Core/Communication.h | 6 | ||||
-rw-r--r-- | lldb/source/API/SBCommunication.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Core/Communication.cpp | 22 | ||||
-rw-r--r-- | lldb/source/Core/ConnectionFileDescriptor.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Target/Process.cpp | 2 | ||||
-rw-r--r-- | lldb/tools/driver/Driver.cpp | 2 |
9 files changed, 32 insertions, 14 deletions
diff --git a/lldb/include/lldb/API/SBCommunication.h b/lldb/include/lldb/API/SBCommunication.h index 198523e538a..7533cf6e2f2 100644 --- a/lldb/include/lldb/API/SBCommunication.h +++ b/lldb/include/lldb/API/SBCommunication.h @@ -30,7 +30,7 @@ public: 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 (); diff --git a/lldb/include/lldb/Core/Communication.h b/lldb/include/lldb/Core/Communication.h index 834b25a0389..f841bae5713 100644 --- a/lldb/include/lldb/Core/Communication.h +++ b/lldb/include/lldb/Core/Communication.h @@ -109,7 +109,7 @@ public: /// 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 @@ private: //------------------------------------------------------------------ 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 @@ protected: 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, diff --git a/lldb/source/API/SBCommunication.cpp b/lldb/source/API/SBCommunication.cpp index ac3042fd904..6aa1e244d3c 100644 --- a/lldb/source/API/SBCommunication.cpp +++ b/lldb/source/API/SBCommunication.cpp @@ -24,8 +24,8 @@ SBCommunication::SBCommunication() : { } -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)); diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index 17ed2fd7689..f8de19810b1 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -25,7 +25,7 @@ using namespace lldb_private; //---------------------------------------------------------------------- // 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 @@ Communication::Communication(const char *name) : 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 @@ Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broad 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 @@ Communication::ReadFromConnection (void *dst, size_t dst_len, ConnectionStatus & return 0; } +bool +Communication::CloseOnEOF () +{ + return m_close_on_eof; +} bool Communication::ReadThreadIsRunning () @@ -320,14 +327,21 @@ Communication::ReadThread (void *p) 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; diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp index 96d70bc1012..c333d06b176 100644 --- a/lldb/source/Core/ConnectionFileDescriptor.cpp +++ b/lldb/source/Core/ConnectionFileDescriptor.cpp @@ -156,8 +156,8 @@ ConnectionFileDescriptor::Read (void *dst, size_t dst_len, ConnectionStatus &sta 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) { diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index a06095fa80b..8884c3c95b1 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -166,7 +166,7 @@ Debugger::FindTargetWithProcessID (lldb::pid_t pid) 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 (), diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 63fb35783ea..be962727364 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -32,7 +32,7 @@ using namespace lldb_private; // 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), diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index b025970a477..1c269bee525 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -96,7 +96,7 @@ Process::Process(Target &target, Listener &listener) : 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 () { diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index 29b50f05a55..abd51a56644 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -1178,7 +1178,7 @@ Driver::MainLoop () // 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); |