From d61c10bc79322b5c51a6facf0de490b1dcf6a809 Mon Sep 17 00:00:00 2001 From: Caroline Tice Date: Thu, 16 Jun 2011 16:27:19 +0000 Subject: 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 --- .../source/Interpreter/ScriptInterpreterPython.cpp | 56 ++++++++++++++-------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp') 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(); + } } } } -- cgit v1.2.3