[Lldb-commits] [lldb] r208369 - "process kill" and "process detach" were causing double prompts or prompts that would overwrite each other. Fixed now.

Greg Clayton gclayton at apple.com
Thu May 8 16:04:40 PDT 2014


Author: gclayton
Date: Thu May  8 18:04:39 2014
New Revision: 208369

URL: http://llvm.org/viewvc/llvm-project?rev=208369&view=rev
Log:
"process kill" and "process detach" were causing double prompts or prompts that would overwrite each other. Fixed now.

<rdar://problem/16547729>

Modified:
    lldb/trunk/include/lldb/Host/Editline.h
    lldb/trunk/source/Core/IOHandler.cpp
    lldb/trunk/source/Host/common/Editline.cpp

Modified: lldb/trunk/include/lldb/Host/Editline.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Editline.h?rev=208369&r1=208368&r2=208369&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Editline.h (original)
+++ lldb/trunk/include/lldb/Host/Editline.h Thu May  8 18:04:39 2014
@@ -127,11 +127,6 @@ public:
 
     size_t
     Push (const char *bytes, size_t len);
-
-    // Cache bytes and use them for input without using a FILE. Calling this function
-    // will set the getc callback in the editline
-    size_t
-    SetInputBuffer (const char *c, size_t len);
     
     static int
     GetCharFromInputFileCallback (::EditLine *e, char *c);
@@ -159,10 +154,6 @@ private:
     
     unsigned char
     HandleCompletion (int ch);
-    
-    int
-    GetChar (char *c);
-
 
     static unsigned char
     CallbackEditPrevLine (::EditLine *e, int ch);
@@ -182,9 +173,6 @@ private:
     static FILE *
     GetFilePointer (::EditLine *e, int fd);
 
