forked from OSchip/llvm-project
Add 'batch_mode' to CommandInterpreter. Modify InputReaders to
not write output (prompts, instructions,etc.) if the CommandInterpreter is in batch_mode. Also, finish updating InputReaders to write to the asynchronous stream, rather than using the Debugger's output file directly. llvm-svn: 133162
This commit is contained in:
parent
b570351059
commit
d61c10bc79
|
@ -354,6 +354,12 @@ public:
|
|||
const char *search_word,
|
||||
StringList &commands_found,
|
||||
StringList &commands_help);
|
||||
|
||||
bool
|
||||
GetBatchCommandMode () { return m_batch_command_mode; }
|
||||
|
||||
void
|
||||
SetBatchCommandMode (bool value) { m_batch_command_mode = value; }
|
||||
|
||||
protected:
|
||||
friend class Debugger;
|
||||
|
@ -378,6 +384,7 @@ private:
|
|||
std::string m_repeat_command; // Stores the command that will be executed for an empty command string.
|
||||
std::auto_ptr<ScriptInterpreter> m_script_interpreter_ap;
|
||||
char m_comment_char;
|
||||
bool m_batch_command_mode;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -445,25 +445,29 @@ CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback
|
|||
size_t bytes_len
|
||||
)
|
||||
{
|
||||
File &out_file = reader.GetDebugger().GetOutputFile();
|
||||
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
|
||||
|
||||
switch (notification)
|
||||
{
|
||||
case eInputReaderActivate:
|
||||
out_file.Printf ("%s\n", g_reader_instructions);
|
||||
if (reader.GetPrompt())
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush();
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("%s\n", g_reader_instructions);
|
||||
if (reader.GetPrompt())
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush();
|
||||
}
|
||||
break;
|
||||
|
||||
case eInputReaderDeactivate:
|
||||
break;
|
||||
|
||||
case eInputReaderReactivate:
|
||||
if (reader.GetPrompt())
|
||||
if (reader.GetPrompt() && !batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -481,10 +485,10 @@ CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback
|
|||
((BreakpointOptions::CommandData *)bp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len);
|
||||
}
|
||||
}
|
||||
if (!reader.IsDone() && reader.GetPrompt())
|
||||
if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -502,8 +506,11 @@ CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback
|
|||
((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.Clear();
|
||||
}
|
||||
}
|
||||
out_file.Printf ("Warning: No command attached to breakpoint.\n");
|
||||
out_file.Flush();
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("Warning: No command attached to breakpoint.\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -925,10 +925,12 @@ CommandObjectCommandsAddRegex::InputReaderCallback (void *baton,
|
|||
size_t bytes_len)
|
||||
{
|
||||
CommandObjectCommandsAddRegex *add_regex_cmd = (CommandObjectCommandsAddRegex *) baton;
|
||||
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
|
||||
|
||||
switch (notification)
|
||||
{
|
||||
case eInputReaderActivate:
|
||||
if (!batch_mode)
|
||||
{
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream ();
|
||||
out_stream->Printf("%s\n", "Enter regular expressions in the form 's/<regex>/<subst>/' and terminate with an empty line:");
|
||||
|
@ -955,9 +957,12 @@ CommandObjectCommandsAddRegex::InputReaderCallback (void *baton,
|
|||
Error error (add_regex_cmd->AppendRegexSubstitution (bytes_strref));
|
||||
if (error.Fail())
|
||||
{
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
out_stream->Printf("error: %s\n", error.AsCString());
|
||||
out_stream->Flush();
|
||||
if (!batch_mode)
|
||||
{
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
out_stream->Printf("error: %s\n", error.AsCString());
|
||||
out_stream->Flush();
|
||||
}
|
||||
add_regex_cmd->InputReaderDidCancel ();
|
||||
reader.SetIsDone (true);
|
||||
}
|
||||
|
@ -967,9 +972,12 @@ CommandObjectCommandsAddRegex::InputReaderCallback (void *baton,
|
|||
case eInputReaderInterrupt:
|
||||
{
|
||||
reader.SetIsDone (true);
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
out_stream->PutCString("Regular expression command creations was cancelled.\n");
|
||||
out_stream->Flush();
|
||||
if (!batch_mode)
|
||||
{
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
out_stream->PutCString("Regular expression command creations was cancelled.\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
add_regex_cmd->InputReaderDidCancel ();
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -191,10 +191,12 @@ CommandObjectExpression::MultiLineExpressionCallback
|
|||
)
|
||||
{
|
||||
CommandObjectExpression *cmd_object_expr = (CommandObjectExpression *) baton;
|
||||
|
||||
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
|
||||
|
||||
switch (notification)
|
||||
{
|
||||
case eInputReaderActivate:
|
||||
if (!batch_mode)
|
||||
{
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
out_stream->Printf("%s\n", "Enter expressions, then terminate with an empty line to evaluate:");
|
||||
|
@ -224,6 +226,7 @@ CommandObjectExpression::MultiLineExpressionCallback
|
|||
case eInputReaderInterrupt:
|
||||
cmd_object_expr->m_expr_lines.clear();
|
||||
reader.SetIsDone (true);
|
||||
if (!batch_mode)
|
||||
{
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
out_stream->Printf("%s\n", "Expression evaluation cancelled.");
|
||||
|
|
|
@ -3075,17 +3075,21 @@ public:
|
|||
const char *bytes,
|
||||
size_t bytes_len)
|
||||
{
|
||||
File &out_file = reader.GetDebugger().GetOutputFile();
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
|
||||
static bool got_interrupted;
|
||||
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
|
||||
|
||||
switch (notification)
|
||||
{
|
||||
case eInputReaderActivate:
|
||||
out_file.Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
|
||||
if (reader.GetPrompt())
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush();
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
|
||||
if (reader.GetPrompt())
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush();
|
||||
}
|
||||
got_interrupted = false;
|
||||
break;
|
||||
|
||||
|
@ -3093,10 +3097,10 @@ public:
|
|||
break;
|
||||
|
||||
case eInputReaderReactivate:
|
||||
if (reader.GetPrompt())
|
||||
if (reader.GetPrompt() && !batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush();
|
||||
}
|
||||
got_interrupted = false;
|
||||
break;
|
||||
|
@ -3113,10 +3117,10 @@ public:
|
|||
commands->AppendString (bytes, bytes_len);
|
||||
}
|
||||
}
|
||||
if (!reader.IsDone() && reader.GetPrompt())
|
||||
if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -3124,8 +3128,12 @@ public:
|
|||
{
|
||||
// Finish, and cancel the stop hook.
|
||||
new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
|
||||
out_file.Printf ("Stop hook cancelled.\n");
|
||||
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("Stop hook cancelled.\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
|
||||
reader.SetIsDone (true);
|
||||
}
|
||||
got_interrupted = true;
|
||||
|
@ -3136,8 +3144,11 @@ public:
|
|||
break;
|
||||
|
||||
case eInputReaderDone:
|
||||
if (!got_interrupted)
|
||||
out_file.Printf ("Stop hook #%d added.\n", new_stop_hook->GetID());
|
||||
if (!got_interrupted && !batch_mode)
|
||||
{
|
||||
out_stream->Printf ("Stop hook #%d added.\n", new_stop_hook->GetID());
|
||||
out_stream->Flush();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -452,19 +452,9 @@ Debugger::NotifyTopInputReader (InputReaderAction notification)
|
|||
bool
|
||||
Debugger::InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp)
|
||||
{
|
||||
if (reader_sp)
|
||||
{
|
||||
InputReaderSP top_reader_sp (GetCurrentInputReader());
|
||||
if (top_reader_sp)
|
||||
{
|
||||
return (reader_sp.get() == top_reader_sp.get());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
InputReaderSP top_reader_sp (GetCurrentInputReader());
|
||||
|
||||
return (reader_sp.get() == top_reader_sp.get());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "lldb/Core/InputReader.h"
|
||||
#include "lldb/Core/Debugger.h"
|
||||
#include "lldb/Interpreter/CommandInterpreter.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
@ -300,6 +301,9 @@ InputReader::GetPrompt () const
|
|||
void
|
||||
InputReader::RefreshPrompt ()
|
||||
{
|
||||
if (m_debugger.GetCommandInterpreter().GetBatchCommandMode())
|
||||
return;
|
||||
|
||||
if (!m_prompt.empty())
|
||||
{
|
||||
File &out_file = m_debugger.GetOutputFile();
|
||||
|
|
|
@ -69,7 +69,8 @@ CommandInterpreter::CommandInterpreter
|
|||
m_synchronous_execution (synchronous_execution),
|
||||
m_skip_lldbinit_files (false),
|
||||
m_script_interpreter_ap (),
|
||||
m_comment_char ('#')
|
||||
m_comment_char ('#'),
|
||||
m_batch_command_mode (false)
|
||||
{
|
||||
const char *dbg_name = debugger.GetInstanceName().AsCString();
|
||||
std::string lang_name = ScriptInterpreter::LanguageToString (script_language);
|
||||
|
|
|
@ -499,13 +499,18 @@ ScriptInterpreterPython::InputReaderCallback
|
|||
if (script_interpreter->m_script_lang != eScriptLanguagePython)
|
||||
return 0;
|
||||
|
||||
File &out_file = reader.GetDebugger().GetOutputFile();
|
||||
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
|
||||
|
||||
switch (notification)
|
||||
{
|
||||
case eInputReaderActivate:
|
||||
{
|
||||
out_file.Printf ("Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.\n");
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
|
||||
// Save terminal settings if we can
|
||||
int input_fd = reader.GetDebugger().GetInputFile().GetDescriptor();
|
||||
|
@ -518,7 +523,8 @@ ScriptInterpreterPython::InputReaderCallback
|
|||
{
|
||||
while (!GetPythonLock(1))
|
||||
{
|
||||
out_file.Printf ("Python interpreter locked on another thread; waiting to acquire lock...\n");
|
||||
out_stream->Printf ("Python interpreter locked on another thread; waiting to acquire lock...\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
script_interpreter->EnterSession ();
|
||||
ReleasePythonLock();
|
||||
|
@ -958,21 +964,22 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
|
|||
size_t bytes_len
|
||||
)
|
||||
{
|
||||
static StringList commands_in_progress;
|
||||
|
||||
File &out_file = reader.GetDebugger().GetOutputFile();
|
||||
|
||||
static StringList commands_in_progress;
|
||||
|
||||
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
|
||||
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
|
||||
|
||||
switch (notification)
|
||||
{
|
||||
case eInputReaderActivate:
|
||||
{
|
||||
commands_in_progress.Clear();
|
||||
if (out_file.IsValid())
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s\n", g_reader_instructions);
|
||||
out_stream->Printf ("%s\n", g_reader_instructions);
|
||||
if (reader.GetPrompt())
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush ();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush ();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -981,10 +988,10 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
|
|||
break;
|
||||
|
||||
case eInputReaderReactivate:
|
||||
if (reader.GetPrompt() && out_file.IsValid())
|
||||
if (reader.GetPrompt() && !batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush ();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush ();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -995,10 +1002,10 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
|
|||
{
|
||||
std::string temp_string (bytes, bytes_len);
|
||||
commands_in_progress.AppendString (temp_string.c_str());
|
||||
if (out_file.IsValid() && !reader.IsDone() && reader.GetPrompt())
|
||||
if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
|
||||
{
|
||||
out_file.Printf ("%s", reader.GetPrompt());
|
||||
out_file.Flush ();
|
||||
out_stream->Printf ("%s", reader.GetPrompt());
|
||||
out_stream->Flush ();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1033,12 +1040,19 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
|
|||
bp_options->SetCallback (ScriptInterpreterPython::BreakpointCallbackFunction, baton_sp);
|
||||
}
|
||||
}
|
||||
else
|
||||
out_file.Printf ("Warning: No command attached to breakpoint.\n");
|
||||
else if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("Warning: No command attached to breakpoint.\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out_file.Printf ("Warning: Unable to find script intepreter; no command attached to breakpoint.\n");
|
||||
if (!batch_mode)
|
||||
{
|
||||
out_stream->Printf ("Warning: Unable to find script intepreter; no command attached to breakpoint.\n");
|
||||
out_stream->Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue