diff options
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 43 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 42 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObjectRegexCommand.cpp | 7 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObjectScript.cpp | 19 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObjectScript.h | 11 | ||||
-rw-r--r-- | lldb/source/Interpreter/Options.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreter.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterNone.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 20 |
9 files changed, 76 insertions, 98 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 85622069236..48176f76b28 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -149,29 +149,30 @@ CommandInterpreter::LoadCommandDictionary () bool success; script_language = Args::StringToScriptLanguage (value.GetStringAtIndex(0), lldb::eScriptLanguageDefault, &success); - m_command_dict["apropos"] = CommandObjectSP (new CommandObjectApropos ()); + m_command_dict["apropos"] = CommandObjectSP (new CommandObjectApropos (*this)); m_command_dict["breakpoint"]= CommandObjectSP (new CommandObjectMultiwordBreakpoint (*this)); - //m_command_dict["call"] = CommandObjectSP (new CommandObjectCall ()); + //m_command_dict["call"] = CommandObjectSP (new CommandObjectCall (*this)); m_command_dict["commands"] = CommandObjectSP (new CommandObjectMultiwordCommands (*this)); - m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble ()); - m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression ()); - m_command_dict["file"] = CommandObjectSP (new CommandObjectFile ()); + m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble (*this)); + m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression (*this)); + m_command_dict["file"] = CommandObjectSP (new CommandObjectFile (*this)); m_command_dict["frame"] = CommandObjectSP (new CommandObjectMultiwordFrame (*this)); - m_command_dict["help"] = CommandObjectSP (new CommandObjectHelp ()); + m_command_dict["help"] = CommandObjectSP (new CommandObjectHelp (*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["quit"] = CommandObjectSP (new CommandObjectQuit (*this)); m_command_dict["register"] = CommandObjectSP (new CommandObjectRegister (*this)); - m_command_dict["script"] = CommandObjectSP (new CommandObjectScript (script_language)); + m_command_dict["script"] = CommandObjectSP (new CommandObjectScript (*this, script_language)); m_command_dict["settings"] = CommandObjectSP (new CommandObjectMultiwordSettings (*this)); m_command_dict["source"] = CommandObjectSP (new CommandObjectMultiwordSource (*this)); m_command_dict["target"] = CommandObjectSP (new CommandObjectMultiwordTarget (*this)); m_command_dict["thread"] = CommandObjectSP (new CommandObjectMultiwordThread (*this)); std::auto_ptr<CommandObjectRegexCommand> - break_regex_cmd_ap(new CommandObjectRegexCommand ("regexp-break", + break_regex_cmd_ap(new CommandObjectRegexCommand (*this, + "regexp-break", "Set a breakpoint using a regular expression to specify the location.", "regexp-break [<file>:<line>]\nregexp-break [<address>]\nregexp-break <...>", 2)); if (break_regex_cmd_ap.get()) @@ -574,14 +575,14 @@ CommandInterpreter::HandleCommand stripped_command += strlen(command_cstr); while (isspace(*stripped_command)) ++stripped_command; - command_obj->ExecuteRawCommandString (*this, stripped_command, result); + command_obj->ExecuteRawCommandString (stripped_command, result); } } else { // Remove the command from the args. command_args.Shift(); - command_obj->ExecuteWithOptions (*this, command_args, result); + command_obj->ExecuteWithOptions (command_args, result); } } else @@ -681,8 +682,7 @@ CommandInterpreter::HandleCompletionMatches (Args &parsed_line, { parsed_line.Shift(); cursor_index--; - num_command_matches = command_object->HandleCompletion (*this, - parsed_line, + num_command_matches = command_object->HandleCompletion (parsed_line, cursor_index, cursor_char_position, match_start_point, @@ -1010,7 +1010,7 @@ CommandInterpreter::GetScriptInterpreter () if (pos != m_command_dict.end()) { CommandObject *script_cmd_obj = pos->second.get(); - return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter (*this); + return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter (); } return NULL; } @@ -1041,15 +1041,8 @@ CommandInterpreter::OutputFormattedHelpText (Stream &strm, const char *help_text, uint32_t max_word_len) { - lldb::SettableVariableType var_type; - const char *width_value = - Debugger::GetSettingsController()->GetVariable ("term-width", var_type, - m_debugger.GetInstanceName().AsCString()).GetStringAtIndex(0); - int max_columns = atoi (width_value); - // Sanity check max_columns, to cope with emacs shell mode with TERM=dumb - // (0 rows; 0 columns;). - if (max_columns <= 0) max_columns = 80; - + const uint32_t max_columns = m_debugger.GetTerminalWidth(); + int indent_size = max_word_len + strlen (separator) + 2; strm.IndentMore (indent_size); @@ -1135,7 +1128,7 @@ CommandInterpreter::AproposAllSubCommands (CommandObject *cmd_obj, const char *p complete_command_name.Printf ("%s %s", prefix, command_name); - if (sub_cmd_obj->HelpTextContainsWord (search_word, *this)) + if (sub_cmd_obj->HelpTextContainsWord (search_word)) { commands_found.AppendString (complete_command_name.GetData()); commands_help.AppendString (sub_cmd_obj->GetHelp()); @@ -1159,7 +1152,7 @@ CommandInterpreter::FindCommandsForApropos (const char *search_word, StringList const char *command_name = pos->first.c_str(); CommandObject *cmd_obj = pos->second.get(); - if (cmd_obj->HelpTextContainsWord (search_word, *this)) + if (cmd_obj->HelpTextContainsWord (search_word)) { commands_found.AppendString (command_name); commands_help.AppendString (cmd_obj->GetHelp()); diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index 571c3d49f14..0784b4a9f78 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -38,7 +38,15 @@ using namespace lldb_private; // CommandObject //------------------------------------------------------------------------- -CommandObject::CommandObject (const char *name, const char *help, const char *syntax, uint32_t flags) : +CommandObject::CommandObject +( + CommandInterpreter &interpreter, + const char *name, + const char *help, + const char *syntax, + uint32_t flags +) : + m_interpreter (interpreter), m_cmd_name (name), m_cmd_help_short (), m_cmd_help_long (), @@ -134,19 +142,17 @@ CommandObject::GetFlags() const bool CommandObject::ExecuteCommandString ( - CommandInterpreter &interpreter, const char *command_line, CommandReturnObject &result ) { Args command_args(command_line); - return ExecuteWithOptions (interpreter, command_args, result); + return ExecuteWithOptions (command_args, result); } bool CommandObject::ParseOptions ( - CommandInterpreter &interpreter, Args& args, CommandReturnObject &result ) @@ -177,8 +183,7 @@ CommandObject::ParseOptions else { // No error string, output the usage information into result - options->GenerateOptionUsage (result.GetErrorStream(), this, - interpreter.GetDebugger().GetInstanceName().AsCString()); + options->GenerateOptionUsage (m_interpreter, result.GetErrorStream(), this); } // Set the return status to failed (this was an error). result.SetStatus (eReturnStatusFailed); @@ -188,21 +193,16 @@ CommandObject::ParseOptions return true; } bool -CommandObject::ExecuteWithOptions -( - CommandInterpreter &interpreter, - Args& args, - CommandReturnObject &result -) +CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result) { for (size_t i = 0; i < args.GetArgumentCount(); ++i) { const char *tmp_str = args.GetArgumentAtIndex (i); if (tmp_str[0] == '`') // back-quote - args.ReplaceArgumentAtIndex (i, interpreter.ProcessEmbeddedScriptCommands (tmp_str)); + args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str)); } - Process *process = interpreter.GetDebugger().GetExecutionContext().process; + Process *process = m_interpreter.GetDebugger().GetExecutionContext().process; if (process == NULL) { if (GetFlags().IsSet(CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused)) @@ -248,11 +248,11 @@ CommandObject::ExecuteWithOptions } } - if (!ParseOptions (interpreter, args, result)) + if (!ParseOptions (args, result)) return false; // Call the command-specific version of 'Execute', passing it the already processed arguments. - return Execute (interpreter, args, result); + return Execute (args, result); } class CommandDictCommandPartialMatch @@ -300,7 +300,6 @@ CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, int CommandObject::HandleCompletion ( - CommandInterpreter &interpreter, Args &input, int &cursor_index, int &cursor_char_position, @@ -341,7 +340,7 @@ CommandObject::HandleCompletion input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); bool handled_by_options; - handled_by_options = cur_options->HandleOptionCompletion (interpreter, + handled_by_options = cur_options->HandleOptionCompletion (m_interpreter, input, opt_element_vector, cursor_index, @@ -355,8 +354,7 @@ CommandObject::HandleCompletion } // If we got here, the last word is not an option or an option argument. - return HandleArgumentCompletion (interpreter, - input, + return HandleArgumentCompletion (input, cursor_index, cursor_char_position, opt_element_vector, @@ -397,7 +395,7 @@ contains_string (const char *s1, const char *s2) } bool -CommandObject::HelpTextContainsWord (const char *search_word, CommandInterpreter &interpreter) +CommandObject::HelpTextContainsWord (const char *search_word) { const char *short_help; const char *long_help; @@ -422,7 +420,7 @@ CommandObject::HelpTextContainsWord (const char *search_word, CommandInterpreter && GetOptions() != NULL) { StreamString usage_help; - GetOptions()->GenerateOptionUsage (usage_help, this, interpreter.GetDebugger().GetInstanceName().AsCString()); + GetOptions()->GenerateOptionUsage (m_interpreter, usage_help, this); if (usage_help.GetSize() > 0) { const char *usage_text = usage_help.GetData(); diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp index 30f3eef50ef..534038aeaff 100644 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -24,12 +24,13 @@ using namespace lldb_private; //---------------------------------------------------------------------- CommandObjectRegexCommand::CommandObjectRegexCommand ( + CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t max_matches ) : - CommandObject (name, help, syntax), + CommandObject (interpreter, name, help, syntax), m_max_matches (max_matches), m_entries () { @@ -46,7 +47,6 @@ CommandObjectRegexCommand::~CommandObjectRegexCommand() bool CommandObjectRegexCommand::Execute ( - CommandInterpreter &interpreter, Args& command, CommandReturnObject &result ) @@ -58,7 +58,6 @@ CommandObjectRegexCommand::Execute bool CommandObjectRegexCommand::ExecuteRawCommandString ( - CommandInterpreter &interpreter, const char *command, CommandReturnObject &result ) @@ -90,7 +89,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 m_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 a9d9afca320..59b9a75086e 100644 --- a/lldb/source/Interpreter/CommandObjectScript.cpp +++ b/lldb/source/Interpreter/CommandObjectScript.cpp @@ -27,8 +27,9 @@ using namespace lldb_private; // CommandObjectScript //------------------------------------------------------------------------- -CommandObjectScript::CommandObjectScript (ScriptLanguage script_lang) : - CommandObject ("script", +CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) : + CommandObject (interpreter, + "script", "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.", "script [<script-expression-for-evaluation>]"), m_script_lang (script_lang), @@ -43,12 +44,11 @@ CommandObjectScript::~CommandObjectScript () bool CommandObjectScript::ExecuteRawCommandString ( - CommandInterpreter &interpreter, const char *command, CommandReturnObject &result ) { - ScriptInterpreter *script_interpreter = GetInterpreter (interpreter); + ScriptInterpreter *script_interpreter = GetInterpreter (); if (script_interpreter == NULL) { @@ -57,13 +57,13 @@ CommandObjectScript::ExecuteRawCommandString } if (command == NULL || command[0] == '\0') { - script_interpreter->ExecuteInterpreterLoop (interpreter); + script_interpreter->ExecuteInterpreterLoop (); result.SetStatus (eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } // We can do better when reporting the status of one-liner script execution. - if (script_interpreter->ExecuteOneLine (interpreter, command, &result)) + if (script_interpreter->ExecuteOneLine (command, &result)) result.SetStatus(eReturnStatusSuccessFinishNoResult); else result.SetStatus(eReturnStatusFailed); @@ -80,7 +80,6 @@ CommandObjectScript::WantsRawCommandString() bool CommandObjectScript::Execute ( - CommandInterpreter &interpreter, Args& command, CommandReturnObject &result ) @@ -91,18 +90,18 @@ CommandObjectScript::Execute ScriptInterpreter * -CommandObjectScript::GetInterpreter (CommandInterpreter &interpreter) +CommandObjectScript::GetInterpreter () { if (m_interpreter_ap.get() == NULL) { switch (m_script_lang) { case eScriptLanguagePython: - m_interpreter_ap.reset (new ScriptInterpreterPython (interpreter)); + m_interpreter_ap.reset (new ScriptInterpreterPython (m_interpreter)); break; case eScriptLanguageNone: - m_interpreter_ap.reset (new ScriptInterpreterNone (interpreter)); + m_interpreter_ap.reset (new ScriptInterpreterNone (m_interpreter)); break; } } diff --git a/lldb/source/Interpreter/CommandObjectScript.h b/lldb/source/Interpreter/CommandObjectScript.h index d74f7b156fd..eacd3a6b3ea 100644 --- a/lldb/source/Interpreter/CommandObjectScript.h +++ b/lldb/source/Interpreter/CommandObjectScript.h @@ -26,7 +26,8 @@ class CommandObjectScript : public CommandObject { public: - CommandObjectScript (lldb::ScriptLanguage script_lang); + CommandObjectScript (CommandInterpreter &interpreter, + lldb::ScriptLanguage script_lang); virtual ~CommandObjectScript (); @@ -34,17 +35,15 @@ public: bool WantsRawCommandString(); virtual bool - ExecuteRawCommandString (CommandInterpreter &interpreter, - const char *command, + ExecuteRawCommandString (const char *command, CommandReturnObject &result); virtual bool - Execute (CommandInterpreter &interpreter, - Args& command, + Execute (Args& command, CommandReturnObject &result); ScriptInterpreter * - GetInterpreter (CommandInterpreter &interpreter); + GetInterpreter (); private: lldb::ScriptLanguage m_script_lang; diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 65171b6a6d7..8e7f80896f3 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -361,27 +361,21 @@ Options::OutputFormattedUsageText void Options::GenerateOptionUsage ( + CommandInterpreter &interpreter, Stream &strm, - CommandObject *cmd, - const char *debugger_instance_name, - const char *program_name) + CommandObject *cmd +) { - lldb::SettableVariableType var_type; - const char *screen_width_str = - Debugger::GetSettingsController()->GetVariable ("term-width", var_type, - debugger_instance_name).GetStringAtIndex(0); - uint32_t screen_width = atoi (screen_width_str); - if (screen_width == 0) - screen_width = 80; + const uint32_t screen_width = interpreter.GetDebugger().GetTerminalWidth(); const lldb::OptionDefinition *full_options_table = GetDefinitions(); const uint32_t save_indent_level = strm.GetIndentLevel(); const char *name; if (cmd) - name = cmd->GetCommandName(); + name = cmd->GetCommandName(); else - name = program_name; + name = ""; strm.PutCString ("\nCommand Options Usage:\n"); diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index e4b5634258a..aedeff705c2 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -22,7 +22,8 @@ using namespace lldb; using namespace lldb_private; -ScriptInterpreter::ScriptInterpreter (ScriptLanguage script_lang) : +ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, ScriptLanguage script_lang) : + m_interpreter (interpreter), m_script_lang (script_lang), m_interpreter_pty () { @@ -54,7 +55,6 @@ ScriptInterpreter::GetMasterFileDescriptor () void ScriptInterpreter::CollectDataForBreakpointCommandCallback ( - CommandInterpreter &interpreter, BreakpointOptions *bp_options, CommandReturnObject &result ) diff --git a/lldb/source/Interpreter/ScriptInterpreterNone.cpp b/lldb/source/Interpreter/ScriptInterpreterNone.cpp index dad70aa93d5..3a8f98e380c 100644 --- a/lldb/source/Interpreter/ScriptInterpreterNone.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterNone.cpp @@ -17,7 +17,7 @@ using namespace lldb; using namespace lldb_private; ScriptInterpreterNone::ScriptInterpreterNone (CommandInterpreter &interpreter) : - ScriptInterpreter (eScriptLanguageNone) + ScriptInterpreter (interpreter, eScriptLanguageNone) { } @@ -26,16 +26,16 @@ ScriptInterpreterNone::~ScriptInterpreterNone () } bool -ScriptInterpreterNone::ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *) +ScriptInterpreterNone::ExecuteOneLine (const char *command, CommandReturnObject *) { - interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n"); + m_interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n"); return false; } void -ScriptInterpreterNone::ExecuteInterpreterLoop (CommandInterpreter &interpreter) +ScriptInterpreterNone::ExecuteInterpreterLoop () { - interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n"); + m_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 39ae32a931a..511de8fc792 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -144,7 +144,7 @@ _check_and_flush (FILE *stream) } ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interpreter) : - ScriptInterpreter (eScriptLanguagePython), + ScriptInterpreter (interpreter, eScriptLanguagePython), m_compiled_module (NULL), m_termios_valid (false) { @@ -254,9 +254,7 @@ ScriptInterpreterPython::~ScriptInterpreterPython () } bool -ScriptInterpreterPython::ExecuteOneLine (CommandInterpreter &interpreter, - const char *command, - CommandReturnObject *result = 0) +ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObject *result) { if (command) { @@ -357,11 +355,11 @@ ScriptInterpreterPython::InputReaderCallback void -ScriptInterpreterPython::ExecuteInterpreterLoop (CommandInterpreter &interpreter) +ScriptInterpreterPython::ExecuteInterpreterLoop () { Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); - Debugger &debugger = interpreter.GetDebugger(); + Debugger &debugger = m_interpreter.GetDebugger(); // At the moment, the only time the debugger does not have an input file handle is when this is called // directly from Python, in which case it is both dangerous and unnecessary (not to mention confusing) to @@ -384,7 +382,7 @@ ScriptInterpreterPython::ExecuteInterpreterLoop (CommandInterpreter &interpreter if (error.Success()) { debugger.PushInputReader (reader_sp); - ExecuteOneLine (interpreter, "run_python_interpreter(ConsoleDict)"); + ExecuteOneLine ("run_python_interpreter(ConsoleDict)", NULL); debugger.PopInputReader (reader_sp); } } @@ -643,11 +641,10 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback } void -ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (CommandInterpreter &interpreter, - BreakpointOptions *bp_options, +ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, CommandReturnObject &result) { - Debugger &debugger = interpreter.GetDebugger(); + Debugger &debugger = m_interpreter.GetDebugger(); InputReaderSP reader_sp (new InputReader (debugger)); if (reader_sp) @@ -677,8 +674,7 @@ ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (CommandInterpr // Set a Python one-liner as the callback for the breakpoint. void -ScriptInterpreterPython::SetBreakpointCommandCallback (CommandInterpreter &interpreter, - BreakpointOptions *bp_options, +ScriptInterpreterPython::SetBreakpointCommandCallback (BreakpointOptions *bp_options, const char *oneliner) { std::auto_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData()); |