summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
authorCaroline Tice <ctice@apple.com>2010-11-19 20:47:54 +0000
committerCaroline Tice <ctice@apple.com>2010-11-19 20:47:54 +0000
commitefed613172d902cf2ce49f68dd36f15a29a34dab (patch)
tree9f2dd7ec50382f4e1c2ca600e0d06d60a9bee4c6 /lldb/source/Core
parent601e72c88a65fddc4525a3d5a19b51495a68ce82 (diff)
downloadbcm5719-llvm-efed613172d902cf2ce49f68dd36f15a29a34dab.tar.gz
bcm5719-llvm-efed613172d902cf2ce49f68dd36f15a29a34dab.zip
Add the ability to catch and do the right thing with Interrupts (often control-c)
and end-of-file (often control-d). llvm-svn: 119837
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/Communication.cpp11
-rw-r--r--lldb/source/Core/ConnectionFileDescriptor.cpp14
-rw-r--r--lldb/source/Core/Debugger.cpp45
-rw-r--r--lldb/source/Core/InputReader.cpp4
4 files changed, 65 insertions, 9 deletions
diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp
index f6c689c7aa5..22a9f9ae293 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -260,12 +260,13 @@ Communication::GetCachedBytes (void *dst, size_t dst_len)
}
void
-Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broadcast)
+Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broadcast, ConnectionStatus status)
{
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)
{
@@ -319,12 +320,16 @@ 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);
+ comm->AppendBytesToCache (buf, bytes_read, true, status);
+ else if ((bytes_read == 0)
+ && status == eConnectionStatusEndOfFile)
+ comm->AppendBytesToCache (buf, bytes_read, true, status);
}
switch (status)
{
case eConnectionStatusSuccess:
+ case eConnectionStatusEndOfFile:
break;
case eConnectionStatusNoConnection: // No connection
diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp
index 96d70bc1012..bdf550e5953 100644
--- a/lldb/source/Core/ConnectionFileDescriptor.cpp
+++ b/lldb/source/Core/ConnectionFileDescriptor.cpp
@@ -156,8 +156,18 @@ 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;
+ // 'read' did not return an error, but it didn't return any bytes either ==> End-of-File.
+ // If the file descriptor is still valid, then we don't return an error; otherwise we do.
+ // This allows whoever called us to act on the end-of-file, with a valid file descriptor, if they wish.
+ if (fcntl (m_fd, F_GETFL, 0) >= 0)
+ {
+ error.Clear(); // End-of-file, but not an error. Pass along for the end-of-file handlers.
+ }
+ else
+ {
+ error.SetErrorStringWithFormat("End-of-file.\n");
+ }
+ status = eConnectionStatusEndOfFile;
}
else if (bytes_read < 0)
{
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 617edd2fdf4..a06095fa80b 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -338,20 +338,57 @@ Debugger::GetTargetList ()
void
Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
{
- ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
-}
+ if (bytes_len > 0)
+ ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
+ else
+ ((Debugger *)baton)->DispatchInputEndOfFile ();
+}
void
Debugger::DispatchInput (const char *bytes, size_t bytes_len)
{
-// if (bytes == NULL || bytes_len == 0)
-// return;
+ if (bytes == NULL || bytes_len == 0)
+ return;
WriteToDefaultReader (bytes, bytes_len);
}
void
+Debugger::DispatchInputInterrupt ()
+{
+ m_input_reader_data.clear();
+
+ if (!m_input_readers.empty())
+ {
+ while (CheckIfTopInputReaderIsDone ()) ;
+
+ InputReaderSP reader_sp(m_input_readers.top());
+ if (reader_sp)
+ reader_sp->Notify (eInputReaderInterrupt);
+
+ while (CheckIfTopInputReaderIsDone ()) ;
+ }
+}
+
+void
+Debugger::DispatchInputEndOfFile ()
+{
+ m_input_reader_data.clear();
+
+ if (!m_input_readers.empty())
+ {
+ while (CheckIfTopInputReaderIsDone ()) ;
+
+ InputReaderSP reader_sp(m_input_readers.top());
+ if (reader_sp)
+ reader_sp->Notify (eInputReaderEndOfFile);
+
+ while (CheckIfTopInputReaderIsDone ()) ;
+ }
+}
+
+void
Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
{
if (bytes && bytes_len)
diff --git a/lldb/source/Core/InputReader.cpp b/lldb/source/Core/InputReader.cpp
index 06cfb5b5ff6..b8a61c29953 100644
--- a/lldb/source/Core/InputReader.cpp
+++ b/lldb/source/Core/InputReader.cpp
@@ -324,6 +324,10 @@ InputReader::Notify (InputReaderAction notification)
m_active = false;
break;
+ case eInputReaderInterrupt:
+ case eInputReaderEndOfFile:
+ break;
+
case eInputReaderGotToken:
return; // We don't notify the tokens here, it is done in HandleRawBytes
}
OpenPOWER on IntegriCloud