[Lldb-commits] [lldb] r181257 - <rdar://problem/13063912>

Enrico Granata egranata at apple.com
Mon May 6 15:10:33 PDT 2013


Author: enrico
Date: Mon May  6 17:10:33 2013
New Revision: 181257

URL: http://llvm.org/viewvc/llvm-project?rev=181257&view=rev
Log:
<rdar://problem/13063912>

If the user pressed ^D, that would bypass the exit confirmation mechanism
This checkin remedies that by making sure that users get prompted on exit when appropriate even if they use CTRL+D instead of typing quit at the prompt


Modified:
    lldb/trunk/tools/driver/IOChannel.cpp
    lldb/trunk/tools/driver/IOChannel.h

Modified: lldb/trunk/tools/driver/IOChannel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/IOChannel.cpp?rev=181257&r1=181256&r2=181257&view=diff
==============================================================================
--- lldb/trunk/tools/driver/IOChannel.cpp (original)
+++ lldb/trunk/tools/driver/IOChannel.cpp Mon May  6 17:10:33 2013
@@ -329,9 +329,10 @@ IOChannel::LibeditOutputBytesReceived (v
     }
 }
 
-bool
+IOChannel::LibeditGetInputResult
 IOChannel::LibeditGetInput (std::string &new_line)
 {
+    IOChannel::LibeditGetInputResult retval = IOChannel::eLibeditGetInputResultUnknown;
     if (m_edit_line != NULL)
     {
         int line_len = 0;
@@ -349,6 +350,7 @@ IOChannel::LibeditGetInput (std::string
 
         if (line)
         {
+            retval = IOChannel::eLibeditGetInputValid;
             // strip any newlines off the end of the string...
             while (line_len > 0 && (line[line_len - 1] == '\n' || line[line_len - 1] == '\r'))
                 --line_len;
@@ -359,17 +361,22 @@ IOChannel::LibeditGetInput (std::string
             }
             else
             {
+                retval = IOChannel::eLibeditGetInputEmpty;
                 // Someone just hit ENTER, return the empty string
                 new_line.clear();
             }
             // Return true to indicate success even if a string is empty
-            return true;
+            return retval;
+        }
+        else
+        {
+            retval = (line_len == 0 ? IOChannel::eLibeditGetInputEOF : IOChannel::eLibeditGetInputResultError);
         }
     }
     // Return false to indicate failure. This can happen when the file handle
     // is closed (EOF).
     new_line.clear();
-    return false;
+    return retval;
 }
 
 void *
@@ -422,9 +429,17 @@ IOChannel::Run ()
 
                     if (CommandQueueIsEmpty())
                     {
-                        if (LibeditGetInput(line) == false)
+                        IOChannel::LibeditGetInputResult getline_result = LibeditGetInput(line);
+                        if (getline_result == IOChannel::eLibeditGetInputEOF)
+                        {
+                            // EOF occurred
+                            // pretend that a quit was typed so the user gets a potential
+                            // chance to confirm
+                            line.assign("quit");
+                        }
+                        else if (getline_result == IOChannel::eLibeditGetInputResultError || getline_result == IOChannel::eLibeditGetInputResultUnknown)
                         {
-                            // EOF or some other file error occurred
+                            // some random error occurred, exit and don't ask because the state might be corrupt
                             done = true;
                             continue;
                         }

Modified: lldb/trunk/tools/driver/IOChannel.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/IOChannel.h?rev=181257&r1=181256&r2=181257&view=diff
==============================================================================
--- lldb/trunk/tools/driver/IOChannel.h (original)
+++ lldb/trunk/tools/driver/IOChannel.h Mon May  6 17:10:33 2013
@@ -38,6 +38,15 @@ public:
         eBroadcastBitsSTDIN           = (1 << 7),
         eAllEventBits                 = 0xffffffff
     };
+    
+    enum LibeditGetInputResult
+    {
+        eLibeditGetInputEOF = 0,
+        eLibeditGetInputValid = 1,
+        eLibeditGetInputEmpty = 2,
+        eLibeditGetInputResultError = 4,
+        eLibeditGetInputResultUnknown = 0xffffffff
+    };
 
     IOChannel (FILE *editline_in,
                FILE *editline_out,
@@ -66,7 +75,7 @@ public:
     void
     ErrWrite (const char *buffer, size_t len, bool asynchronous);
 
-    bool
+    LibeditGetInputResult
     LibeditGetInput (std::string &);
     
     static void





More information about the lldb-commits mailing list