From f6913cd7af4c4a3ba6dfb0295f32a66a1413c9e2 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Fri, 7 Mar 2014 00:53:24 +0000 Subject: [PATCH] Allow line numbers to be shown in multi-line expressions. llvm-svn: 203185 --- lldb/include/lldb/Core/IOHandler.h | 8 ++++++- lldb/include/lldb/Host/Editline.h | 10 +++++++- .../source/Commands/CommandObjectCommands.cpp | 5 ++-- .../Commands/CommandObjectExpression.cpp | 1 + lldb/source/Core/IOHandler.cpp | 23 +++++++++++++++++++ lldb/source/Host/common/Editline.cpp | 1 + .../source/Interpreter/CommandInterpreter.cpp | 4 ++++ 7 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h index 78d1e7447db4..ae5a9b45e2c6 100644 --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -380,6 +380,7 @@ namespace lldb_private { const char *editline_name, // Used for saving history files const char *prompt, bool multi_line, + uint32_t line_number_start, // If non-zero show line numbers starting at 'line_number_start' IOHandlerDelegate &delegate); IOHandlerEditline (Debugger &debugger, @@ -390,6 +391,7 @@ namespace lldb_private { const char *editline_name, // Used for saving history files const char *prompt, bool multi_line, + uint32_t line_number_start, // If non-zero show line numbers starting at 'line_number_start' IOHandlerDelegate &delegate); virtual @@ -437,7 +439,10 @@ namespace lldb_private { bool GetLines (StringList &lines); - + + void + SetBaseLineNumber (uint32_t line); + private: static LineStatus LineCompletedCallback (Editline *editline, @@ -458,6 +463,7 @@ namespace lldb_private { std::unique_ptr m_editline_ap; IOHandlerDelegate &m_delegate; std::string m_prompt; + uint32_t m_base_line_number; // If non-zero, then show line numbers in prompt bool m_multi_line; }; diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h index b92de1052f29..9e1cc4d1e2c1 100644 --- a/lldb/include/lldb/Host/Editline.h +++ b/lldb/include/lldb/Host/Editline.h @@ -135,7 +135,14 @@ public: void SetPrompt (const char *p); - + + void + ShowLineNumbers (bool enable, uint32_t line_offset) + { + m_prompt_with_line_numbers = enable; + m_line_offset = line_offset; + } + private: Error @@ -193,6 +200,7 @@ private: LineCompletedCallbackType m_line_complete_callback; void *m_line_complete_callback_baton; Command m_lines_command; + uint32_t m_line_offset; uint32_t m_lines_curr_line; uint32_t m_lines_max_line; bool m_prompt_with_line_numbers; diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 7bfdec094d6c..e3e113aac23b 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -1034,9 +1034,10 @@ protected: Debugger &debugger = m_interpreter.GetDebugger(); const bool multiple_lines = true; // Get multiple lines IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger, - "lldb", // Name of input reader for history - "\033[K> ", // Prompt and clear line + "lldb", // Name of input reader for history + "\033[K> ", // Prompt and clear line multiple_lines, + 0, // Don't show line numbers *this)); if (io_handler_sp) diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index c772a2e58912..7dacaa73cd1a 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -428,6 +428,7 @@ CommandObjectExpression::DoExecute "lldb-expr", // Name of input reader for history NULL, // No prompt multiple_lines, + 1, // Show line numbers starting at 1 *this)); StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile()); diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 26039375105d..3bedb713c42a 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -157,6 +157,7 @@ IOHandlerConfirm::IOHandlerConfirm (Debugger &debugger, NULL, // NULL editline_name means no history loaded/saved NULL, false, // Multi-line + 0, *this), m_default_response (default_response), m_user_response (default_response) @@ -311,6 +312,7 @@ IOHandlerEditline::IOHandlerEditline (Debugger &debugger, const char *editline_name, // Used for saving history files const char *prompt, bool multi_line, + uint32_t line_number_start, IOHandlerDelegate &delegate) : IOHandlerEditline(debugger, StreamFileSP(), // Inherit input from top input reader @@ -320,6 +322,7 @@ IOHandlerEditline::IOHandlerEditline (Debugger &debugger, editline_name, // Used for saving history files prompt, multi_line, + line_number_start, delegate) { } @@ -332,11 +335,13 @@ IOHandlerEditline::IOHandlerEditline (Debugger &debugger, const char *editline_name, // Used for saving history files const char *prompt, bool multi_line, + uint32_t line_number_start, IOHandlerDelegate &delegate) : IOHandler (debugger, input_sp, output_sp, error_sp, flags), m_editline_ap (), m_delegate (delegate), m_prompt (), + m_base_line_number (line_number_start), m_multi_line (multi_line) { SetPrompt(prompt); @@ -356,6 +361,8 @@ IOHandlerEditline::IOHandlerEditline (Debugger &debugger, GetInputFILE (), GetOutputFILE (), GetErrorFILE ())); + if (m_base_line_number > 0) + m_editline_ap->ShowLineNumbers(true, m_base_line_number); m_editline_ap->SetLineCompleteCallback (LineCompletedCallback, this); m_editline_ap->SetAutoCompleteCallback (AutoCompleteCallback, this); } @@ -491,6 +498,14 @@ IOHandlerEditline::SetPrompt (const char *p) return true; } +void +IOHandlerEditline::SetBaseLineNumber (uint32_t line) +{ + m_base_line_number = line; + if (m_editline_ap) + m_editline_ap->ShowLineNumbers (true, line); + +} bool IOHandlerEditline::GetLines (StringList &lines) { @@ -506,7 +521,15 @@ IOHandlerEditline::GetLines (StringList &lines) while (lines_status == LineStatus::Success) { + // Show line numbers if we are asked to std::string line; + if (m_base_line_number > 0 && GetIsInteractive()) + { + FILE *out = GetOutputFILE(); + if (out) + ::fprintf(out, "%u", m_base_line_number + (uint32_t)lines.GetSize()); + } + if (GetLine(line)) { lines.AppendString(line); diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 9f96ce15f000..da08d0e3ee9a 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -42,6 +42,7 @@ Editline::Editline (const char *prog, // prog can't be NULL m_line_complete_callback (NULL), m_line_complete_callback_baton (NULL), m_lines_command (Command::None), + m_line_offset (0), m_lines_curr_line (0), m_lines_max_line (0), m_prompt_with_line_numbers (false), diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 7a563b7c122b..832ccbb06f37 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2663,6 +2663,7 @@ CommandInterpreter::HandleCommandsFromFile (FileSpec &cmd_file, NULL, // Pass in NULL for "editline_name" so no history is saved, or written debugger.GetPrompt(), false, // Not multi-line + 0, *this)); const bool old_async_execution = debugger.GetAsyncExecution(); @@ -3052,6 +3053,7 @@ CommandInterpreter::GetLLDBCommandsFromIOHandler (const char *prompt, "lldb", // Name of input reader for history prompt, // Prompt true, // Get multiple lines + 0, // Don't show line numbers delegate)); // IOHandlerDelegate if (io_handler_sp) @@ -3077,6 +3079,7 @@ CommandInterpreter::GetPythonCommandsFromIOHandler (const char *prompt, "lldb-python", // Name of input reader for history prompt, // Prompt true, // Get multiple lines + 0, // Don't show line numbers delegate)); // IOHandlerDelegate if (io_handler_sp) @@ -3110,6 +3113,7 @@ CommandInterpreter::RunCommandInterpreter(bool auto_handle_events, "lldb", m_debugger.GetPrompt(), multiple_lines, + 0, // Don't show line numbers *this)); m_debugger.PushIOHandler(m_command_io_handler_sp);