diff options
Diffstat (limited to 'source/Commands/CommandObjectCommands.cpp')
| -rw-r--r-- | source/Commands/CommandObjectCommands.cpp | 238 | 
1 files changed, 151 insertions, 87 deletions
| diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp index 7d9bb7dad8fdd..f98eac055f242 100644 --- a/source/Commands/CommandObjectCommands.cpp +++ b/source/Commands/CommandObjectCommands.cpp @@ -366,7 +366,7 @@ protected:          // Instance variables to hold the values for command options.          OptionValueBoolean m_stop_on_error; -	    OptionValueBoolean m_silent_run; +        OptionValueBoolean m_silent_run;          OptionValueBoolean m_stop_on_continue;      }; @@ -387,14 +387,15 @@ protected:                  m_options.m_stop_on_continue.OptionWasSet())              {                  // Use user set settings -                LazyBool print_command = m_options.m_silent_run.GetCurrentValue() ? eLazyBoolNo : eLazyBoolYes; +                CommandInterpreterRunOptions options; +                options.SetStopOnContinue(m_options.m_stop_on_continue.GetCurrentValue()); +                options.SetStopOnError (m_options.m_stop_on_error.GetCurrentValue()); +                options.SetEchoCommands (!m_options.m_silent_run.GetCurrentValue()); +                options.SetPrintResults (!m_options.m_silent_run.GetCurrentValue()); +                  m_interpreter.HandleCommandsFromFile (cmd_file,                                                        exe_ctx, -                                                      m_options.m_stop_on_continue.GetCurrentValue() ? eLazyBoolYes : eLazyBoolNo, // Stop on continue -                                                      m_options.m_stop_on_error.GetCurrentValue() ? eLazyBoolYes : eLazyBoolNo, // Stop on error -                                                      print_command,        // Echo command -                                                      print_command,        // Print command output -                                                      eLazyBoolCalculate,   // Add to history +                                                      options,                                                        result);              } @@ -402,13 +403,10 @@ protected:              {                  // 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, -                                                      eLazyBoolCalculate, // Stop on continue -                                                      eLazyBoolCalculate, // Stop on error -                                                      eLazyBoolCalculate, // Echo command -                                                      eLazyBoolCalculate, // Print command output -                                                      eLazyBoolCalculate, // Add to history +                                                      options,                                                        result);              } @@ -830,8 +828,16 @@ protected:              {                  if (m_interpreter.CommandExists (command_name))                  { -                    result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n", -                                                  command_name); +                    if (cmd_obj->IsRemovable()) +                    { +                        result.AppendErrorWithFormat ("'%s' is not an alias, it is a debugger command which can be removed using the 'command delete' command.\n", +                                                      command_name); +                    } +                    else +                    { +                        result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n", +                                                      command_name); +                    }                      result.SetStatus (eReturnStatusFailed);                  }                  else @@ -868,6 +874,77 @@ protected:      }  }; +#pragma mark CommandObjectCommandsDelete +//------------------------------------------------------------------------- +// CommandObjectCommandsDelete +//------------------------------------------------------------------------- + +class CommandObjectCommandsDelete : public CommandObjectParsed +{ +public: +    CommandObjectCommandsDelete (CommandInterpreter &interpreter) : +    CommandObjectParsed (interpreter, +                         "command delete", +                         "Allow the user to delete user-defined regular expression, python or multi-word commands.", +                         NULL) +    { +        CommandArgumentEntry arg; +        CommandArgumentData alias_arg; + +        // Define the first (and only) variant of this arg. +        alias_arg.arg_type = eArgTypeCommandName; +        alias_arg.arg_repetition = eArgRepeatPlain; + +        // There is only one variant this argument could be; put it into the argument entry. +        arg.push_back (alias_arg); + +        // Push the data for the first argument into the m_arguments vector. +        m_arguments.push_back (arg); +    } + +    ~CommandObjectCommandsDelete() +    { +    } + +protected: +    bool +    DoExecute (Args& args, CommandReturnObject &result) +    { +        CommandObject::CommandMap::iterator pos; + +        if (args.GetArgumentCount() != 0) +        { +            const char *command_name = args.GetArgumentAtIndex(0); +            if (m_interpreter.CommandExists (command_name)) +            { +                if (m_interpreter.RemoveCommand (command_name)) +                { +                    result.SetStatus (eReturnStatusSuccessFinishNoResult); +                } +                else +                { +                    result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n", +                                                  command_name); +                    result.SetStatus (eReturnStatusFailed); +                } +            } +            else +            { +                result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n", +                                              command_name); +                result.SetStatus (eReturnStatusFailed); +            } +        } +        else +        { +            result.AppendErrorWithFormat ("must call '%s' with one or more valid user defined regular expression, python or multi-word command names", GetCommandName ()); +            result.SetStatus (eReturnStatusFailed); +        } + +        return result.Succeeded(); +    } +}; +  //-------------------------------------------------------------------------  // CommandObjectCommandsAddRegex  //------------------------------------------------------------------------- @@ -875,7 +952,7 @@ protected:  class CommandObjectCommandsAddRegex :      public CommandObjectParsed, -    public IOHandlerDelegate +    public IOHandlerDelegateMultiline  {  public:      CommandObjectCommandsAddRegex (CommandInterpreter &interpreter) : @@ -883,7 +960,7 @@ public:                         "command regex",                         "Allow the user to create a regular expression command.",                         "command regex <cmd-name> [s/<regex>/<subst>/ ...]"), -        IOHandlerDelegate(IOHandlerDelegate::Completion::LLDBCommand), +        IOHandlerDelegateMultiline ("", IOHandlerDelegate::Completion::LLDBCommand),          m_options (interpreter)      {          SetHelpLong( @@ -920,8 +997,8 @@ public:  protected: -    virtual void -    IOHandlerActivated (IOHandler &io_handler) +    void +    IOHandlerActivated (IOHandler &io_handler) override      {          StreamFileSP output_sp(io_handler.GetOutputStreamFile());          if (output_sp) @@ -931,8 +1008,8 @@ protected:          }      } -    virtual void -    IOHandlerInputComplete (IOHandler &io_handler, std::string &data) +    void +    IOHandlerInputComplete (IOHandler &io_handler, std::string &data) override      {          io_handler.SetIsDone(true);          if (m_regex_cmd_ap.get()) @@ -944,7 +1021,6 @@ protected:                  bool check_only = false;                  for (size_t i=0; i<num_lines; ++i)                  { -                    printf ("regex[%zu] = %s\n", i, lines[i].c_str());                      llvm::StringRef bytes_strref (lines[i]);                      Error error = AppendRegexSubstitution (bytes_strref, check_only);                      if (error.Fail()) @@ -964,54 +1040,9 @@ protected:              }          }      } -     -    virtual LineStatus -    IOHandlerLinesUpdated (IOHandler &io_handler, -                           StringList &lines, -                           uint32_t line_idx, -                           Error &error) -    { -        if (line_idx == UINT32_MAX) -        { -            // Return true to indicate we are done getting lines (this -            // is a "fake" line - the real terminating blank line was -            // removed during a previous call with the code below) -            error.Clear(); -            return LineStatus::Done; -        } -        else -        { -            const size_t num_lines = lines.GetSize(); -            if (line_idx + 1 == num_lines) -            { -                // The last line was edited, if this line is empty, then we are done -                // getting our multiple lines. -                if (lines[line_idx].empty()) -                { -                    // Remove the last empty line from "lines" so it doesn't appear -                    // in our final expression and return true to indicate we are done -                    // getting lines -                    lines.PopBack(); -                    return LineStatus::Done; -                } -            } -            // Check the current line to make sure it is formatted correctly -            bool check_only = true; -            llvm::StringRef regex_sed(lines[line_idx]); -            error = AppendRegexSubstitution (regex_sed, check_only); -            if (error.Fail()) -            { -                return LineStatus::Error; -            } -            else -            { -                return LineStatus::Success; -            } -        } -    }      bool -    DoExecute (Args& command, CommandReturnObject &result) +    DoExecute (Args& command, CommandReturnObject &result) override      {          const size_t argc = command.GetArgumentCount();          if (argc == 0) @@ -1027,16 +1058,22 @@ protected:                                                                   name,                                                                    m_options.GetHelp (),                                                                   m_options.GetSyntax (), -                                                                 10)); +                                                                 10, +                                                                 0, +                                                                 true));              if (argc == 1)              {                  Debugger &debugger = m_interpreter.GetDebugger(); +                bool color_prompt = debugger.GetUseColor();                  const bool multiple_lines = true; // Get multiple lines                  IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger, +                                                                  IOHandler::Type::Other,                                                                    "lldb-regex", // Name of input reader for history -                                                                  "\033[K> ",   // Prompt and clear line +                                                                  "> ",         // Prompt +                                                                  NULL,         // Continuation prompt                                                                    multiple_lines, +                                                                  color_prompt,                                                                    0,            // Don't show line numbers                                                                    *this)); @@ -1110,21 +1147,25 @@ protected:          if (second_separator_char_pos == std::string::npos)          { -            error.SetErrorStringWithFormat("missing second '%c' separator char after '%.*s'",  +            error.SetErrorStringWithFormat("missing second '%c' separator char after '%.*s' in '%.*s'",                                             separator_char,                                              (int)(regex_sed.size() - first_separator_char_pos - 1), -                                           regex_sed.data() + (first_separator_char_pos + 1)); -            return error;             +                                           regex_sed.data() + (first_separator_char_pos + 1), +                                           (int)regex_sed.size(), +                                           regex_sed.data()); +            return error;          }          const size_t third_separator_char_pos = regex_sed.find (separator_char, second_separator_char_pos + 1);          if (third_separator_char_pos == std::string::npos)          { -            error.SetErrorStringWithFormat("missing third '%c' separator char after '%.*s'",  +            error.SetErrorStringWithFormat("missing third '%c' separator char after '%.*s' in '%.*s'",                                             separator_char,                                              (int)(regex_sed.size() - second_separator_char_pos - 1), -                                           regex_sed.data() + (second_separator_char_pos + 1)); +                                           regex_sed.data() + (second_separator_char_pos + 1), +                                           (int)regex_sed.size(), +                                           regex_sed.data());              return error;                      } @@ -1262,8 +1303,8 @@ private:           std::string m_syntax;       }; -     virtual Options * -     GetOptions () +     Options * +     GetOptions () override       {           return &m_options;       } @@ -1292,15 +1333,24 @@ public:      CommandObjectPythonFunction (CommandInterpreter &interpreter,                                   std::string name,                                   std::string funct, +                                 std::string help,                                   ScriptedCommandSynchronicity synch) :          CommandObjectRaw (interpreter,                            name.c_str(), -                          (std::string("Run Python function ") + funct).c_str(), +                          NULL,                            NULL),          m_function_name(funct),          m_synchro(synch),          m_fetched_help_long(false)      { +        if (!help.empty()) +            SetHelp(help.c_str()); +        else +        { +            StreamString stream; +            stream.Printf("For more information run 'help %s'",name.c_str()); +            SetHelp(stream.GetData()); +        }      }      virtual @@ -1357,7 +1407,8 @@ protected:                                                           raw_command_line,                                                           m_synchro,                                                           result, -                                                         error) == false) +                                                         error, +                                                         m_exe_ctx) == false)          {              result.AppendError(error.AsCString());              result.SetStatus(eReturnStatusFailed); @@ -1617,7 +1668,12 @@ protected:              switch (short_option)              {                  case 'f': -                    m_funct_name = std::string(option_arg); +                    if (option_arg) +                        m_funct_name.assign(option_arg); +                    break; +                case 'h': +                    if (option_arg) +                        m_short_help.assign(option_arg);                      break;                  case 's':                      m_synchronicity = (ScriptedCommandSynchronicity) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); @@ -1635,7 +1691,8 @@ protected:          void          OptionParsingStarting ()          { -            m_funct_name = ""; +            m_funct_name.clear(); +            m_short_help.clear();              m_synchronicity = eScriptedCommandSynchronicitySynchronous;          } @@ -1652,6 +1709,7 @@ protected:          // Instance variables to hold the values for command options.          std::string m_funct_name; +        std::string m_short_help;          ScriptedCommandSynchronicity m_synchronicity;      }; @@ -1695,6 +1753,7 @@ protected:                          CommandObjectSP command_obj_sp(new CommandObjectPythonFunction (m_interpreter,                                                                                          m_cmd_name,                                                                                          funct_name_str.c_str(), +                                                                                        m_short_help,                                                                                          m_synchronicity));                          if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp, true)) @@ -1748,8 +1807,9 @@ protected:              return false;          } -        // Store the command name and synchronicity in case we get multi-line input +        // Store the options in case we get multi-line input          m_cmd_name = command.GetArgumentAtIndex(0); +        m_short_help.assign(m_options.m_short_help);          m_synchronicity = m_options.m_synchronicity;          if (m_options.m_funct_name.empty()) @@ -1764,6 +1824,7 @@ protected:              CommandObjectSP new_cmd(new CommandObjectPythonFunction(m_interpreter,                                                                      m_cmd_name,                                                                      m_options.m_funct_name, +                                                                    m_options.m_short_help,                                                                      m_synchronicity));              if (m_interpreter.AddUserCommand(m_cmd_name, new_cmd, true))              { @@ -1782,6 +1843,7 @@ protected:      CommandOptions m_options;      std::string m_cmd_name; +    std::string m_short_help;      ScriptedCommandSynchronicity m_synchronicity;  }; @@ -1797,6 +1859,7 @@ OptionDefinition  CommandObjectCommandsScriptAdd::CommandOptions::g_option_table[] =  {      { LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonFunction,        "Name of the Python function to bind to this command name."}, +    { LLDB_OPT_SET_1, false, "help"  , 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeHelpText, "The help text to display for this command."},      { LLDB_OPT_SET_1, false, "synchronicity", 's', OptionParser::eRequiredArgument, NULL, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity,        "Set the synchronicity of this command's executions with regard to LLDB event system."},      { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }  }; @@ -1949,11 +2012,11 @@ public:                              "A set of commands for managing or customizing script commands.",                              "command script <subcommand> [<subcommand-options>]")      { -        LoadSubCommand ("add",  CommandObjectSP (new CommandObjectCommandsScriptAdd (interpreter))); -        LoadSubCommand ("delete",   CommandObjectSP (new CommandObjectCommandsScriptDelete (interpreter))); -        LoadSubCommand ("clear", CommandObjectSP (new CommandObjectCommandsScriptClear (interpreter))); +        LoadSubCommand ("add",    CommandObjectSP (new CommandObjectCommandsScriptAdd (interpreter))); +        LoadSubCommand ("delete", CommandObjectSP (new CommandObjectCommandsScriptDelete (interpreter))); +        LoadSubCommand ("clear",  CommandObjectSP (new CommandObjectCommandsScriptClear (interpreter)));          LoadSubCommand ("list",   CommandObjectSP (new CommandObjectCommandsScriptList (interpreter))); -        LoadSubCommand ("import",   CommandObjectSP (new CommandObjectCommandsScriptImport (interpreter))); +        LoadSubCommand ("import", CommandObjectSP (new CommandObjectCommandsScriptImport (interpreter)));      }      ~CommandObjectMultiwordCommandsScript () @@ -1978,9 +2041,10 @@ CommandObjectMultiwordCommands::CommandObjectMultiwordCommands (CommandInterpret      LoadSubCommand ("source",  CommandObjectSP (new CommandObjectCommandsSource (interpreter)));      LoadSubCommand ("alias",   CommandObjectSP (new CommandObjectCommandsAlias (interpreter)));      LoadSubCommand ("unalias", CommandObjectSP (new CommandObjectCommandsUnalias (interpreter))); +    LoadSubCommand ("delete",  CommandObjectSP (new CommandObjectCommandsDelete (interpreter)));      LoadSubCommand ("regex",   CommandObjectSP (new CommandObjectCommandsAddRegex (interpreter))); -    LoadSubCommand ("history",   CommandObjectSP (new CommandObjectCommandsHistory (interpreter))); -    LoadSubCommand ("script",   CommandObjectSP (new CommandObjectMultiwordCommandsScript (interpreter))); +    LoadSubCommand ("history", CommandObjectSP (new CommandObjectCommandsHistory (interpreter))); +    LoadSubCommand ("script",  CommandObjectSP (new CommandObjectMultiwordCommandsScript (interpreter)));  }  CommandObjectMultiwordCommands::~CommandObjectMultiwordCommands () | 
