kastiglione created this revision. kastiglione added reviewers: jingham, aprantl, augusto2112. kastiglione requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Fixes incomplete command names in `apropos` results. The full command names given by `apropos` have come from command name string literals given to `CommandObject` constructors. For most commands, this has been accurate, but some commands have incorrect strings. This results in `apropos` output that doesn't tell the user the full command name they might want learn more about. These strings can be fixed. There's a seperate issue that can't be fixed as easily: plugin commands. With the way they're implemented, plugin commands have to exclude the root command from their command name string. To illustrate, the `language objc` subcommand has to set its command name string to "objc", which results in apropos printing results as `objc ...` instead of `language objc ...`. To fix both of these issues, this commit changes `FindCommandsForApropos` to derive the fully qualified command name using the keys of subcommand maps. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116491 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp =================================================================== --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -2839,12 +2839,10 @@ void CommandInterpreter::FindCommandsForApropos( llvm::StringRef search_word, StringList &commands_found, - StringList &commands_help, CommandObject::CommandMap &command_map) { - CommandObject::CommandMap::const_iterator pos; - - for (pos = command_map.begin(); pos != command_map.end(); ++pos) { - llvm::StringRef command_name = pos->first; - CommandObject *cmd_obj = pos->second.get(); + StringList &commands_help, const CommandObject::CommandMap &command_map) { + for (const auto &pair : command_map) { + llvm::StringRef command_name = pair.first; + CommandObject *cmd_obj = pair.second.get(); const bool search_short_help = true; const bool search_long_help = false; @@ -2854,14 +2852,18 @@ cmd_obj->HelpTextContainsWord(search_word, search_short_help, search_long_help, search_syntax, search_options)) { - commands_found.AppendString(cmd_obj->GetCommandName()); + commands_found.AppendString(command_name); commands_help.AppendString(cmd_obj->GetHelp()); } - if (cmd_obj->IsMultiwordObject()) { - CommandObjectMultiword *cmd_multiword = cmd_obj->GetAsMultiwordCommand(); - FindCommandsForApropos(search_word, commands_found, commands_help, - cmd_multiword->GetSubcommandDictionary()); + if (auto *multiword_cmd = cmd_obj->GetAsMultiwordCommand()) { + StringList subcommands_found; + FindCommandsForApropos(search_word, subcommands_found, commands_help, + multiword_cmd->GetSubcommandDictionary()); + for (const auto &subcommand_name : subcommands_found) { + auto qualified_name = (command_name + " " + subcommand_name).str(); + commands_found.AppendString(qualified_name); + } } } } Index: lldb/include/lldb/Interpreter/CommandInterpreter.h =================================================================== --- lldb/include/lldb/Interpreter/CommandInterpreter.h +++ lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -649,7 +649,7 @@ void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found, StringList &commands_help, - CommandObject::CommandMap &command_map); + const CommandObject::CommandMap &command_map); // An interruptible wrapper around the stream output void PrintCommandOutput(Stream &stream, llvm::StringRef str);
Index: lldb/source/Interpreter/CommandInterpreter.cpp =================================================================== --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -2839,12 +2839,10 @@ void CommandInterpreter::FindCommandsForApropos( llvm::StringRef search_word, StringList &commands_found, - StringList &commands_help, CommandObject::CommandMap &command_map) { - CommandObject::CommandMap::const_iterator pos; - - for (pos = command_map.begin(); pos != command_map.end(); ++pos) { - llvm::StringRef command_name = pos->first; - CommandObject *cmd_obj = pos->second.get(); + StringList &commands_help, const CommandObject::CommandMap &command_map) { + for (const auto &pair : command_map) { + llvm::StringRef command_name = pair.first; + CommandObject *cmd_obj = pair.second.get(); const bool search_short_help = true; const bool search_long_help = false; @@ -2854,14 +2852,18 @@ cmd_obj->HelpTextContainsWord(search_word, search_short_help, search_long_help, search_syntax, search_options)) { - commands_found.AppendString(cmd_obj->GetCommandName()); + commands_found.AppendString(command_name); commands_help.AppendString(cmd_obj->GetHelp()); } - if (cmd_obj->IsMultiwordObject()) { - CommandObjectMultiword *cmd_multiword = cmd_obj->GetAsMultiwordCommand(); - FindCommandsForApropos(search_word, commands_found, commands_help, - cmd_multiword->GetSubcommandDictionary()); + if (auto *multiword_cmd = cmd_obj->GetAsMultiwordCommand()) { + StringList subcommands_found; + FindCommandsForApropos(search_word, subcommands_found, commands_help, + multiword_cmd->GetSubcommandDictionary()); + for (const auto &subcommand_name : subcommands_found) { + auto qualified_name = (command_name + " " + subcommand_name).str(); + commands_found.AppendString(qualified_name); + } } } } Index: lldb/include/lldb/Interpreter/CommandInterpreter.h =================================================================== --- lldb/include/lldb/Interpreter/CommandInterpreter.h +++ lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -649,7 +649,7 @@ void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found, StringList &commands_help, - CommandObject::CommandMap &command_map); + const CommandObject::CommandMap &command_map); // An interruptible wrapper around the stream output void PrintCommandOutput(Stream &stream, llvm::StringRef str);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits