diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
commit | f73363f1dd94996356cefbf24388f561891acf0b (patch) | |
tree | e3c31248bdb36eaec5fd833490d4278162dba2a0 /source/Commands/CommandObjectCommands.cpp | |
parent | 160ee69dd7ae18978f4068116777639ea98dc951 (diff) |
Notes
Diffstat (limited to 'source/Commands/CommandObjectCommands.cpp')
-rw-r--r-- | source/Commands/CommandObjectCommands.cpp | 117 |
1 files changed, 36 insertions, 81 deletions
diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp index c9d71a65754b..3012ee4a188d 100644 --- a/source/Commands/CommandObjectCommands.cpp +++ b/source/Commands/CommandObjectCommands.cpp @@ -18,16 +18,17 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/IOHandler.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandHistory.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandObjectRegexCommand.h" #include "lldb/Interpreter/CommandReturnObject.h" +#include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Interpreter/OptionValueBoolean.h" #include "lldb/Interpreter/OptionValueString.h" #include "lldb/Interpreter/OptionValueUInt64.h" #include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Utility/Args.h" #include "lldb/Utility/StringList.h" using namespace lldb; @@ -234,20 +235,13 @@ public: return ""; } - int HandleArgumentCompletion(Args &input, int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, int max_return_elements, - bool &word_complete, - StringList &matches) override { - auto completion_str = input[cursor_index].ref; - completion_str = completion_str.take_front(cursor_char_position); - + int HandleArgumentCompletion( + CompletionRequest &request, + OptionElementVector &opt_element_vector) override { CommandCompletions::InvokeCommonCompletionCallbacks( GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, - completion_str, match_start_point, max_return_elements, nullptr, - word_complete, matches); - return matches.GetSize(); + request, nullptr); + return request.GetMatches().GetSize(); } Options *GetOptions() override { return &m_options; } @@ -330,9 +324,8 @@ protected: m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, result); } else { - // No options were set, inherit any settings from nested "command - // source" commands, - // or set to sane default settings... + // No options were set, inherit any settings from nested "command source" + // commands, or set to sane default settings... CommandInterpreterRunOptions options; m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, result); } @@ -543,9 +536,9 @@ rather than using a positional placeholder:" ~CommandObjectCommandsAlias() override = default; protected: - bool DoExecute(const char *raw_command_line, + bool DoExecute(llvm::StringRef raw_command_line, CommandReturnObject &result) override { - if (!raw_command_line || !raw_command_line[0]) { + if (raw_command_line.empty()) { result.AppendError("'command alias' requires at least two arguments"); return false; } @@ -553,42 +546,13 @@ protected: ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); m_option_group.NotifyOptionParsingStarting(&exe_ctx); - const char *remainder = nullptr; - - if (raw_command_line[0] == '-') { - // We have some options and these options MUST end with --. - const char *end_options = nullptr; - const char *s = raw_command_line; - while (s && s[0]) { - end_options = ::strstr(s, "--"); - if (end_options) { - end_options += 2; // Get past the "--" - if (::isspace(end_options[0])) { - remainder = end_options; - while (::isspace(*remainder)) - ++remainder; - break; - } - } - s = end_options; - } - - if (end_options) { - Args args( - llvm::StringRef(raw_command_line, end_options - raw_command_line)); - if (!ParseOptions(args, result)) - return false; + OptionsWithRaw args_with_suffix(raw_command_line); + const char *remainder = args_with_suffix.GetRawPart().c_str(); - Status error(m_option_group.NotifyOptionParsingFinished(&exe_ctx)); - if (error.Fail()) { - result.AppendError(error.AsCString()); - result.SetStatus(eReturnStatusFailed); - return false; - } - } - } - if (nullptr == remainder) - remainder = raw_command_line; + if (args_with_suffix.HasArgs()) + if (!ParseOptionsAndNotify(args_with_suffix.GetArgs(), result, + m_option_group, exe_ctx)) + return false; llvm::StringRef raw_command_string(remainder); Args args(raw_command_string); @@ -613,8 +577,7 @@ protected: } // Strip the new alias name off 'raw_command_string' (leave it on args, - // which gets passed to 'Execute', which - // does the stripping itself. + // which gets passed to 'Execute', which does the stripping itself. size_t pos = raw_command_string.find(alias_command); if (pos == 0) { raw_command_string = raw_command_string.substr(alias_command.size()); @@ -652,9 +615,8 @@ protected: return false; } else if (!cmd_obj->WantsRawCommandString()) { // Note that args was initialized with the original command, and has not - // been updated to this point. - // Therefore can we pass it to the version of Execute that does not - // need/expect raw input in the alias. + // been updated to this point. Therefore can we pass it to the version of + // Execute that does not need/expect raw input in the alias. return HandleAliasingNormalCommand(args, result); } else { return HandleAliasingRawCommand(alias_command, raw_command_string, @@ -1128,8 +1090,8 @@ protected: return error; } const size_t first_separator_char_pos = 1; - // use the char that follows 's' as the regex separator character - // so we can have "s/<regex>/<subst>/" or "s|<regex>|<subst>|" + // use the char that follows 's' as the regex separator character so we can + // have "s/<regex>/<subst>/" or "s|<regex>|<subst>|" const char separator_char = regex_sed[first_separator_char_pos]; const size_t second_separator_char_pos = regex_sed.find(separator_char, first_separator_char_pos + 1); @@ -1158,8 +1120,7 @@ protected: } if (third_separator_char_pos != regex_sed_size - 1) { - // Make sure that everything that follows the last regex - // separator char + // Make sure that everything that follows the last regex separator char if (regex_sed.find_first_not_of("\t\n\v\f\r ", third_separator_char_pos + 1) != std::string::npos) { @@ -1307,7 +1268,7 @@ public: } protected: - bool DoExecute(const char *raw_command_line, + bool DoExecute(llvm::StringRef raw_command_line, CommandReturnObject &result) override { ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); @@ -1396,7 +1357,7 @@ public: } protected: - bool DoExecute(const char *raw_command_line, + bool DoExecute(llvm::StringRef raw_command_line, CommandReturnObject &result) override { ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); @@ -1462,20 +1423,13 @@ public: ~CommandObjectCommandsScriptImport() override = default; - int HandleArgumentCompletion(Args &input, int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, int max_return_elements, - bool &word_complete, - StringList &matches) override { - llvm::StringRef completion_str = input[cursor_index].ref; - completion_str = completion_str.take_front(cursor_char_position); - + int HandleArgumentCompletion( + CompletionRequest &request, + OptionElementVector &opt_element_vector) override { CommandCompletions::InvokeCommonCompletionCallbacks( GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, - completion_str, match_start_point, max_return_elements, nullptr, - word_complete, matches); - return matches.GetSize(); + request, nullptr); + return request.GetMatches().GetSize(); } Options *GetOptions() override { return &m_options; } @@ -1540,10 +1494,11 @@ protected: // FIXME: this is necessary because CommandObject::CheckRequirements() // assumes that commands won't ever be recursively invoked, but it's // actually possible to craft a Python script that does other "command - // script imports" in __lldb_init_module the real fix is to have recursive - // commands possible with a CommandInvocation object separate from the - // CommandObject itself, so that recursive command invocations won't stomp - // on each other (wrt to execution contents, options, and more) + // script imports" in __lldb_init_module the real fix is to have + // recursive commands possible with a CommandInvocation object separate + // from the CommandObject itself, so that recursive command invocations + // won't stomp on each other (wrt to execution contents, options, and + // more) m_exe_ctx.Clear(); if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule( entry.c_str(), m_options.m_allow_reload, init_session, error)) { @@ -1639,7 +1594,7 @@ protected: break; case 's': m_synchronicity = - (ScriptedCommandSynchronicity)Args::StringToOptionEnum( + (ScriptedCommandSynchronicity)OptionArgParser::ToOptionEnum( option_arg, GetDefinitions()[option_idx].enum_values, 0, error); if (!error.Success()) error.SetErrorStringWithFormat( |