-    static int
-    GetCharInputBufferCallback (::EditLine *e, char *c);
-
     enum class Command
     {
         None = 0,
@@ -195,12 +183,9 @@ private:
     EditlineHistorySP m_history_sp;
     std::string m_prompt;
     std::string m_lines_prompt;
-    std::string m_getc_buffer;
-    Mutex m_getc_mutex;
-    Condition m_getc_cond;
+    lldb_private::Predicate<bool> m_getting_char;
     CompleteCallbackType m_completion_callback;
     void *m_completion_callback_baton;
-//    Mutex m_gets_mutex; // Make sure only one thread
     LineCompletedCallbackType m_line_complete_callback;
     void *m_line_complete_callback_baton;
     Command m_lines_command;

Modified: lldb/trunk/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=208369&r1=208368&r2=208369&view=diff
==============================================================================
--- lldb/trunk/source/Core/IOHandler.cpp (original)
+++ lldb/trunk/source/Core/IOHandler.cpp Thu May  8 18:04:39 2014
@@ -618,7 +618,7 @@ IOHandlerEditline::Run ()
 void
 IOHandlerEditline::Hide ()
 {
-    if (m_editline_ap && m_editline_ap->GettingLine())
+    if (m_editline_ap)
         m_editline_ap->Hide();
 }
 
@@ -626,8 +626,10 @@ IOHandlerEditline::Hide ()
 void
 IOHandlerEditline::Refresh ()
 {
-    if (m_editline_ap && m_editline_ap->GettingLine())
+    if (m_editline_ap)
+    {
         m_editline_ap->Refresh();
+    }
     else
     {
         const char *prompt = GetPrompt();

Modified: lldb/trunk/source/Host/common/Editline.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Editline.cpp?rev=208369&r1=208368&r2=208369&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Editline.cpp (original)
+++ lldb/trunk/source/Host/common/Editline.cpp Thu May  8 18:04:39 2014
@@ -162,10 +162,7 @@ Editline::Editline (const char *prog,
     m_history_sp (),
     m_prompt (),
     m_lines_prompt (),
-    m_getc_buffer (),
-    m_getc_mutex (Mutex::eMutexTypeNormal),
-    m_getc_cond (),
-//    m_gets_mutex (Mutex::eMutexTypeNormal),
+    m_getting_char (false),
     m_completion_callback (NULL),
     m_completion_callback_baton (NULL),
     m_line_complete_callback (NULL),
@@ -725,41 +722,6 @@ Editline::GetPromptCallback (::EditLine
     return "";
 }
 
-size_t
-Editline::SetInputBuffer (const char *c, size_t len)
-{
-    if (c && len > 0)
-    {
-        Mutex::Locker locker(m_getc_mutex);
-        SetGetCharCallback(GetCharInputBufferCallback);
-        m_getc_buffer.append(c, len);
-        m_getc_cond.Broadcast();
-    }
-    return len;
-}
-
-int
-Editline::GetChar (char *c)
-{
-    Mutex::Locker locker(m_getc_mutex);
-    if (m_getc_buffer.empty())
-        m_getc_cond.Wait(m_getc_mutex);
-    if (m_getc_buffer.empty())
-        return 0;
-    *c = m_getc_buffer[0];
-    m_getc_buffer.erase(0,1);
-    return 1;
-}
-
-int
-Editline::GetCharInputBufferCallback (EditLine *e, char *c)
-{
-    Editline *editline = GetClientData (e);
-    if (editline)
-        return editline->GetChar(c);
-    return 0;
-}
-
 int
 Editline::GetCharFromInputFileCallback (EditLine *e, char *c)
 {
@@ -778,7 +740,12 @@ Editline::GetCharFromInputFileCallback (
         {
             lldb::ConnectionStatus status = eConnectionStatusSuccess;
             char ch = 0;
-            if (editline->m_file.Read(&ch, 1, UINT32_MAX, status, NULL))
+            // When we start to call el_gets() the editline library needs to
+            // output the prompt
+            editline->m_getting_char.SetValue(true, eBroadcastAlways);
+            const size_t n = editline->m_file.Read(&ch, 1, UINT32_MAX, status, NULL);
+            editline->m_getting_char.SetValue(false, eBroadcastAlways);
+            if (n)
             {
                 if (ch == '\x04')
                 {
@@ -835,12 +802,23 @@ Editline::GetCharFromInputFileCallback (
 void
 Editline::Hide ()
 {
-    FILE *out_file = GetOutputFile();
-    if (out_file)
+    if (m_getting_line)
     {
-        const LineInfo *line_info  = ::el_line(m_editline);
-        if (line_info)
-            ::fprintf (out_file, "\033[%uD\033[K", (uint32_t)(strlen(GetPrompt()) + line_info->cursor - line_info->buffer));
+        // If we are getting a line, we might have started to call el_gets() and
+        // it might be printing the prompt. Here we make sure we are actually getting
+        // a character. This way we know the entire prompt has been printed.
+        TimeValue timeout = TimeValue::Now();
+        timeout.OffsetWithSeconds(1);
+        if (m_getting_char.WaitForValueEqualTo(true, &timeout))
+        {
+            FILE *out_file = GetOutputFile();
+            if (out_file)
+            {
+                const LineInfo *line_info  = ::el_line(m_editline);
+                if (line_info)
+                    ::fprintf (out_file, "\033[%uD\033[K", (uint32_t)(strlen(GetPrompt()) + line_info->cursor - line_info->buffer));
+            }
+        }
     }
 }
 
@@ -848,7 +826,18 @@ Editline::Hide ()
 void
 Editline::Refresh()
 {
-    ::el_set (m_editline, EL_REFRESH);
+    if (m_getting_line)
+    {
+        // If we are getting a line, we might have started to call el_gets() and
+        // it might be printing the prompt. Here we make sure we are actually getting
+        // a character. This way we know the entire prompt has been printed.
+        TimeValue timeout = TimeValue::Now();
+        timeout.OffsetWithSeconds(1);
+        if (m_getting_char.WaitForValueEqualTo(true, &timeout))
+        {
+            ::el_set (m_editline, EL_REFRESH);
+        }
+    }
 }
 
 bool





More information about the lldb-commits mailing list