[Lldb-commits] [lldb] r133162 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h source/Commands/CommandObjectBreakpointCommand.cpp source/Commands/CommandObjectCommands.cpp source/Commands/CommandObjectExpression.cpp source/Commands/CommandObjectTarget.cpp source/Core/Debugger.cpp source/Core/InputReader.cpp source/Interpreter/CommandInterpreter.cpp source/Interpreter/ScriptInterpreterPython.cpp
Caroline Tice
ctice at apple.com
Thu Jun 16 09:27:20 PDT 2011
Author: ctice
Date: Thu Jun 16 11:27:19 2011
New Revision: 133162
URL: http://llvm.org/viewvc/llvm-project?rev=133162&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Commands/CommandObjectExpression.cpp
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/source/Core/Debugger.cpp
lldb/trunk/source/Core/InputReader.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Thu Jun 16 11:27:19 2011
@@ -354,6 +354,12 @@
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 @@
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;
};
Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Thu Jun 16 11:27:19 2011
@@ -445,25 +445,29 @@
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 @@
((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 @@
((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;
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Thu Jun 16 11:27:19 2011
@@ -925,10 +925,12 @@
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 @@
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 @@
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;
Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Jun 16 11:27:19 2011
@@ -191,10 +191,12 @@
)
{
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 @@
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.");
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Thu Jun 16 11:27:19 2011
@@ -3075,17 +3075,21 @@
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 @@
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 @@
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 @@
{
// 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 @@
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;
}
Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Thu Jun 16 11:27:19 2011
@@ -452,19 +452,9 @@
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());
}
Modified: lldb/trunk/source/Core/InputReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/InputReader.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Core/InputReader.cpp (original)
+++ lldb/trunk/source/Core/InputReader.cpp Thu Jun 16 11:27:19 2011
@@ -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 @@
void
InputReader::RefreshPrompt ()
{
+ if (m_debugger.GetCommandInterpreter().GetBatchCommandMode())
+ return;
+
if (!m_prompt.empty())
{
File &out_file = m_debugger.GetOutputFile();
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Thu Jun 16 11:27:19 2011
@@ -69,7 +69,8 @@
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);
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=133162&r1=133161&r2=133162&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Thu Jun 16 11:27:19 2011
@@ -499,13 +499,18 @@
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 @@
{
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 @@
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 @@
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 @@
{
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 @@
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();
+ }
}
}
}
More information about the lldb-commits
mailing list