diff options
author | Caroline Tice <ctice@apple.com> | 2011-06-16 16:27:19 +0000 |
---|---|---|
committer | Caroline Tice <ctice@apple.com> | 2011-06-16 16:27:19 +0000 |
commit | d61c10bc79322b5c51a6facf0de490b1dcf6a809 (patch) | |
tree | 73a8aea61d3de2ce8e74caa23e216bc18ce67fa4 | |
parent | b5703510595ebf8af37e6e7a479534a01e69fccd (diff) | |
download | bcm5719-llvm-d61c10bc79322b5c51a6facf0de490b1dcf6a809.tar.gz bcm5719-llvm-d61c10bc79322b5c51a6facf0de490b1dcf6a809.zip |
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
-rw-r--r-- | lldb/include/lldb/Interpreter/CommandInterpreter.h | 7 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectBreakpointCommand.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 20 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 41 | ||||
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 14 | ||||
-rw-r--r-- | lldb/source/Core/InputReader.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 56 |
9 files changed, 115 insertions, 70 deletions
diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 645650c3ee8..044d076fcdf 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -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; }; diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index b452dbc5106..c68f54cdf25 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -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; diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index e8d43779e5f..03fa8856045 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -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; diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 9f2e79e1a67..7d1af333d84 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -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."); diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 1399fb0de46..3245dbb0e42 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -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; } diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 5610ad764c6..ba43411dfaf 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -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()); } diff --git a/lldb/source/Core/InputReader.cpp b/lldb/source/Core/InputReader.cpp index 26f7f842314..c6e90eb54d7 100644 --- a/lldb/source/Core/InputReader.cpp +++ b/lldb/source/Core/InputReader.cpp @@ -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(); diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index c0f6dcd794e..d5f04020df1 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -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); diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index a3a3f9982d3..610c019cb33 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -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(); + } } } } |