llvm-project/lldb/source/Commands/CommandObjectCrossref.cpp
Greg Clayton a701509229 Fixed the way set/show variables were being accessed to being natively
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
2010-09-18 01:14:36 +00:00

93 lines
2.3 KiB
C++

//===-- CommandObjectCrossref.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Interpreter/CommandObjectCrossref.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/CommandReturnObject.h"
using namespace lldb;
using namespace lldb_private;
//-------------------------------------------------------------------------
// CommandObjectCrossref
//-------------------------------------------------------------------------
CommandObjectCrossref::CommandObjectCrossref
(
CommandInterpreter &interpreter,
const char *name,
const char *help,
const char *syntax
) :
CommandObject (interpreter, name, help, syntax),
m_crossref_object_types()
{
}
CommandObjectCrossref::~CommandObjectCrossref ()
{
}
bool
CommandObjectCrossref::Execute
(
Args& command,
CommandReturnObject &result
)
{
if (m_crossref_object_types.GetArgumentCount() == 0)
{
result.AppendErrorWithFormat ("There are no objects for which you can call '%s'.\n", GetCommandName());
result.SetStatus (eReturnStatusFailed);
}
else
{
GenerateHelpText (result);
}
return result.Succeeded();
}
void
CommandObjectCrossref::AddObject (const char *obj_name)
{
m_crossref_object_types.AppendArgument (obj_name);
}
const char **
CommandObjectCrossref::GetObjectTypes () const
{
return m_crossref_object_types.GetConstArgumentVector();
}
void
CommandObjectCrossref::GenerateHelpText (CommandReturnObject &result)
{
result.AppendMessage ("This command can be called on the following types of objects:");
const size_t count = m_crossref_object_types.GetArgumentCount();
for (size_t i = 0; i < count; ++i)
{
const char *obj_name = m_crossref_object_types.GetArgumentAtIndex(i);
result.AppendMessageWithFormat (" %s (e.g. '%s %s')\n", obj_name,
obj_name, GetCommandName());
}
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
bool
CommandObjectCrossref::IsCrossRefObject ()
{
return true;
}