[Lldb-commits] [lldb] r264123 - Change 'apropos' such that it doesn't look into the "long help/syntax" strings for commands
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 22 18:21:56 PDT 2016
Author: enrico
Date: Tue Mar 22 20:21:55 2016
New Revision: 264123
URL: http://llvm.org/viewvc/llvm-project?rev=264123&view=rev
Log:
Change 'apropos' such that it doesn't look into the "long help/syntax" strings for commands
This solves issues such as 'apropos foo' returning valid matches just because syntax examples happen to use 'foo' as a placeholder token
Fixes rdar://9043025
Modified:
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/include/lldb/Interpreter/CommandObject.h
lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
lldb/trunk/packages/Python/lldbsuite/test/functionalities/multidebugger_commands/TestMultipleDebuggersCommands.py
lldb/trunk/source/Commands/CommandObjectApropos.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Interpreter/CommandObject.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Tue Mar 22 20:21:55 2016
@@ -201,8 +201,6 @@ class CommandInterpreter :
public IOHandlerDelegate
{
public:
- typedef std::map<std::string, lldb::CommandObjectSP> CommandAliasMap;
-
enum
{
eBroadcastBitThreadShouldExit = (1 << 0),
@@ -527,7 +525,8 @@ public:
StringList &commands_found,
StringList &commands_help,
bool search_builtin_commands,
- bool search_user_commands);
+ bool search_user_commands,
+ bool search_alias_commands);
bool
GetBatchCommandMode () { return m_batch_command_mode; }
@@ -680,13 +679,19 @@ private:
CommandObject *
ResolveCommandImpl(std::string &command_line, CommandReturnObject &result);
+ void
+ FindCommandsForApropos (const char *word,
+ StringList &commands_found,
+ StringList &commands_help,
+ CommandObject::CommandMap &command_map);
+
Debugger &m_debugger; // The debugger session that this interpreter is associated with
ExecutionContextRef m_exe_ctx_ref; // The current execution context to use when handling commands
bool m_synchronous_execution;
bool m_skip_lldbinit_files;
bool m_skip_app_init_files;
CommandObject::CommandMap m_command_dict; // Stores basic built-in commands (they cannot be deleted, removed or overwritten).
- CommandAliasMap m_alias_dict; // Stores user aliases/abbreviations for commands
+ CommandObject::CommandMap m_alias_dict; // Stores user aliases/abbreviations for commands
CommandObject::CommandMap m_user_dict; // Stores user-defined commands
CommandHistory m_command_history;
std::string m_repeat_command; // Stores the command that will be executed for an empty command string.
Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Tue Mar 22 20:21:55 2016
@@ -373,7 +373,11 @@ public:
}
bool
- HelpTextContainsWord (const char *search_word);
+ HelpTextContainsWord (const char *search_word,
+ bool search_short_help = true,
+ bool search_long_help = true,
+ bool search_syntax = true,
+ bool search_options = true);
//------------------------------------------------------------------
/// The flags accessor.
Modified: lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h Tue Mar 22 20:21:55 2016
@@ -96,6 +96,11 @@ public:
}
protected:
+ CommandObject::CommandMap&
+ GetSubcommandDictionary ()
+ {
+ return m_subcommand_dict;
+ }
CommandObject::CommandMap m_subcommand_dict;
bool m_can_be_removed;
Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/multidebugger_commands/TestMultipleDebuggersCommands.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/multidebugger_commands/TestMultipleDebuggersCommands.py?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/multidebugger_commands/TestMultipleDebuggersCommands.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/multidebugger_commands/TestMultipleDebuggersCommands.py Tue Mar 22 20:21:55 2016
@@ -20,7 +20,7 @@ class MultipleDebuggersCommandsTestCase(
def test_multipledebuggers_commands(self):
"""Test that commands do not try and hold on to stale CommandInterpreters in a multiple debuggers scenario"""
source_init_files = False
- magic_text = "The following built-in commands may relate to 'env'"
+ magic_text = "The following commands may relate to 'env'"
debugger_1 = lldb.SBDebugger.Create(source_init_files)
interpreter_1 = debugger_1.GetCommandInterpreter()
Modified: lldb/trunk/source/Commands/CommandObjectApropos.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectApropos.cpp?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectApropos.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectApropos.cpp Tue Mar 22 20:21:55 2016
@@ -62,13 +62,10 @@ CommandObjectApropos::DoExecute (Args& a
// is private.
StringList commands_found;
StringList commands_help;
- StringList user_commands_found;
- StringList user_commands_help;
- m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help, true, false);
- m_interpreter.FindCommandsForApropos (search_word, user_commands_found, user_commands_help, false, true);
+ m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help, true, true, true);
- if (commands_found.GetSize() == 0 && user_commands_found.GetSize() == 0)
+ if (commands_found.GetSize() == 0)
{
result.AppendMessageWithFormat ("No commands found pertaining to '%s'. Try 'help' to see a complete list of debugger commands.\n", search_word);
}
@@ -76,7 +73,7 @@ CommandObjectApropos::DoExecute (Args& a
{
if (commands_found.GetSize() > 0)
{
- result.AppendMessageWithFormat ("The following built-in commands may relate to '%s':\n", search_word);
+ result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word);
size_t max_len = 0;
for (size_t i = 0; i < commands_found.GetSize(); ++i)
@@ -92,28 +89,6 @@ CommandObjectApropos::DoExecute (Args& a
"--",
commands_help.GetStringAtIndex(i),
max_len);
- if (user_commands_found.GetSize() > 0)
- result.AppendMessage("");
- }
-
- if (user_commands_found.GetSize() > 0)
- {
- result.AppendMessageWithFormat ("The following user commands may relate to '%s':\n", search_word);
- size_t max_len = 0;
-
- for (size_t i = 0; i < user_commands_found.GetSize(); ++i)
- {
- size_t len = strlen (user_commands_found.GetStringAtIndex (i));
- if (len > max_len)
- max_len = len;
- }
-
- for (size_t i = 0; i < user_commands_found.GetSize(); ++i)
- m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
- user_commands_found.GetStringAtIndex(i),
- "--",
- user_commands_help.GetStringAtIndex(i),
- max_len);
}
}
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Mar 22 20:21:55 2016
@@ -780,7 +780,7 @@ CommandInterpreter::GetCommandSP (const
if (include_aliases && HasAliases())
{
- CommandAliasMap::iterator alias_pos = m_alias_dict.find(cmd);
+ auto alias_pos = m_alias_dict.find(cmd);
if (alias_pos != m_alias_dict.end())
command_sp = alias_pos->second;
}
@@ -831,7 +831,7 @@ CommandInterpreter::GetCommandSP (const
if (num_alias_matches == 1)
{
cmd.assign(matches->GetStringAtIndex (num_cmd_matches));
- CommandAliasMap::iterator alias_pos = m_alias_dict.find(cmd);
+ auto alias_pos = m_alias_dict.find(cmd);
if (alias_pos != m_alias_dict.end())
alias_match_sp = alias_pos->second;
}
@@ -2781,54 +2781,63 @@ CommandInterpreter::OutputHelpText (Stre
}
void
-CommandInterpreter::FindCommandsForApropos (const char *search_word, StringList &commands_found,
- StringList &commands_help, bool search_builtin_commands, bool search_user_commands)
+CommandInterpreter::FindCommandsForApropos (const char *search_word,
+ StringList &commands_found,
+ StringList &commands_help,
+ CommandObject::CommandMap &command_map)
{
CommandObject::CommandMap::const_iterator pos;
-
- if (search_builtin_commands)
+
+ for (pos = command_map.begin(); pos != command_map.end(); ++pos)
{
- for (pos = m_command_dict.begin(); pos != m_command_dict.end(); ++pos)
- {
- const char *command_name = pos->first.c_str();
- CommandObject *cmd_obj = pos->second.get();
-
- if (cmd_obj->HelpTextContainsWord (search_word))
- {
- commands_found.AppendString (command_name);
- commands_help.AppendString (cmd_obj->GetHelp());
- }
-
- if (cmd_obj->IsMultiwordObject())
- cmd_obj->AproposAllSubCommands (command_name,
- search_word,
- commands_found,
- commands_help);
-
+ const char *command_name = pos->first.c_str();
+ CommandObject *cmd_obj = pos->second.get();
+
+ const bool search_short_help = true;
+ const bool search_long_help = false;
+ const bool search_syntax = false;
+ const bool search_options = false;
+ if (strcasestr(command_name, search_word) ||
+ cmd_obj->HelpTextContainsWord (search_word,
+ search_short_help,
+ search_long_help,
+ search_syntax,
+ search_options))
+ {
+ commands_found.AppendString (command_name);
+ commands_help.AppendString (cmd_obj->GetHelp());
+ }
+
+ if (cmd_obj->IsMultiwordObject())
+ {
+ CommandObjectMultiword *cmd_multiword = (CommandObjectMultiword*)cmd_obj;
+ FindCommandsForApropos(search_word,
+ commands_found,
+ commands_help,
+ cmd_multiword->GetSubcommandDictionary());
}
}
+}
+
+
+void
+CommandInterpreter::FindCommandsForApropos (const char *search_word,
+ StringList &commands_found,
+ StringList &commands_help,
+ bool search_builtin_commands,
+ bool search_user_commands,
+ bool search_alias_commands)
+{
+ CommandObject::CommandMap::const_iterator pos;
+
+ if (search_builtin_commands)
+ FindCommandsForApropos(search_word, commands_found, commands_help, m_command_dict);
if (search_user_commands)
- {
- for (pos = m_user_dict.begin(); pos != m_user_dict.end(); ++pos)
- {
- const char *command_name = pos->first.c_str();
- CommandObject *cmd_obj = pos->second.get();
-
- if (cmd_obj->HelpTextContainsWord (search_word))
- {
- commands_found.AppendString (command_name);
- commands_help.AppendString (cmd_obj->GetHelp());
- }
+ FindCommandsForApropos(search_word, commands_found, commands_help, m_user_dict);
- if (cmd_obj->IsMultiwordObject())
- cmd_obj->AproposAllSubCommands (command_name,
- search_word,
- commands_found,
- commands_help);
-
- }
- }
+ if (search_alias_commands)
+ FindCommandsForApropos(search_word, commands_found, commands_help, m_alias_dict);
}
void
Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Tue Mar 22 20:21:55 2016
@@ -411,7 +411,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;
@@ -421,14 +425,15 @@ CommandObject::HelpTextContainsWord (con
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;
More information about the lldb-commits
mailing list