[Lldb-commits] [lldb] r133209 - in /lldb/branches/commands-from-file: include/lldb/API/SBCommandInterpreter.h include/lldb/API/SBInputReader.h include/lldb/Core/Debugger.h include/lldb/Interpreter/CommandInterpreter.h source/API/SBCommandInterpreter.cpp source/Interpreter/CommandInterpreter.cpp tools/driver/Driver.cpp
Caroline Tice
ctice at apple.com
Thu Jun 16 15:40:38 PDT 2011
Author: ctice
Date: Thu Jun 16 17:40:38 2011
New Revision: 133209
URL: http://llvm.org/viewvc/llvm-project?rev=133209&view=rev
Log:
Commit current work on reading commands from files and
directing it to appropriate InputReaders. Hopefully
this commit will go to my newly created branch.
Modified:
lldb/branches/commands-from-file/include/lldb/API/SBCommandInterpreter.h
lldb/branches/commands-from-file/include/lldb/API/SBInputReader.h
lldb/branches/commands-from-file/include/lldb/Core/Debugger.h
lldb/branches/commands-from-file/include/lldb/Interpreter/CommandInterpreter.h
lldb/branches/commands-from-file/source/API/SBCommandInterpreter.cpp
lldb/branches/commands-from-file/source/Interpreter/CommandInterpreter.cpp
lldb/branches/commands-from-file/tools/driver/Driver.cpp
Modified: lldb/branches/commands-from-file/include/lldb/API/SBCommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/include/lldb/API/SBCommandInterpreter.h?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/include/lldb/API/SBCommandInterpreter.h (original)
+++ lldb/branches/commands-from-file/include/lldb/API/SBCommandInterpreter.h Thu Jun 16 17:40:38 2011
@@ -87,6 +87,9 @@
int match_start_point,
int max_return_elements,
lldb::SBStringList &matches);
+
+ void
+ SetInputReader (lldb::SBInputReader &reader);
protected:
Modified: lldb/branches/commands-from-file/include/lldb/API/SBInputReader.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/include/lldb/API/SBInputReader.h?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/include/lldb/API/SBInputReader.h (original)
+++ lldb/branches/commands-from-file/include/lldb/API/SBInputReader.h Thu Jun 16 17:40:38 2011
@@ -64,6 +64,7 @@
protected:
friend class SBDebugger;
+ friend class SBCommandInterpreter;
#ifndef SWIG
Modified: lldb/branches/commands-from-file/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/include/lldb/Core/Debugger.h?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/include/lldb/Core/Debugger.h (original)
+++ lldb/branches/commands-from-file/include/lldb/Core/Debugger.h Thu Jun 16 17:40:38 2011
@@ -429,6 +429,7 @@
SetCloseInputOnEOF (bool b);
protected:
+ friend class CommandInterpreter;
static void
DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
Modified: lldb/branches/commands-from-file/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/include/lldb/Interpreter/CommandInterpreter.h?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/branches/commands-from-file/include/lldb/Interpreter/CommandInterpreter.h Thu Jun 16 17:40:38 2011
@@ -360,6 +360,12 @@
void
SetBatchCommandMode (bool value) { m_batch_command_mode = value; }
+
+ lldb::InputReaderSP &
+ GetInputReader () { return m_default_input_reader; }
+
+ void
+ SetInputReader (lldb::InputReaderSP &reader_sp) { m_default_input_reader = reader_sp; }
protected:
friend class Debugger;
@@ -385,6 +391,7 @@
std::auto_ptr<ScriptInterpreter> m_script_interpreter_ap;
char m_comment_char;
bool m_batch_command_mode;
+ lldb::InputReaderSP m_default_input_reader;
};
Modified: lldb/branches/commands-from-file/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/source/API/SBCommandInterpreter.cpp?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/branches/commands-from-file/source/API/SBCommandInterpreter.cpp Thu Jun 16 17:40:38 2011
@@ -18,6 +18,7 @@
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBCommandReturnObject.h"
+#include "lldb/API/SBInputReader.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBCommandInterpreter.h"
#include "lldb/API/SBProcess.h"
@@ -304,6 +305,13 @@
return CommandObject::GetArgumentDescriptionAsCString (arg_type);
}
+void
+SBCommandInterpreter::SetInputReader (lldb::SBInputReader &reader)
+{
+ InputReaderSP reader_sp (reader.get());
+ if (m_opaque_ptr)
+ m_opaque_ptr->SetInputReader (reader_sp);
+}
extern "C" bool
LLDBSwigPythonBreakpointCallbackFunction
Modified: lldb/branches/commands-from-file/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/source/Interpreter/CommandInterpreter.cpp?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/branches/commands-from-file/source/Interpreter/CommandInterpreter.cpp Thu Jun 16 17:40:38 2011
@@ -70,7 +70,8 @@
m_skip_lldbinit_files (false),
m_script_interpreter_ap (),
m_comment_char ('#'),
- m_batch_command_mode (false)
+ m_batch_command_mode (false),
+ m_default_input_reader ()
{
const char *dbg_name = debugger.GetInstanceName().AsCString();
std::string lang_name = ScriptInterpreter::LanguageToString (script_language);
@@ -1874,16 +1875,71 @@
{
if (cmd_file.Exists())
{
- bool success;
StringList commands;
- success = commands.ReadFileLines(cmd_file);
+ InputReaderSP cmd_input_reader = GetInputReader();
+
+ bool success = commands.ReadFileLines(cmd_file);
if (!success)
{
result.AppendErrorWithFormat ("Error reading commands from file: %s.\n", cmd_file.GetFilename().AsCString());
result.SetStatus (eReturnStatusFailed);
return;
}
- HandleCommands (commands, context, stop_on_continue, stop_on_error, echo_command, print_result, result);
+
+ bool old_async_execution = m_debugger.GetAsyncExecution();
+ if (!stop_on_continue)
+ m_debugger.SetAsyncExecution (false);
+
+ bool save_auto_confirm = m_debugger.GetAutoConfirm();
+ m_debugger.SetAutoConfirm (true);
+
+ bool save_batch_command_mode = GetBatchCommandMode();
+ SetBatchCommandMode (true);
+
+ size_t num_lines = commands.GetSize();
+ StreamString input_stream;
+ for (size_t i = 0; i < num_lines;++i)
+ {
+ const char *cmd = commands.GetStringAtIndex (i);
+ if (m_debugger.InputReaderIsTopReader (cmd_input_reader))
+ {
+ CommandReturnObject tmp_result;
+
+ if (!cmd || (strlen(cmd) == 0)) // Do NOT interpreter blank lines as 'repeat'
+ continue;
+
+ if (echo_command)
+ result.AppendMessageWithFormat ("%s\n", cmd);
+ success = HandleCommand(cmd, false, tmp_result, NULL);
+ if (!success || !tmp_result.Succeeded())
+ {
+ if (stop_on_error)
+ {
+ result.AppendErrorWithFormat ("Aborting reading of commands after command #%d: '%s' failed.\n",
+ i, cmd);
+ result.SetStatus (eReturnStatusFailed);
+ m_debugger.SetAsyncExecution (old_async_execution);
+ SetBatchCommandMode (save_batch_command_mode);
+ return;
+ } else if (print_result)
+ {
+ result.AppendMessageWithFormat ("Command #%d '%s' failed with error: %s.\n",
+ i + 1,
+ cmd,
+ tmp_result.GetErrorData());
+ }
+ }
+ }
+ else
+ {
+ if (echo_command)
+ result.AppendMessageWithFormat ("%s\n", cmd);
+ m_debugger.DispatchInput (cmd, strlen(cmd));
+ m_debugger.DispatchInput ("\n", 1);
+ }
+ }
+ SetBatchCommandMode (save_batch_command_mode);
+ m_debugger.SetAutoConfirm (save_auto_confirm);
}
else
{
Modified: lldb/branches/commands-from-file/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/commands-from-file/tools/driver/Driver.cpp?rev=133209&r1=133208&r2=133209&view=diff
==============================================================================
--- lldb/branches/commands-from-file/tools/driver/Driver.cpp (original)
+++ lldb/branches/commands-from-file/tools/driver/Driver.cpp Thu Jun 16 17:40:38 2011
@@ -1115,6 +1115,7 @@
}
m_debugger.PushInputReader (m_editline_reader);
+ m_debugger.GetCommandInterpreter().SetInputReader (m_editline_reader);
SBListener listener(m_debugger.GetListener());
if (listener.IsValid())
More information about the lldb-commits
mailing list