diff options
| author | Greg Clayton <gclayton@apple.com> | 2010-06-23 01:19:29 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2010-06-23 01:19:29 +0000 |
| commit | 6611103cfe7a8c08554816fc08abef2e2960e799 (patch) | |
| tree | b940bb129b59af3cf6923f8d69f095d2d9fc8dca /lldb/source/Interpreter | |
| parent | ef5a4383ad679e58743c540c25d6a1bab0c77423 (diff) | |
| download | bcm5719-llvm-6611103cfe7a8c08554816fc08abef2e2960e799.tar.gz bcm5719-llvm-6611103cfe7a8c08554816fc08abef2e2960e799.zip | |
Very large changes that were needed in order to allow multiple connections
to the debugger from GUI windows. Previously there was one global debugger
instance that could be accessed that had its own command interpreter and
current state (current target/process/thread/frame). When a GUI debugger
was attached, if it opened more than one window that each had a console
window, there were issues where the last one to setup the global debugger
object won and got control of the debugger.
To avoid this we now create instances of the lldb_private::Debugger that each
has its own state:
- target list for targets the debugger instance owns
- current process/thread/frame
- its own command interpreter
- its own input, output and error file handles to avoid conflicts
- its own input reader stack
So now clients should call:
SBDebugger::Initialize(); // (static function)
SBDebugger debugger (SBDebugger::Create());
// Use which ever file handles you wish
debugger.SetErrorFileHandle (stderr, false);
debugger.SetOutputFileHandle (stdout, false);
debugger.SetInputFileHandle (stdin, true);
// main loop
SBDebugger::Terminate(); // (static function)
SBDebugger::Initialize() and SBDebugger::Terminate() are ref counted to
ensure nothing gets destroyed too early when multiple clients might be
attached.
Cleaned up the command interpreter and the CommandObject and all subclasses
to take more appropriate arguments.
llvm-svn: 106615
Diffstat (limited to 'lldb/source/Interpreter')
| -rw-r--r-- | lldb/source/Interpreter/CommandContext.cpp | 77 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 119 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 68 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandObjectRegexCommand.cpp | 8 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandObjectScript.cpp | 70 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandObjectScript.h | 14 | ||||
| -rw-r--r-- | lldb/source/Interpreter/Options.cpp | 40 | ||||
| -rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterNone.cpp | 12 | ||||
| -rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 91 |
9 files changed, 174 insertions, 325 deletions
diff --git a/lldb/source/Interpreter/CommandContext.cpp b/lldb/source/Interpreter/CommandContext.cpp deleted file mode 100644 index 012611c5262..00000000000 --- a/lldb/source/Interpreter/CommandContext.cpp +++ /dev/null @@ -1,77 +0,0 @@ -//===-- CommandContext.cpp --------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "lldb/Interpreter/CommandContext.h" - -#include "lldb/Core/Debugger.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Interpreter/CommandObject.h" -#include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" - -using namespace lldb; -using namespace lldb_private; - -CommandContext::CommandContext () : - m_exe_ctx () -{ -} - -CommandContext::~CommandContext () -{ -} - -Target * -CommandContext::GetTarget() -{ - return Debugger::GetSharedInstance().GetCurrentTarget().get(); -} - - -ExecutionContext & -CommandContext::GetExecutionContext() -{ - return m_exe_ctx; -} - -void -CommandContext::Update (ExecutionContext *override_context) -{ - m_exe_ctx.Clear(); - - if (override_context != NULL) - { - m_exe_ctx.target = override_context->target; - m_exe_ctx.process = override_context->process; - m_exe_ctx.thread = override_context->thread; - m_exe_ctx.frame = override_context->frame; - } - else - { - TargetSP target_sp (Debugger::GetSharedInstance().GetCurrentTarget()); - if (target_sp) - { - m_exe_ctx.process = target_sp->GetProcessSP().get(); - if (m_exe_ctx.process && m_exe_ctx.process->IsRunning() == false) - { - m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetCurrentThread().get(); - if (m_exe_ctx.thread == NULL) - m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get(); - if (m_exe_ctx.thread) - { - m_exe_ctx.frame = m_exe_ctx.thread->GetCurrentFrame().get(); - if (m_exe_ctx.frame == NULL) - m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get(); - } - } - } - } -} diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 2c278b1f13f..984711de193 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -12,7 +12,6 @@ #include <getopt.h> #include <stdlib.h> -#include "../Commands/CommandObjectAdd.h" #include "../Commands/CommandObjectAlias.h" #include "../Commands/CommandObjectAppend.h" #include "../Commands/CommandObjectApropos.h" @@ -33,7 +32,6 @@ #include "../Commands/CommandObjectQuit.h" #include "lldb/Interpreter/CommandObjectRegexCommand.h" #include "../Commands/CommandObjectRegister.h" -#include "../Commands/CommandObjectRemove.h" #include "CommandObjectScript.h" #include "../Commands/CommandObjectSelect.h" #include "../Commands/CommandObjectSet.h" @@ -44,7 +42,6 @@ #include "../Commands/CommandObjectSyntax.h" #include "../Commands/CommandObjectTarget.h" #include "../Commands/CommandObjectThread.h" -#include "../Commands/CommandObjectTranslate.h" #include "../Commands/CommandObjectUnalias.h" #include "../Commands/CommandObjectVariable.h" @@ -64,16 +61,14 @@ using namespace lldb_private; CommandInterpreter::CommandInterpreter ( + Debugger &debugger, ScriptLanguage script_language, - bool synchronous_execution, - Listener *listener, - SourceManager& source_manager + bool synchronous_execution ) : Broadcaster ("CommandInterpreter"), + m_debugger (debugger), m_script_language (script_language), - m_synchronous_execution (synchronous_execution), - m_listener (listener), - m_source_manager (source_manager) + m_synchronous_execution (synchronous_execution) { } @@ -204,43 +199,38 @@ CommandInterpreter::LoadCommandDictionary () // the crossref object exists and is ready to take the cross reference. Put the cross referencing command // objects into the CommandDictionary now, so they are ready for use when the other commands get created. - m_command_dict["select"] = CommandObjectSP (new CommandObjectSelect ()); - m_command_dict["info"] = CommandObjectSP (new CommandObjectInfo ()); - m_command_dict["delete"] = CommandObjectSP (new CommandObjectDelete ()); + m_command_dict["select"] = CommandObjectSP (new CommandObjectSelect ()); + m_command_dict["info"] = CommandObjectSP (new CommandObjectInfo ()); + m_command_dict["delete"] = CommandObjectSP (new CommandObjectDelete ()); // Non-CommandObjectCrossref commands can now be created. - //m_command_dict["add"] = CommandObjectSP (new CommandObjectAdd ()); m_command_dict["alias"] = CommandObjectSP (new CommandObjectAlias ()); m_command_dict["append"] = CommandObjectSP (new CommandObjectAppend ()); m_command_dict["apropos"] = CommandObjectSP (new CommandObjectApropos ()); - //m_command_dict["args"] = CommandObjectSP (new CommandObjectArgs ()); - m_command_dict["breakpoint"]= CommandObjectSP (new CommandObjectMultiwordBreakpoint (this)); + m_command_dict["breakpoint"]= CommandObjectSP (new CommandObjectMultiwordBreakpoint (*this)); m_command_dict["call"] = CommandObjectSP (new CommandObjectCall ()); m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble ()); m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression ()); m_command_dict["file"] = CommandObjectSP (new CommandObjectFile ()); - m_command_dict["frame"] = CommandObjectSP (new CommandObjectMultiwordFrame (this)); + m_command_dict["frame"] = CommandObjectSP (new CommandObjectMultiwordFrame (*this)); m_command_dict["help"] = CommandObjectSP (new CommandObjectHelp ()); - m_command_dict["image"] = CommandObjectSP (new CommandObjectImage (this)); - m_command_dict["log"] = CommandObjectSP (new CommandObjectLog (this)); - m_command_dict["memory"] = CommandObjectSP (new CommandObjectMemory (this)); - m_command_dict["process"] = CommandObjectSP (new CommandObjectMultiwordProcess (this)); + m_command_dict["image"] = CommandObjectSP (new CommandObjectImage (*this)); + m_command_dict["log"] = CommandObjectSP (new CommandObjectLog (*this)); + m_command_dict["memory"] = CommandObjectSP (new CommandObjectMemory (*this)); + m_command_dict["process"] = CommandObjectSP (new CommandObjectMultiwordProcess (*this)); m_command_dict["quit"] = CommandObjectSP (new CommandObjectQuit ()); - m_command_dict["register"] = CommandObjectSP (new CommandObjectRegister (this)); - //m_command_dict["remove"] = CommandObjectSP (new CommandObjectRemove ()); + m_command_dict["register"] = CommandObjectSP (new CommandObjectRegister (*this)); m_command_dict["script"] = CommandObjectSP (new CommandObjectScript (m_script_language)); m_command_dict["set"] = CommandObjectSP (new CommandObjectSet ()); m_command_dict["settings"] = CommandObjectSP (new CommandObjectSettings ()); m_command_dict["show"] = CommandObjectSP (new CommandObjectShow ()); m_command_dict["source"] = CommandObjectSP (new CommandObjectSource ()); m_command_dict["source-file"] = CommandObjectSP (new CommandObjectSourceFile ()); - //m_command_dict["syntax"] = CommandObjectSP (new CommandObjectSyntax ()); - m_command_dict["target"] = CommandObjectSP (new CommandObjectMultiwordTarget (this)); - m_command_dict["thread"] = CommandObjectSP (new CommandObjectMultiwordThread (this)); - //m_command_dict["translate"] = CommandObjectSP (new CommandObjectTranslate ()); + m_command_dict["target"] = CommandObjectSP (new CommandObjectMultiwordTarget (*this)); + m_command_dict["thread"] = CommandObjectSP (new CommandObjectMultiwordThread (*this)); m_command_dict["unalias"] = CommandObjectSP (new CommandObjectUnalias ()); - m_command_dict["variable"] = CommandObjectSP (new CommandObjectVariable (this)); + m_command_dict["variable"] = CommandObjectSP (new CommandObjectVariable (*this)); std::auto_ptr<CommandObjectRegexCommand> break_regex_cmd_ap(new CommandObjectRegexCommand ("regexp-break", @@ -568,8 +558,13 @@ CommandInterpreter::ShowVariableHelp (CommandReturnObject &result) // parses the line and takes the appropriate actions. bool -CommandInterpreter::HandleCommand (const char *command_line, bool add_to_history, CommandReturnObject &result, - ExecutionContext *override_context) +CommandInterpreter::HandleCommand +( + const char *command_line, + bool add_to_history, + CommandReturnObject &result, + ExecutionContext *override_context +) { // FIXME: there should probably be a mutex to make sure only one thread can // run the interpreter at a time. @@ -580,7 +575,7 @@ CommandInterpreter::HandleCommand (const char *command_line, bool add_to_history // result.AppendMessageWithFormat ("Processing command: %s\n", command_line); // } - m_current_context.Update (override_context); + m_debugger.UpdateExecutionContext (override_context); if (command_line == NULL || command_line[0] == '\0') { @@ -639,7 +634,7 @@ CommandInterpreter::HandleCommand (const char *command_line, bool add_to_history stripped_command += strlen(command_cstr); while (isspace(*stripped_command)) ++stripped_command; - command_obj->ExecuteRawCommandString(stripped_command, Context(), this, result); + command_obj->ExecuteRawCommandString (*this, stripped_command, result); } } else @@ -649,7 +644,7 @@ CommandInterpreter::HandleCommand (const char *command_line, bool add_to_history // Remove the command from the args. command_args.Shift(); - command_obj->ExecuteWithOptions (command_args, Context(), this, result); + command_obj->ExecuteWithOptions (*this, command_args, result); } } else @@ -658,9 +653,12 @@ CommandInterpreter::HandleCommand (const char *command_line, bool add_to_history int num_matches; int cursor_index = command_args.GetArgumentCount() - 1; int cursor_char_position = strlen (command_args.GetArgumentAtIndex(command_args.GetArgumentCount() - 1)); - num_matches = HandleCompletionMatches (command_args, cursor_index, - cursor_char_position, - 0, -1, matches); + num_matches = HandleCompletionMatches (command_args, + cursor_index, + cursor_char_position, + 0, + -1, + matches); if (num_matches > 0) { @@ -740,8 +738,12 @@ CommandInterpreter::HandleCompletionMatches (Args &parsed_line, { parsed_line.Shift(); cursor_index--; - num_command_matches = command_object->HandleCompletion (parsed_line, cursor_index, cursor_char_position, - match_start_point, max_return_elements, this, + num_command_matches = command_object->HandleCompletion (*this, + parsed_line, + cursor_index, + cursor_char_position, + match_start_point, + max_return_elements, matches); } } @@ -779,8 +781,12 @@ CommandInterpreter::HandleCompletion (const char *current_line, // Only max_return_elements == -1 is supported at present: assert (max_return_elements == -1); - num_command_matches = HandleCompletionMatches (parsed_line, cursor_index, cursor_char_position, match_start_point, - max_return_elements, matches); + num_command_matches = HandleCompletionMatches (parsed_line, + cursor_index, + cursor_char_position, + match_start_point, + max_return_elements, + matches); if (num_command_matches <= 0) return num_command_matches; @@ -817,12 +823,6 @@ CommandInterpreter::HandleCompletion (const char *current_line, return num_command_matches; } -CommandContext * -CommandInterpreter::Context () -{ - return &m_current_context; -} - const Args * CommandInterpreter::GetProgramArguments () { @@ -916,20 +916,6 @@ CommandInterpreter::SetScriptLanguage (ScriptLanguage lang) m_script_language = lang; } -Listener * -CommandInterpreter::GetListener () -{ - return m_listener; -} - -SourceManager & -CommandInterpreter::GetSourceManager () -{ - return m_source_manager; -} - - - OptionArgVectorSP CommandInterpreter::GetAliasOptions (const char *alias_name) { @@ -1132,16 +1118,15 @@ CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result) ScriptInterpreter * CommandInterpreter::GetScriptInterpreter () { - CommandObject::CommandMap::iterator pos; - - pos = m_command_dict.find ("script"); - if (pos != m_command_dict.end()) + CommandObject::CommandMap::iterator pos; + + pos = m_command_dict.find ("script"); + if (pos != m_command_dict.end()) { - CommandObject *script_cmd_obj = pos->second.get(); - return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter (); + CommandObject *script_cmd_obj = pos->second.get(); + return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter (*this); } - else - return NULL; + return NULL; } diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index eb8cdd2260d..384c03acfa2 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -133,21 +133,20 @@ CommandObject::GetFlags() const bool CommandObject::ExecuteCommandString ( + CommandInterpreter &interpreter, const char *command_line, - CommandContext *context, - CommandInterpreter *interpreter, CommandReturnObject &result ) { Args command_args(command_line); - return ExecuteWithOptions (command_args, context, interpreter, result); + return ExecuteWithOptions (interpreter, command_args, result); } bool CommandObject::ParseOptions ( + CommandInterpreter &interpreter, Args& args, - CommandInterpreter *interpreter, CommandReturnObject &result ) { @@ -189,9 +188,8 @@ CommandObject::ParseOptions bool CommandObject::ExecuteWithOptions ( + CommandInterpreter &interpreter, Args& args, - CommandContext *context, - CommandInterpreter *interpreter, CommandReturnObject &result ) { @@ -199,10 +197,10 @@ CommandObject::ExecuteWithOptions { const char *tmp_str = args.GetArgumentAtIndex (i); if (tmp_str[0] == '`') // back-quote - args.ReplaceArgumentAtIndex (i, interpreter->ProcessEmbeddedScriptCommands (tmp_str)); + args.ReplaceArgumentAtIndex (i, interpreter.ProcessEmbeddedScriptCommands (tmp_str)); } - Process *process = context->GetExecutionContext().process; + Process *process = interpreter.GetDebugger().GetExecutionContext().process; if (process == NULL) { if (GetFlags().IsSet(CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused)) @@ -248,11 +246,11 @@ CommandObject::ExecuteWithOptions } } - if (!ParseOptions (args, interpreter, result)) + if (!ParseOptions (interpreter, args, result)) return false; // Call the command-specific version of 'Execute', passing it the already processed arguments. - return Execute (args, context, interpreter, result); + return Execute (interpreter, args, result); } class CommandDictCommandPartialMatch @@ -300,12 +298,12 @@ CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, int CommandObject::HandleCompletion ( + CommandInterpreter &interpreter, Args &input, int &cursor_index, int &cursor_char_position, int match_start_point, int max_return_elements, - CommandInterpreter *interpreter, StringList &matches ) { @@ -340,46 +338,30 @@ CommandObject::HandleCompletion input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); bool handled_by_options; - handled_by_options = cur_options->HandleOptionCompletion(input, - opt_element_vector, - cursor_index, - cursor_char_position, - match_start_point, - max_return_elements, - interpreter, - matches); + handled_by_options = cur_options->HandleOptionCompletion (interpreter, + input, + opt_element_vector, + cursor_index, + cursor_char_position, + match_start_point, + max_return_elements, + matches); if (handled_by_options) return matches.GetSize(); } // If we got here, the last word is not an option or an option argument. - return HandleArgumentCompletion(input, - cursor_index, - cursor_char_position, - opt_element_vector, - match_start_point, - max_return_elements, - interpreter, - matches); + return HandleArgumentCompletion (interpreter, + input, + cursor_index, + cursor_char_position, + opt_element_vector, + match_start_point, + max_return_elements, + matches); } } -int -CommandObject::HandleArgumentCompletion -( - Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - CommandInterpreter *interpreter, - StringList &matches -) -{ - return 0; -} - // Case insensitive version of ::strstr() // Returns true if s2 is contained within s1. diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp index b3fa6a41d97..e165fc8009a 100644 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -46,9 +46,8 @@ CommandObjectRegexCommand::~CommandObjectRegexCommand() bool CommandObjectRegexCommand::Execute ( + CommandInterpreter &interpreter, Args& command, - CommandContext *context, - CommandInterpreter *interpreter, CommandReturnObject &result ) { @@ -59,9 +58,8 @@ CommandObjectRegexCommand::Execute bool CommandObjectRegexCommand::ExecuteRawCommandString ( + CommandInterpreter &interpreter, const char *command, - CommandContext *context, - CommandInterpreter *interpreter, CommandReturnObject &result ) { @@ -92,7 +90,7 @@ CommandObjectRegexCommand::ExecuteRawCommandString // Interpret the new command and return this as the result! // if (m_options.verbose) // result.GetOutputStream().Printf("%s\n", new_command.c_str()); - return interpreter->HandleCommand(new_command.c_str(), true, result); + return interpreter.HandleCommand(new_command.c_str(), true, result); } } result.SetStatus(eReturnStatusFailed); diff --git a/lldb/source/Interpreter/CommandObjectScript.cpp b/lldb/source/Interpreter/CommandObjectScript.cpp index 2cbca117bfc..3a7362de075 100644 --- a/lldb/source/Interpreter/CommandObjectScript.cpp +++ b/lldb/source/Interpreter/CommandObjectScript.cpp @@ -43,15 +43,12 @@ CommandObjectScript::~CommandObjectScript () bool CommandObjectScript::ExecuteRawCommandString ( + CommandInterpreter &interpreter, const char *command, - CommandContext *context, - CommandInterpreter *interpreter, CommandReturnObject &result ) { - std::string arg_str (command); - - ScriptInterpreter *script_interpreter = GetInterpreter (); + ScriptInterpreter *script_interpreter = GetInterpreter (interpreter); if (script_interpreter == NULL) { @@ -59,23 +56,11 @@ CommandObjectScript::ExecuteRawCommandString result.SetStatus (eReturnStatusFailed); } - FILE *out_fh = Debugger::GetSharedInstance().GetOutputFileHandle(); - FILE *err_fh = Debugger::GetSharedInstance().GetOutputFileHandle(); - if (out_fh && err_fh) - { - if (arg_str.empty()) - script_interpreter->ExecuteInterpreterLoop (out_fh, err_fh); - else - script_interpreter->ExecuteOneLine (arg_str, out_fh, err_fh); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } + if (command == NULL || command[0] == '\0') + script_interpreter->ExecuteInterpreterLoop (interpreter); else - { - if (out_fh == NULL) - result.AppendError("invalid output file handle"); - else - result.AppendError("invalid error file handle"); - } + script_interpreter->ExecuteOneLine (interpreter, command); + result.SetStatus (eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } @@ -88,60 +73,29 @@ CommandObjectScript::WantsRawCommandString() bool CommandObjectScript::Execute ( + CommandInterpreter &interpreter, Args& command, - CommandContext *context, - CommandInterpreter *interpreter, CommandReturnObject &result ) { - std::string arg_str; - ScriptInterpreter *script_interpreter = GetInterpreter (); - - if (script_interpreter == NULL) - { - result.AppendError("no script interpeter"); - result.SetStatus (eReturnStatusFailed); - } - - const int argc = command.GetArgumentCount(); - for (int i = 0; i < argc; ++i) - arg_str.append(command.GetArgumentAtIndex(i)); - - - FILE *out_fh = Debugger::GetSharedInstance().GetOutputFileHandle(); - FILE *err_fh = Debugger::GetSharedInstance().GetOutputFileHandle(); - if (out_fh && err_fh) - { - if (arg_str.empty()) - script_interpreter->ExecuteInterpreterLoop (out_fh, err_fh); - else - script_interpreter->ExecuteOneLine (arg_str, out_fh, err_fh); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - if (out_fh == NULL) - result.AppendError("invalid output file handle"); - else - result.AppendError("invalid error file handle"); - } - return result.Succeeded(); + // everything should be handled in ExecuteRawCommandString + return false; } ScriptInterpreter * -CommandObjectScript::GetInterpreter () +CommandObjectScript::GetInterpreter (CommandInterpreter &interpreter) { if (m_interpreter_ap.get() == NULL) { switch (m_script_lang) { case eScriptLanguagePython: - m_interpreter_ap.reset (new ScriptInterpreterPython ()); + m_interpreter_ap.reset (new ScriptInterpreterPython (interpreter)); break; case eScriptLanguageNone: - m_interpreter_ap.reset (new ScriptInterpreterNone ()); + m_interpreter_ap.reset (new ScriptInterpreterNone (interpreter)); break; } } diff --git a/lldb/source/Interpreter/CommandObjectScript.h b/lldb/source/Interpreter/CommandObjectScript.h index 7cd57518ff7..d74f7b156fd 100644 --- a/lldb/source/Interpreter/CommandObjectScript.h +++ b/lldb/source/Interpreter/CommandObjectScript.h @@ -34,19 +34,17 @@ public: bool WantsRawCommandString(); virtual bool - ExecuteRawCommandString (const char *command, - CommandContext *context, - CommandInterpreter *interpreter, - CommandReturnObject &result); + ExecuteRawCommandString (CommandInterpreter &interpreter, + const char *command, + CommandReturnObject &result); virtual bool - Execute (Args& command, - CommandContext *context, - CommandInterpreter *interpreter, + Execute (CommandInterpreter &interpreter, + Args& command, CommandReturnObject &result); ScriptInterpreter * - GetInterpreter (); + GetInterpreter (CommandInterpreter &interpreter); private: lldb::ScriptLanguage m_script_lang; diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 1f42e2a417b..9baa9d26d43 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -532,13 +532,13 @@ Options::VerifyPartialOptions (CommandReturnObject &result) bool Options::HandleOptionCompletion ( + CommandInterpreter &interpreter, Args &input, OptionElementVector &opt_element_vector, int cursor_index, int char_pos, int match_start_point, int max_return_elements, - lldb_private::CommandInterpreter *interpreter, lldb_private::StringList &matches ) { @@ -625,15 +625,15 @@ Options::HandleOptionCompletion if (opt_defs_index != -1) { - HandleOptionArgumentCompletion (input, - cursor_index, - strlen (input.GetArgumentAtIndex(cursor_index)), - opt_element_vector, - i, - match_start_point, - max_return_elements, - interpreter, - matches); + HandleOptionArgumentCompletion (interpreter, + input, + cursor_index, + strlen (input.GetArgumentAtIndex(cursor_index)), + opt_element_vector, + i, + match_start_point, + max_return_elements, + matches); return true; } else @@ -655,6 +655,7 @@ Options::HandleOptionCompletion bool Options::HandleOptionArgumentCompletion ( + CommandInterpreter &interpreter, Args &input, int cursor_index, int char_pos, @@ -662,7 +663,6 @@ Options::HandleOptionArgumentCompletion int opt_element_index, int match_start_point, int max_return_elements, - lldb_private::CommandInterpreter *interpreter, lldb_private::StringList &matches ) { @@ -713,7 +713,7 @@ Options::HandleOptionArgumentCompletion if (module_name) { FileSpec module_spec(module_name); - lldb::TargetSP target_sp = interpreter->Context()->GetTarget()->GetSP(); + lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget(); // Search filters require a target... if (target_sp != NULL) filter_ap.reset (new SearchFilterByModule (target_sp, module_spec)); @@ -723,12 +723,12 @@ Options::HandleOptionArgumentCompletion } } - return CommandCompletions::InvokeCommonCompletionCallbacks (completion_mask, - input.GetArgumentAtIndex (opt_arg_pos), - match_start_point, - max_return_elements, - interpreter, - filter_ap.get(), - matches); - + return CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, + completion_mask, + input.GetArgumentAtIndex (opt_arg_pos), + match_start_point, + max_return_elements, + filter_ap.get(), + matches); + } diff --git a/lldb/source/Interpreter/ScriptInterpreterNone.cpp b/lldb/source/Interpreter/ScriptInterpreterNone.cpp index cdc399e7d86..c9bd2827fc9 100644 --- a/lldb/source/Interpreter/ScriptInterpreterNone.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterNone.cpp @@ -10,11 +10,13 @@ #include "lldb/Interpreter/ScriptInterpreterNone.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StringList.h" +#include "lldb/Core/Debugger.h" +#include "lldb/Interpreter/CommandInterpreter.h" using namespace lldb; using namespace lldb_private; -ScriptInterpreterNone::ScriptInterpreterNone () : +ScriptInterpreterNone::ScriptInterpreterNone (CommandInterpreter &interpreter) : ScriptInterpreter (eScriptLanguageNone) { } @@ -24,15 +26,15 @@ ScriptInterpreterNone::~ScriptInterpreterNone () } void -ScriptInterpreterNone::ExecuteOneLine (const std::string &line, FILE *out, FILE *err) +ScriptInterpreterNone::ExecuteOneLine (CommandInterpreter &interpreter, const char *command) { - ::fprintf (err, "error: there is no embedded script interpreter in this mode.\n"); + interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n"); } void -ScriptInterpreterNone::ExecuteInterpreterLoop (FILE *out, FILE *err) +ScriptInterpreterNone::ExecuteInterpreterLoop (CommandInterpreter &interpreter) { - fprintf (err, "error: there is no embedded script interpreter in this mode.\n"); + interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n"); } diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 59eb4642298..5fb0130f354 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -24,6 +24,7 @@ #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointLocation.h" +#include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/FileSpec.h" #include "lldb/Core/InputReader.h" @@ -33,6 +34,7 @@ #include "lldb/Host/Host.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" +#include "lldb/Core/Debugger.h" #include "lldb/Target/Process.h" extern "C" void init_lldb (void); @@ -139,7 +141,7 @@ _check_and_flush (FILE *stream) return fflush (stream) || prev_fail ? EOF : 0; } -ScriptInterpreterPython::ScriptInterpreterPython () : +ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interpreter) : ScriptInterpreter (eScriptLanguagePython), m_compiled_module (NULL), m_termios_valid (false) @@ -194,7 +196,7 @@ ScriptInterpreterPython::ScriptInterpreterPython () : } const char *pty_slave_name = GetScriptInterpreterPtyName (); - FILE *out_fh = Debugger::GetSharedInstance().GetOutputFileHandle(); + FILE *out_fh = interpreter.GetDebugger().GetOutputFileHandle(); PyObject *pmod = PyImport_ExecCodeModule( const_cast<char*>("embedded_interpreter"), @@ -249,14 +251,15 @@ ScriptInterpreterPython::~ScriptInterpreterPython () } void -ScriptInterpreterPython::ExecuteOneLine (const std::string& line, FILE *out, FILE *err) +ScriptInterpreterPython::ExecuteOneLine (CommandInterpreter &interpreter, const char *command) { - int success; - - success = PyRun_SimpleString (line.c_str()); - if (success != 0) + if (command) { - fprintf (err, "error: python failed attempting to evaluate '%s'\n", line.c_str()); + int success; + + success = PyRun_SimpleString (command); + if (success != 0) + interpreter.GetDebugger().GetErrorStream().Printf ("error: python failed attempting to evaluate '%s'\n", command); } } @@ -266,7 +269,7 @@ size_t ScriptInterpreterPython::InputReaderCallback ( void *baton, - InputReader *reader, + InputReader &reader, lldb::InputReaderAction notification, const char *bytes, size_t bytes_len @@ -275,19 +278,20 @@ ScriptInterpreterPython::InputReaderCallback if (baton == NULL) return 0; - ScriptInterpreterPython *interpreter = (ScriptInterpreterPython *) baton; + ScriptInterpreterPython *script_interpreter = (ScriptInterpreterPython *) baton; switch (notification) { case eInputReaderActivate: { // Save terminal settings if we can - interpreter->m_termios_valid = ::tcgetattr (::fileno (reader->GetInputFileHandle()), - &interpreter->m_termios) == 0; + FILE *input_fh = reader.GetDebugger().GetInputFileHandle(); + int input_fd = ::fileno (input_fh); + script_interpreter->m_termios_valid = ::tcgetattr (input_fd, &script_interpreter->m_termios) == 0; struct termios tmp_termios; - if (::tcgetattr (::fileno (reader->GetInputFileHandle()), &tmp_termios) == 0) + if (::tcgetattr (input_fd, &tmp_termios) == 0) { tmp_termios.c_cc[VEOF] = _POSIX_VDISABLE; - ::tcsetattr (::fileno (reader->GetInputFileHandle()), TCSANOW, &tmp_termios); + ::tcsetattr (input_fd, TCSANOW, &tmp_termios); } } break; @@ -302,11 +306,11 @@ ScriptInterpreterPython::InputReaderCallback if (bytes && bytes_len) { if ((int) bytes[0] == 4) - ::write (interpreter->GetMasterFileDescriptor(), "quit()", 6); + ::write (script_interpreter->GetMasterFileDescriptor(), "quit()", 6); else - ::write (interpreter->GetMasterFileDescriptor(), bytes, bytes_len); + ::write (script_interpreter->GetMasterFileDescriptor(), bytes, bytes_len); } - ::write (interpreter->GetMasterFileDescriptor(), "\n", 1); + ::write (script_interpreter->GetMasterFileDescriptor(), "\n", 1); break; case eInputReaderDone: @@ -315,11 +319,11 @@ ScriptInterpreterPython::InputReaderCallback // Write a newline out to the reader output //::fwrite ("\n", 1, 1, out_fh); // Restore terminal settings if they were validly saved - if (interpreter->m_termios_valid) + if (script_interpreter->m_termios_valid) { - ::tcsetattr (::fileno (reader->GetInputFileHandle()), + ::tcsetattr (::fileno (reader.GetDebugger().GetInputFileHandle()), TCSANOW, - &interpreter->m_termios); + &script_interpreter->m_termios); } break; } @@ -329,11 +333,12 @@ ScriptInterpreterPython::InputReaderCallback void -ScriptInterpreterPython::ExecuteInterpreterLoop (FILE *out, FILE *err) +ScriptInterpreterPython::ExecuteInterpreterLoop (CommandInterpreter &interpreter) { Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); - InputReaderSP reader_sp (new InputReader()); + Debugger &debugger = interpreter.GetDebugger(); + InputReaderSP reader_sp (new InputReader(debugger)); if (reader_sp) { Error error (reader_sp->Initialize (ScriptInterpreterPython::InputReaderCallback, @@ -345,9 +350,9 @@ ScriptInterpreterPython::ExecuteInterpreterLoop (FILE *out, FILE *err) if (error.Success()) { - Debugger::GetSharedInstance().PushInputReader (reader_sp); - ExecuteOneLine ("run_python_interpreter(ConsoleDict)", out, err); - Debugger::GetSharedInstance().PopInputReader (reader_sp); + debugger.PushInputReader (reader_sp); + ExecuteOneLine (interpreter, "run_python_interpreter(ConsoleDict)"); + debugger.PopInputReader (reader_sp); } } } @@ -528,7 +533,7 @@ size_t ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback ( void *baton, - InputReader *reader, + InputReader &reader, lldb::InputReaderAction notification, const char *bytes, size_t bytes_len @@ -536,7 +541,7 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback { static StringList commands_in_progress; - FILE *out_fh = reader->GetOutputFileHandle(); + FILE *out_fh = reader.GetDebugger().GetOutputFileHandle(); switch (notification) { case eInputReaderActivate: @@ -545,8 +550,8 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback if (out_fh) { ::fprintf (out_fh, "%s\n", g_reader_instructions); - if (reader->GetPrompt()) - ::fprintf (out_fh, "%s", reader->GetPrompt()); + if (reader.GetPrompt()) + ::fprintf (out_fh, "%s", reader.GetPrompt()); } } break; @@ -555,16 +560,16 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback break; case eInputReaderReactivate: - if (reader->GetPrompt() && out_fh) - ::fprintf (out_fh, "%s", reader->GetPrompt()); + if (reader.GetPrompt() && out_fh) + ::fprintf (out_fh, "%s", reader.GetPrompt()); break; case eInputReaderGotToken: { std::string temp_string (bytes, bytes_len); commands_in_progress.AppendString (temp_string.c_str()); - if (out_fh && !reader->IsDone() && reader->GetPrompt()) - ::fprintf (out_fh, "%s", reader->GetPrompt()); + if (out_fh && !reader.IsDone() && reader.GetPrompt()) + ::fprintf (out_fh, "%s", reader.GetPrompt()); } break; @@ -575,7 +580,7 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback data_ap->user_source.AppendList (commands_in_progress); if (data_ap.get()) { - ScriptInterpreter *interpreter = Debugger::GetSharedInstance().GetCommandInterpreter().GetScriptInterpreter(); + ScriptInterpreter *interpreter = reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); if (interpreter) { if (interpreter->GenerateBreakpointCommandCallbackData (data_ap->user_source, @@ -602,10 +607,12 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback } void -ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, +ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (CommandInterpreter &interpreter, + BreakpointOptions *bp_options, CommandReturnObject &result) { - InputReaderSP reader_sp (new InputReader ()); + Debugger &debugger = interpreter.GetDebugger(); + InputReaderSP reader_sp (new InputReader (debugger)); if (reader_sp) { @@ -618,7 +625,7 @@ ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (BreakpointOpti true); // echo input if (err.Success()) - Debugger::GetSharedInstance().PushInputReader (reader_sp); + debugger.PushInputReader (reader_sp); else { result.AppendError (err.AsCString()); @@ -819,11 +826,11 @@ ScriptInterpreterPython::BreakpointCallbackFunction if (python_string != NULL) { - bool success = - Debugger::GetSharedInstance().GetCommandInterpreter().GetScriptInterpreter()->ExecuteOneLineWithReturn - (python_string, - ScriptInterpreter::eBool, - (void *) &temp_bool); + bool success = context->exe_ctx.target->GetDebugger(). + GetCommandInterpreter(). + GetScriptInterpreter()->ExecuteOneLineWithReturn (python_string, + ScriptInterpreter::eBool, + (void *) &temp_bool); if (success) ret_value = temp_bool; } |

