diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -403,7 +403,7 @@ void SetInterruptExits(bool b) { m_interrupt_exits = b; } - const StringList *GetCurrentLines() const { return m_current_lines_ptr; } + StringList GetCurrentLines() const; uint32_t GetCurrentLineIndex() const; diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h --- a/lldb/include/lldb/Host/Editline.h +++ b/lldb/include/lldb/Host/Editline.h @@ -227,6 +227,9 @@ void PrintAsync(Stream *stream, const char *s, size_t len); + /// Convert the current input lines into a UTF8 StringList + StringList GetInputAsStringList(int line_count = UINT32_MAX); + private: /// Sets the lowest line number for multi-line editing sessions. A value of /// zero suppresses @@ -282,9 +285,6 @@ /// Save the line currently being edited void SaveEditedLine(); - /// Convert the current input lines into a UTF8 StringList - StringList GetInputAsStringList(int line_count = UINT32_MAX); - /// Replaces the current multi-line session with the next entry from history. unsigned char RecallHistory(HistoryOperation op); diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -508,6 +508,16 @@ return m_curr_line_idx; } +StringList IOHandlerEditline::GetCurrentLines() const { +#if LLDB_ENABLE_LIBEDIT + if (m_editline_up) + return m_editline_up->GetInputAsStringList(); +#endif + if (m_current_lines_ptr) + return *m_current_lines_ptr; + return StringList(); +} + bool IOHandlerEditline::GetLines(StringList &lines, bool &interrupted) { m_current_lines_ptr = &lines; diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -528,17 +528,15 @@ current_code.append(m_code.CopyList()); IOHandlerEditline &editline = static_cast(io_handler); - const StringList *current_lines = editline.GetCurrentLines(); - if (current_lines) { - const uint32_t current_line_idx = editline.GetCurrentLineIndex(); - - if (current_line_idx < current_lines->GetSize()) { - for (uint32_t i = 0; i < current_line_idx; ++i) { - const char *line_cstr = current_lines->GetStringAtIndex(i); - if (line_cstr) { - current_code.append("\n"); - current_code.append(line_cstr); - } + StringList current_lines = editline.GetCurrentLines(); + const uint32_t current_line_idx = editline.GetCurrentLineIndex(); + + if (current_line_idx < current_lines.GetSize()) { + for (uint32_t i = 0; i < current_line_idx; ++i) { + const char *line_cstr = current_lines.GetStringAtIndex(i); + if (line_cstr) { + current_code.append("\n"); + current_code.append(line_cstr); } } }