Allow line numbers to be shown in multi-line expressions.

llvm-svn: 203185
This commit is contained in:
Greg Clayton 2014-03-07 00:53:24 +00:00
parent b9a0265cc1
commit f6913cd7af
7 changed files with 48 additions and 4 deletions

View File

@ -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<Editline> 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;
};

View File

@ -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;

View File

@ -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)

View File

@ -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());

View File

@ -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);

View File

@ -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),

View File

@ -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);