diff options
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/include/lldb/Host/Editline.h | 17 | ||||
-rw-r--r-- | lldb/source/Core/IOHandler.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Host/common/Editline.cpp | 81 |
3 files changed, 40 insertions, 64 deletions
diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h index 2f0b18a9799..6f4b56f0a44 100644 --- a/lldb/include/lldb/Host/Editline.h +++ b/lldb/include/lldb/Host/Editline.h @@ -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; diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 8573a1a9c5c..79eb89251c8 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -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(); diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 0b549444027..7af9f39a786 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -162,10 +162,7 @@ Editline::Editline (const char *prog, // prog can't be NULL 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 *e) 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 (EditLine *e, char *c) { 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 (EditLine *e, char *c) 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 |