diff options
Diffstat (limited to 'source/Interpreter/CommandObject.cpp')
| -rw-r--r-- | source/Interpreter/CommandObject.cpp | 265 | 
1 files changed, 115 insertions, 150 deletions
diff --git a/source/Interpreter/CommandObject.cpp b/source/Interpreter/CommandObject.cpp index 616d3e38acbb..75e42925406b 100644 --- a/source/Interpreter/CommandObject.cpp +++ b/source/Interpreter/CommandObject.cpp @@ -53,7 +53,6 @@ CommandObject::CommandObject      m_cmd_help_short (),      m_cmd_help_long (),      m_cmd_syntax (), -    m_is_alias (false),      m_flags (flags),      m_arguments(),      m_deprecated_command_override_callback (nullptr), @@ -89,12 +88,12 @@ CommandObject::GetSyntax ()      {          StreamString syntax_str;          syntax_str.Printf ("%s", GetCommandName()); -        if (GetOptions() != nullptr) +        if (!IsDashDashCommand() && GetOptions() != nullptr)              syntax_str.Printf (" <cmd-options>");          if (m_arguments.size() > 0)          {              syntax_str.Printf (" "); -            if (WantsRawCommandString() && GetOptions() && GetOptions()->NumCommandOptions()) +            if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() && GetOptions()->NumCommandOptions())                  syntax_str.Printf("-- ");              GetFormattedCommandArguments (syntax_str);          } @@ -119,25 +118,19 @@ CommandObject::SetCommandName (const char *name)  void  CommandObject::SetHelp (const char *cstr)  { -    m_cmd_help_short = cstr; -} - -void -CommandObject::SetHelp (std::string str) -{ -    m_cmd_help_short = str; +    if (cstr) +        m_cmd_help_short = cstr; +    else +        m_cmd_help_short.assign("");  }  void  CommandObject::SetHelpLong (const char *cstr)  { -    m_cmd_help_long = cstr; -} - -void -CommandObject::SetHelpLong (std::string str) -{ -    m_cmd_help_long = str; +    if (cstr) +        m_cmd_help_long = cstr; +    else +        m_cmd_help_long.assign("");  }  void @@ -283,7 +276,7 @@ CommandObject::CheckRequirements (CommandReturnObject &result)          {              Target *target = m_exe_ctx.GetTargetPtr();              if (target) -                m_api_locker.Lock (target->GetAPIMutex()); +                m_api_locker = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());          }      } @@ -343,46 +336,8 @@ void  CommandObject::Cleanup ()  {      m_exe_ctx.Clear(); -    m_api_locker.Unlock(); -} - - -class CommandDictCommandPartialMatch -{ -    public: -        CommandDictCommandPartialMatch (const char *match_str) -        { -            m_match_str = match_str; -        } -        bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const -        { -            // A NULL or empty string matches everything. -            if (m_match_str == nullptr || *m_match_str == '\0') -                return true; - -            return map_element.first.find (m_match_str, 0) == 0; -        } - -    private: -        const char *m_match_str; -}; - -int -CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str, -                                              StringList &matches) -{ -    int number_added = 0; -    CommandDictCommandPartialMatch matcher(cmd_str); - -    CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher); - -    while (matching_cmds != in_map.end()) -    { -        ++number_added; -        matches.AppendString((*matching_cmds).first.c_str()); -        matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);; -    } -    return number_added; +    if (m_api_locker.owns_lock()) +        m_api_locker.unlock();  }  int @@ -457,7 +412,11 @@ CommandObject::HandleCompletion  }  bool -CommandObject::HelpTextContainsWord (const char *search_word) +CommandObject::HelpTextContainsWord (const char *search_word, +                                     bool search_short_help, +                                     bool search_long_help, +                                     bool search_syntax, +                                     bool search_options)  {      std::string options_usage_help; @@ -467,14 +426,15 @@ CommandObject::HelpTextContainsWord (const char *search_word)      const char *long_help = GetHelpLong();      const char *syntax_help = GetSyntax(); -    if (short_help && strcasestr (short_help, search_word)) +    if (search_short_help && short_help && strcasestr (short_help, search_word))          found_word = true; -    else if (long_help && strcasestr (long_help, search_word)) +    else if (search_long_help && long_help && strcasestr (long_help, search_word))          found_word = true; -    else if (syntax_help && strcasestr (syntax_help, search_word)) +    else if (search_syntax && syntax_help && strcasestr (syntax_help, search_word))          found_word = true;      if (!found_word +        && search_options          && GetOptions() != nullptr)      {          StreamString usage_help; @@ -727,46 +687,47 @@ RegisterNameHelpTextCallback ()  static const char *  BreakpointIDHelpTextCallback ()  { -    return "Breakpoint ID's consist major and minor numbers;  the major number " -    "corresponds to the single entity that was created with a 'breakpoint set' " -    "command; the minor numbers correspond to all the locations that were actually " -    "found/set based on the major breakpoint.  A full breakpoint ID might look like " -    "3.14, meaning the 14th location set for the 3rd breakpoint.  You can specify " -    "all the locations of a breakpoint by just indicating the major breakpoint " -    "number. A valid breakpoint id consists either of just the major id number, " -    "or the major number, a dot, and the location number (e.g. 3 or 3.2 could " -    "both be valid breakpoint ids)."; +    return "Breakpoints are identified using major and minor numbers; the major " +           "number corresponds to the single entity that was created with a 'breakpoint " +           "set' command; the minor numbers correspond to all the locations that were " +           "actually found/set based on the major breakpoint.  A full breakpoint ID might " +           "look like 3.14, meaning the 14th location set for the 3rd breakpoint.  You " +           "can specify all the locations of a breakpoint by just indicating the major " +           "breakpoint number. A valid breakpoint ID consists either of just the major " +           "number, or the major number followed by a dot and the location number (e.g. " +           "3 or 3.2 could both be valid breakpoint IDs.)";  }  static const char *  BreakpointIDRangeHelpTextCallback ()  { -    return "A 'breakpoint id list' is a manner of specifying multiple breakpoints. " -    "This can be done  through several mechanisms.  The easiest way is to just " -    "enter a space-separated list of breakpoint ids.  To specify all the " -    "breakpoint locations under a major breakpoint, you can use the major " -    "breakpoint number followed by '.*', eg. '5.*' means all the locations under " -    "breakpoint 5.  You can also indicate a range of breakpoints by using " -    "<start-bp-id> - <end-bp-id>.  The start-bp-id and end-bp-id for a range can " -    "be any valid breakpoint ids.  It is not legal, however, to specify a range " -    "using specific locations that cross major breakpoint numbers.  I.e. 3.2 - 3.7" -    " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; +    return "A 'breakpoint ID list' is a manner of specifying multiple breakpoints. " +           "This can be done through several mechanisms.  The easiest way is to just " +           "enter a space-separated list of breakpoint IDs.  To specify all the " +           "breakpoint locations under a major breakpoint, you can use the major " +           "breakpoint number followed by '.*', eg. '5.*' means all the locations under " +           "breakpoint 5.  You can also indicate a range of breakpoints by using " +           "<start-bp-id> - <end-bp-id>.  The start-bp-id and end-bp-id for a range can " +           "be any valid breakpoint IDs.  It is not legal, however, to specify a range " +           "using specific locations that cross major breakpoint numbers.  I.e. 3.2 - 3.7" +           " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";  }  static const char *  BreakpointNameHelpTextCallback ()  {      return "A name that can be added to a breakpoint when it is created, or later " -    "on with the \"breakpoint name add\" command.  " -    "Breakpoint names can be used to specify breakpoints in all the places breakpoint ID's " -    "and breakpoint ID ranges can be used.  As such they provide a convenient way to group breakpoints, " -    "and to operate on breakpoints you create without having to track the breakpoint number.  " -    "Note, the attributes you set when using a breakpoint name in a breakpoint command don't " -    "adhere to the name, but instead are set individually on all the breakpoints currently tagged with that name.  Future breakpoints " -    "tagged with that name will not pick up the attributes previously given using that name.  " -    "In order to distinguish breakpoint names from breakpoint ID's and ranges, " -    "names must start with a letter from a-z or A-Z and cannot contain spaces, \".\" or \"-\".  " -    "Also, breakpoint names can only be applied to breakpoints, not to breakpoint locations."; +           "on with the \"breakpoint name add\" command.  " +           "Breakpoint names can be used to specify breakpoints in all the places breakpoint IDs " +           "and breakpoint ID ranges can be used.  As such they provide a convenient way to group breakpoints, " +           "and to operate on breakpoints you create without having to track the breakpoint number.  " +           "Note, the attributes you set when using a breakpoint name in a breakpoint command don't " +           "adhere to the name, but instead are set individually on all the breakpoints currently tagged with that " +           "name.  Future breakpoints " +           "tagged with that name will not pick up the attributes previously given using that name.  " +           "In order to distinguish breakpoint names from breakpoint IDs and ranges, " +           "names must start with a letter from a-z or A-Z and cannot contain spaces, \".\" or \"-\".  " +           "Also, breakpoint names can only be applied to breakpoints, not to breakpoint locations.";  }  static const char * @@ -956,68 +917,46 @@ void  CommandObject::GenerateHelpText (Stream &output_strm)  {      CommandInterpreter& interpreter = GetCommandInterpreter(); -    if (GetOptions() != nullptr) +    if (WantsRawCommandString()) +    { +        std::string help_text(GetHelp()); +        help_text.append("  Expects 'raw' input (see 'help raw-input'.)"); +        interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(), 1); +    } +    else +        interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1); +    output_strm.Printf("\nSyntax: %s\n", GetSyntax()); +    Options *options = GetOptions(); +    if (options != nullptr) +    { +        options->GenerateOptionUsage(output_strm, this); +    } +    const char *long_help = GetHelpLong(); +    if ((long_help != nullptr) && (strlen(long_help) > 0)) +    { +        FormatLongHelpText(output_strm, long_help); +    } +    if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0)      { -        if (WantsRawCommandString()) -        { -            std::string help_text (GetHelp()); -            help_text.append ("  This command takes 'raw' input (no need to quote stuff)."); -            interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1); -        } -        else -            interpreter.OutputFormattedHelpText (output_strm, "", "", GetHelp(), 1); -        output_strm.Printf ("\nSyntax: %s\n", GetSyntax()); -        GetOptions()->GenerateOptionUsage (output_strm, this); -        const char *long_help = GetHelpLong(); -        if ((long_help != nullptr) -            && (strlen (long_help) > 0)) -            FormatLongHelpText (output_strm, long_help);          if (WantsRawCommandString() && !WantsCompletion())          {              // Emit the message about using ' -- ' between the end of the command options and the raw input              // conditionally, i.e., only if the command object does not want completion. -            interpreter.OutputFormattedHelpText (output_strm, "", "", -                                                 "\nIMPORTANT NOTE:  Because this command takes 'raw' input, if you use any command options" -                                                 " you must use ' -- ' between the end of the command options and the beginning of the raw input.", 1); +            interpreter.OutputFormattedHelpText( +                output_strm, "", "", +                "\nImportant Note: Because this command takes 'raw' input, if you use any command options" +                " you must use ' -- ' between the end of the command options and the beginning of the raw input.", +                1);          } -        else if (GetNumArgumentEntries() > 0 -                 && GetOptions() -                 && GetOptions()->NumCommandOptions() > 0) +        else if (GetNumArgumentEntries() > 0)          {              // Also emit a warning about using "--" in case you are using a command that takes options and arguments. -            interpreter.OutputFormattedHelpText (output_strm, "", "", -                                                 "\nThis command takes options and free-form arguments.  If your arguments resemble" -                                                 " option specifiers (i.e., they start with a - or --), you must use ' -- ' between" -                                                 " the end of the command options and the beginning of the arguments.", 1); -        } -    } -    else if (IsMultiwordObject()) -    { -        if (WantsRawCommandString()) -        { -            std::string help_text (GetHelp()); -            help_text.append ("  This command takes 'raw' input (no need to quote stuff)."); -            interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1); -        } -        else -            interpreter.OutputFormattedHelpText (output_strm, "", "", GetHelp(), 1); -        GenerateHelpText (output_strm); -    } -    else -    { -        const char *long_help = GetHelpLong(); -        if ((long_help != nullptr) -            && (strlen (long_help) > 0)) -            FormatLongHelpText (output_strm, long_help); -        else if (WantsRawCommandString()) -        { -            std::string help_text (GetHelp()); -            help_text.append ("  This command takes 'raw' input (no need to quote stuff)."); -            interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1); +            interpreter.OutputFormattedHelpText( +                output_strm, "", "", "\nThis command takes options and free-form arguments.  If your arguments resemble" +                                     " option specifiers (i.e., they start with a - or --), you must use ' -- ' between" +                                     " the end of the command options and the beginning of the arguments.", +                1);          } -        else -            interpreter.OutputFormattedHelpText (output_strm, "", "", GetHelp(), 1); -        output_strm.Printf ("\nSyntax: %s\n", GetSyntax());      }  } @@ -1067,6 +1006,31 @@ CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy)      return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);  } +Thread * +CommandObject::GetDefaultThread() +{ +    Thread *thread_to_use = m_exe_ctx.GetThreadPtr(); +    if (thread_to_use) +        return thread_to_use; +     +    Process *process = m_exe_ctx.GetProcessPtr(); +    if (!process) +    { +        Target *target = m_exe_ctx.GetTargetPtr(); +        if (!target) +        { +            target = m_interpreter.GetDebugger().GetSelectedTarget().get(); +        } +        if (target) +            process = target->GetProcessSP().get(); +    } + +    if (process) +        return process->GetThreadList().GetSelectedThread().get(); +    else +        return nullptr; +} +  bool  CommandObjectParsed::Execute (const char *args_string, CommandReturnObject &result)  { @@ -1138,9 +1102,8 @@ const char *arch_helper()      return g_archs_help.GetData();  } -CommandObject::ArgumentTableEntry -CommandObject::g_arguments_data[] = -{ +CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { +    // clang-format off      { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." },      { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." },      { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." }, @@ -1170,7 +1133,7 @@ CommandObject::g_arguments_data[] =      { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr },      { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" },      { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." }, -    { eArgTypeLanguage, "language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr }, +    { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr },      { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." },      { eArgTypeLogCategory, "log-category", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." },      { eArgTypeLogChannel, "log-channel", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." }, @@ -1198,7 +1161,7 @@ CommandObject::g_arguments_data[] =      { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },      { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." },      { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands.  Currently only Python is valid." }, -    { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "The word for which you wish to search for information about." }, +    { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." },      { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." },      { eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a settings variable that is an array (try 'settings list' to see all the possible settings variables and their types)." },      { eArgTypeSettingKey, "setting-key", CommandCompletions::eNoCompletion, { nullptr, false }, "A key into a settings variables that is a dictionary (try 'settings list' to see all the possible settings variables and their types)." }, @@ -1223,7 +1186,9 @@ CommandObject::g_arguments_data[] =      { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, { nullptr, false }, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." },      { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." },      { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." }, -    { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." } +    { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." }, +    { eArgRawInput, "raw-input", CommandCompletions::eNoCompletion, { nullptr, false }, "Free-form text passed to a command without prior interpretation, allowing spaces without requiring quotes.  To pass arguments and free form text put two dashes ' -- ' between the last argument and any raw input." } +    // clang-format on  };  const CommandObject::ArgumentTableEntry*  | 
