accessed by the objects that own the settings. The previous approach wasn't very usable and made for a lot of unnecessary code just to access variables that were already owned by the objects. While I fixed those things, I saw that CommandObject objects should really have a reference to their command interpreter so they can access the terminal with if they want to output usaage. Fixed up all CommandObjects to take an interpreter and cleaned up the API to not need the interpreter to be passed in. Fixed the disassemble command to output the usage if no options are passed down and arguments are passed (all disassebmle variants take options, there are no "args only"). llvm-svn: 114252
103 lines
3.4 KiB
C++
103 lines
3.4 KiB
C++
//===-- 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
|
|
#include "lldb/Interpreter/Args.h"
|
|
#include "lldb/Interpreter/Options.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
//-------------------------------------------------------------------------
|
|
// CommandObjectApropos
|
|
//-------------------------------------------------------------------------
|
|
|
|
CommandObjectApropos::CommandObjectApropos (CommandInterpreter &interpreter) :
|
|
CommandObject (interpreter,
|
|
"apropos",
|
|
"Find a list of debugger commands related to a particular word/subject.",
|
|
"apropos <search-word>")
|
|
{
|
|
}
|
|
|
|
CommandObjectApropos::~CommandObjectApropos()
|
|
{
|
|
}
|
|
|
|
|
|
bool
|
|
CommandObjectApropos::Execute
|
|
(
|
|
Args& args,
|
|
CommandReturnObject &result
|
|
)
|
|
{
|
|
const int argc = args.GetArgumentCount ();
|
|
|
|
if (argc == 1)
|
|
{
|
|
const char *search_word = args.GetArgumentAtIndex(0);
|
|
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;
|
|
m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help);
|
|
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;
|
|
|
|
for (size_t i = 0; i < commands_found.GetSize(); ++i)
|
|
{
|
|
size_t len = strlen (commands_found.GetStringAtIndex (i));
|
|
if (len > max_len)
|
|
max_len = len;
|
|
}
|
|
|
|
for (size_t i = 0; i < commands_found.GetSize(); ++i)
|
|
m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
|
|
commands_found.GetStringAtIndex(i),
|
|
"--", commands_help.
|
|
GetStringAtIndex(i),
|
|
max_len);
|
|
|
|
}
|
|
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();
|
|
}
|