2010-06-09 00:52:24 +08:00
|
|
|
//===-- CommandObjectApropos.cpp ---------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CommandObjectApropos.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
|
|
|
#include "lldb/Interpreter/Options.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectApropos
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CommandObjectApropos::CommandObjectApropos () :
|
|
|
|
CommandObject ("apropos",
|
2010-09-08 06:38:08 +08:00
|
|
|
"Find a list of debugger commands related to a particular word/subject.",
|
2010-06-09 00:52:24 +08:00
|
|
|
"apropos <search-word>")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectApropos::~CommandObjectApropos()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandObjectApropos::Execute
|
|
|
|
(
|
|
|
|
CommandInterpreter &interpreter,
|
|
|
|
Args& args,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
const int argc = args.GetArgumentCount ();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
const char *search_word = args.GetArgumentAtIndex(0);
|
2010-06-09 00:52:24 +08:00
|
|
|
if ((search_word != NULL)
|
|
|
|
&& (strlen (search_word) > 0))
|
|
|
|
{
|
|
|
|
// The bulk of the work must be done inside the Command Interpreter, since the command dictionary
|
|
|
|
// is private.
|
|
|
|
StringList commands_found;
|
|
|
|
StringList commands_help;
|
2010-06-23 09:19:29 +08:00
|
|
|
interpreter.FindCommandsForApropos (search_word, commands_found, commands_help);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (commands_found.GetSize() == 0)
|
|
|
|
{
|
|
|
|
result.AppendMessageWithFormat ("No commands found pertaining to '%s'.", search_word);
|
|
|
|
result.AppendMessage ("Try 'help' to see a complete list of debugger commands.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word);
|
|
|
|
size_t max_len = 0;
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
for (size_t i = 0; i < commands_found.GetSize(); ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
size_t len = strlen (commands_found.GetStringAtIndex (i));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (len > max_len)
|
|
|
|
max_len = len;
|
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
for (size_t i = 0; i < commands_found.GetSize(); ++i)
|
2010-06-23 09:19:29 +08:00
|
|
|
interpreter.OutputFormattedHelpText (result.GetOutputStream(),
|
|
|
|
commands_found.GetStringAtIndex(i),
|
|
|
|
"--", commands_help.
|
|
|
|
GetStringAtIndex(i),
|
|
|
|
max_len);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("'' is not a valid search word.\n");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("'apropos' must be called with exactly one argument.\n");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|