forked from OSchip/llvm-project
Add infrastructure for standardizing arguments for commands and
command options; makes it easier to ensure that the same type of argument will have the same name everywhere, hooks up help for command arguments, so that users can ask for help when they are confused about what an argument should be; puts in the beginnings of the ability to do tab-completion for certain types of arguments, allows automatic syntax help generation for commands with arguments, and adds command arguments into command options help correctly. Currently only the breakpoint-id and breakpoint-id-range arguments, in the breakpoint commands, have been hooked up to use the new mechanism. The next steps will be to fix the command options arguments to use this mechanism, and to fix the rest of the regular command arguments to use this mechanism. Most of the help text is currently missing or dummy text; this will need to be filled in, and the existing argument help text will need to be cleaned up a bit (it was thrown in quickly, mostly for testing purposes). Help command now works for all argument types, although the help may not be very helpful yet. Those commands that take "raw" command strings now indicate it in their help text. llvm-svn: 115318
This commit is contained in:
parent
b5051dc529
commit
e139cf2320
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Interpreter/Args.h"
|
||||
#include "lldb/Interpreter/CommandCompletions.h"
|
||||
#include "lldb/Core/StringList.h"
|
||||
#include "lldb/Core/Flags.h"
|
||||
|
||||
|
@ -25,8 +26,29 @@ namespace lldb_private {
|
|||
class CommandObject
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, lldb::CommandObjectSP> CommandMap;
|
||||
|
||||
typedef const char *(ArgumentHelpCallbackFunction) ();
|
||||
|
||||
struct ArgumentTableEntry // Entries in the main argument information table
|
||||
{
|
||||
lldb::CommandArgumentType arg_type;
|
||||
const char *arg_name;
|
||||
CommandCompletions::CommonCompletionTypes completion_type;
|
||||
ArgumentHelpCallbackFunction *help_function;
|
||||
const char *help_text;
|
||||
};
|
||||
|
||||
struct CommandArgumentData // Used to build individual command argument lists
|
||||
{
|
||||
lldb::CommandArgumentType arg_type;
|
||||
lldb::ArgumentRepetitionType arg_repetition;
|
||||
};
|
||||
|
||||
typedef std::vector<CommandArgumentData> CommandArgumentEntry; // Used to build individual command argument lists
|
||||
|
||||
static ArgumentTableEntry g_arguments_data[lldb::eArgTypeLastArg]; // Main argument information table
|
||||
|
||||
typedef std::map<std::string, lldb::CommandObjectSP> CommandMap;
|
||||
|
||||
CommandObject (CommandInterpreter &interpreter,
|
||||
const char *name,
|
||||
|
@ -88,6 +110,30 @@ public:
|
|||
virtual Options *
|
||||
GetOptions ();
|
||||
|
||||
static const ArgumentTableEntry*
|
||||
GetArgumentTable ();
|
||||
|
||||
static const lldb::CommandArgumentType
|
||||
LookupArgumentName (const char *arg_name);
|
||||
|
||||
static ArgumentTableEntry *
|
||||
FindArgumentDataByType (lldb::CommandArgumentType arg_type);
|
||||
|
||||
int
|
||||
GetNumArgumentEntries ();
|
||||
|
||||
CommandArgumentEntry *
|
||||
GetArgumentEntryAtIndex (int idx);
|
||||
|
||||
static void
|
||||
GetArgumentHelp (Stream &str, lldb::CommandArgumentType arg_type, CommandInterpreter &interpreter);
|
||||
|
||||
const char *
|
||||
GetArgumentName (lldb::CommandArgumentType arg_type);
|
||||
|
||||
void
|
||||
GetFormattedCommandArguments (Stream &str);
|
||||
|
||||
enum
|
||||
{
|
||||
eFlagProcessMustBeLaunched = (1 << 0),
|
||||
|
@ -277,6 +323,7 @@ protected:
|
|||
std::string m_cmd_syntax;
|
||||
bool m_is_alias;
|
||||
Flags m_flags;
|
||||
std::vector<CommandArgumentEntry> m_arguments;
|
||||
};
|
||||
|
||||
} // namespace lldb_private
|
||||
|
|
|
@ -503,6 +503,75 @@ typedef enum VarSetOperationType
|
|||
eVarSetOperationInvalid
|
||||
} VarSetOperationType;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/// Command argument types.
|
||||
///
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
typedef enum CommandArgumentType
|
||||
{
|
||||
eArgTypeAddress = 0,
|
||||
eArgTypeArchitecture,
|
||||
eArgTypeBoolean,
|
||||
eArgTypeBreakpointID,
|
||||
eArgTypeBreakpointIDRange,
|
||||
eArgTypeByteSize,
|
||||
eArgTypeChannel,
|
||||
eArgTypeCount,
|
||||
eArgTypeExpression,
|
||||
eArgTypeFilename,
|
||||
eArgTypeFormat,
|
||||
eArgTypeFullName,
|
||||
eArgTypeFunctionName,
|
||||
eArgTypeIndex,
|
||||
eArgTypeLineNum,
|
||||
eArgTypeMethod,
|
||||
eArgTypeName,
|
||||
eArgTypeNumLines,
|
||||
eArgTypeNumberPerLine,
|
||||
eArgTypeOffset,
|
||||
eArgTypeOther,
|
||||
eArgTypePath,
|
||||
eArgTypePathPrefix,
|
||||
eArgTypePathPrefixPair,
|
||||
eArgTypePid,
|
||||
eArgTypePlugin,
|
||||
eArgTypeProcessName,
|
||||
eArgTypeQueueName,
|
||||
eArgTypeRegisterName,
|
||||
eArgTypeRegularExpression,
|
||||
eArgTypeRunMode,
|
||||
eArgTypeSearchWord,
|
||||
eArgTypeSelector,
|
||||
eArgTypeSettingIndex,
|
||||
eArgTypeSettingKey,
|
||||
eArgTypeSettingPrefix,
|
||||
eArgTypeSettingVariableName,
|
||||
eArgTypeShlibName,
|
||||
eArgTypeSourceFile,
|
||||
eArgTypeStartAddress,
|
||||
eArgTypeSymbol,
|
||||
eArgTypeThreadID,
|
||||
eArgTypeThreadIndex,
|
||||
eArgTypeThreadName,
|
||||
eArgTypeUUID,
|
||||
eArgTypeUnixSignalNumber,
|
||||
eArgTypeVarName,
|
||||
eArgTypeValue,
|
||||
eArgTypeWidth,
|
||||
eArgTypeNone,
|
||||
eArgTypeLastArg // Always keep this entry as the last entry in this enumeration!!
|
||||
} CommandArgumentType;
|
||||
|
||||
typedef enum ArgumentRepetitionType
|
||||
{
|
||||
eArgRepeatPlain, // Exactly one occurrence
|
||||
eArgRepeatOptional, // At most one occurrence, but it's optional
|
||||
eArgRepeatPlus, // One or more occurrences
|
||||
eArgRepeatStar // Zero or more occurrences
|
||||
} ArgumentRepetitionType;
|
||||
|
||||
|
||||
} // namespace lldb
|
||||
|
||||
|
||||
|
|
|
@ -685,8 +685,20 @@ CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &in
|
|||
CommandObject (interpreter,
|
||||
"breakpoint list",
|
||||
"List some or all breakpoints at configurable levels of detail.",
|
||||
"breakpoint list [<breakpoint-id>]")
|
||||
NULL)
|
||||
{
|
||||
CommandArgumentEntry arg;
|
||||
CommandArgumentData bp_id_arg;
|
||||
|
||||
// Define the first (and only) variant of this arg.
|
||||
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
||||
bp_id_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// There is only one variant this argument could be; put it into the argument entry.
|
||||
arg.push_back (bp_id_arg);
|
||||
|
||||
// Push the data for the first argument into the m_arguments vector.
|
||||
m_arguments.push_back (arg);
|
||||
}
|
||||
|
||||
CommandObjectBreakpointList::~CommandObjectBreakpointList ()
|
||||
|
@ -774,14 +786,28 @@ CommandObjectBreakpointList::Execute
|
|||
CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
|
||||
CommandObject (interpreter,
|
||||
"enable",
|
||||
"Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
|
||||
"breakpoint enable [<breakpoint-id> | <breakpoint-id-list>]")
|
||||
"Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
|
||||
NULL)
|
||||
{
|
||||
// This command object can either be called via 'enable' or 'breakpoint enable'. Because it has two different
|
||||
// potential invocation methods, we need to be a little tricky about generating the syntax string.
|
||||
//StreamString tmp_string;
|
||||
//tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
|
||||
//m_cmd_syntax.assign (tmp_string.GetData(), tmp_string.GetSize());
|
||||
CommandArgumentEntry arg;
|
||||
CommandArgumentData bp_id_arg;
|
||||
CommandArgumentData bp_id_range_arg;
|
||||
|
||||
// Create the first variant for the first (and only) argument for this command.
|
||||
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
||||
bp_id_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// Create the second variant for the first (and only) argument for this command.
|
||||
bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
|
||||
bp_id_range_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// The first (and only) argument for this command could be either a bp_id or a bp_id_range.
|
||||
// Push both variants into the entry for the first argument for this command.
|
||||
arg.push_back (bp_id_arg);
|
||||
arg.push_back (bp_id_range_arg);
|
||||
|
||||
// Add the entry for the first argument for this command to the object's arguments vector.
|
||||
m_arguments.push_back (arg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -875,15 +901,29 @@ CommandObjectBreakpointEnable::Execute
|
|||
|
||||
CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
|
||||
CommandObject (interpreter,
|
||||
"disable",
|
||||
"breakpoint disable",
|
||||
"Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
|
||||
"disable [<breakpoint-id> | <breakpoint-id-list>]")
|
||||
NULL)
|
||||
{
|
||||
// This command object can either be called via 'enable' or 'breakpoint enable'. Because it has two different
|
||||
// potential invocation methods, we need to be a little tricky about generating the syntax string.
|
||||
//StreamString tmp_string;
|
||||
//tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
|
||||
//m_cmd_syntax.assign(tmp_string.GetData(), tmp_string.GetSize());
|
||||
CommandArgumentEntry arg;
|
||||
CommandArgumentData bp_id_arg;
|
||||
CommandArgumentData bp_id_range_arg;
|
||||
|
||||
// Create the first variant for the first (and only) argument for this command.
|
||||
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
||||
bp_id_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// Create the second variant for the first (and only) argument for this command.
|
||||
bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
|
||||
bp_id_range_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// The first (and only) argument for this command could be either a bp_id or a bp_id_range.
|
||||
// Push both variants into the entry for the first argument for this command.
|
||||
arg.push_back (bp_id_arg);
|
||||
arg.push_back (bp_id_range_arg);
|
||||
|
||||
// Add the entry for the first argument for this command to the object's arguments vector.
|
||||
m_arguments.push_back (arg);
|
||||
}
|
||||
|
||||
CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
|
||||
|
@ -977,8 +1017,27 @@ CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter
|
|||
CommandObject (interpreter,
|
||||
"breakpoint delete",
|
||||
"Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
|
||||
"breakpoint delete [<breakpoint-id> | <breakpoint-id-list>]")
|
||||
NULL)
|
||||
{
|
||||
CommandArgumentEntry arg;
|
||||
CommandArgumentData bp_id_arg;
|
||||
CommandArgumentData bp_id_range_arg;
|
||||
|
||||
// Create the first variant for the first (and only) argument for this command.
|
||||
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
||||
bp_id_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// Create the second variant for the first (and only) argument for this command.
|
||||
bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
|
||||
bp_id_range_arg.arg_repetition = eArgRepeatStar;
|
||||
|
||||
// The first (and only) argument for this command could be either a bp_id or a bp_id_range.
|
||||
// Push both variants into the entry for the first argument for this command.
|
||||
arg.push_back (bp_id_arg);
|
||||
arg.push_back (bp_id_range_arg);
|
||||
|
||||
// Add the entry for the first argument for this command to the object's arguments vector.
|
||||
m_arguments.push_back (arg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1198,8 +1257,27 @@ CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter
|
|||
CommandObject (interpreter,
|
||||
"breakpoint modify",
|
||||
"Modify the options on a breakpoint or set of breakpoints in the executable.",
|
||||
"breakpoint modify <cmd-options> <breakpoint-id> [<breakpoint-id> ...]")
|
||||
NULL)
|
||||
{
|
||||
CommandArgumentEntry arg;
|
||||
CommandArgumentData bp_id_arg;
|
||||
CommandArgumentData bp_id_range_arg;
|
||||
|
||||
// Create the first variant for the first (and only) argument for this command.
|
||||
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
||||
bp_id_arg.arg_repetition = eArgRepeatPlus;
|
||||
|
||||
// Create the second variant for the first (and only) argument for this command.
|
||||
bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
|
||||
bp_id_range_arg.arg_repetition = eArgRepeatPlus;
|
||||
|
||||
// The first (and only) argument for this command could be either a bp_id or a bp_id_range.
|
||||
// Push both variants into the entry for the first argument for this command.
|
||||
arg.push_back (bp_id_arg);
|
||||
arg.push_back (bp_id_range_arg);
|
||||
|
||||
// Add the entry for the first argument for this command to the object's arguments vector.
|
||||
m_arguments.push_back (arg);
|
||||
}
|
||||
|
||||
CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
|
||||
|
|
|
@ -95,7 +95,14 @@ CommandObjectHelp::Execute (Args& command, CommandReturnObject &result)
|
|||
Stream &output_strm = result.GetOutputStream();
|
||||
if (sub_cmd_obj->GetOptions() != NULL)
|
||||
{
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1);
|
||||
if (sub_cmd_obj->WantsRawCommandString())
|
||||
{
|
||||
std::string help_text (sub_cmd_obj->GetHelp());
|
||||
help_text.append (" This command takes 'raw' input (no need to quote stuff).");
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1);
|
||||
}
|
||||
else
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1);
|
||||
output_strm.Printf ("\nSyntax: %s\n", sub_cmd_obj->GetSyntax());
|
||||
sub_cmd_obj->GetOptions()->GenerateOptionUsage (m_interpreter, output_strm, sub_cmd_obj);
|
||||
const char *long_help = sub_cmd_obj->GetHelpLong();
|
||||
|
@ -105,7 +112,14 @@ CommandObjectHelp::Execute (Args& command, CommandReturnObject &result)
|
|||
}
|
||||
else if (sub_cmd_obj->IsMultiwordObject())
|
||||
{
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1);
|
||||
if (sub_cmd_obj->WantsRawCommandString())
|
||||
{
|
||||
std::string help_text (sub_cmd_obj->GetHelp());
|
||||
help_text.append (" This command takes 'raw' input (no need to quote stuff).");
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1);
|
||||
}
|
||||
else
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1);
|
||||
((CommandObjectMultiword *) sub_cmd_obj)->GenerateHelpText (result);
|
||||
}
|
||||
else
|
||||
|
@ -114,6 +128,12 @@ CommandObjectHelp::Execute (Args& command, CommandReturnObject &result)
|
|||
if ((long_help != NULL)
|
||||
&& (strlen (long_help) > 0))
|
||||
output_strm.Printf ("\n%s", long_help);
|
||||
else if (sub_cmd_obj->WantsRawCommandString())
|
||||
{
|
||||
std::string help_text (sub_cmd_obj->GetHelp());
|
||||
help_text.append (" This command takes 'raw' input (no need to quote stuff).");
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1);
|
||||
}
|
||||
else
|
||||
m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1);
|
||||
output_strm.Printf ("\nSyntax: %s\n", sub_cmd_obj->GetSyntax());
|
||||
|
@ -132,10 +152,21 @@ CommandObjectHelp::Execute (Args& command, CommandReturnObject &result)
|
|||
}
|
||||
else
|
||||
{
|
||||
result.AppendErrorWithFormat
|
||||
("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n",
|
||||
command.GetArgumentAtIndex(0));
|
||||
result.SetStatus (eReturnStatusFailed);
|
||||
// Maybe the user is asking for help about a command argument rather than a command.
|
||||
const CommandArgumentType arg_type = CommandObject::LookupArgumentName (command.GetArgumentAtIndex (0));
|
||||
if (arg_type != eArgTypeLastArg)
|
||||
{
|
||||
Stream &output_strm = result.GetOutputStream ();
|
||||
CommandObject::GetArgumentHelp (output_strm, arg_type, m_interpreter);
|
||||
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AppendErrorWithFormat
|
||||
("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n",
|
||||
command.GetArgumentAtIndex(0));
|
||||
result.SetStatus (eReturnStatusFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -196,11 +196,22 @@ CommandObjectMultiword::GenerateHelpText (CommandReturnObject &result)
|
|||
{
|
||||
std::string indented_command (" ");
|
||||
indented_command.append (pos->first);
|
||||
m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
|
||||
indented_command.c_str(),
|
||||
"--",
|
||||
pos->second->GetHelp(),
|
||||
max_len);
|
||||
if (pos->second->WantsRawCommandString ())
|
||||
{
|
||||
std::string help_text (pos->second->GetHelp());
|
||||
help_text.append (" This command takes 'raw' input (no need to quote stuff).");
|
||||
m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
|
||||
indented_command.c_str(),
|
||||
"--",
|
||||
help_text.c_str(),
|
||||
max_len);
|
||||
}
|
||||
else
|
||||
m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
|
||||
indented_command.c_str(),
|
||||
"--",
|
||||
pos->second->GetHelp(),
|
||||
max_len);
|
||||
}
|
||||
|
||||
output_stream.PutCString ("\nFor more help on any particular subcommand, type 'help <command> <subcommand>'.\n");
|
||||
|
|
|
@ -52,7 +52,8 @@ CommandObject::CommandObject
|
|||
m_cmd_help_long (),
|
||||
m_cmd_syntax (),
|
||||
m_is_alias (false),
|
||||
m_flags (flags)
|
||||
m_flags (flags),
|
||||
m_arguments()
|
||||
{
|
||||
if (help && help[0])
|
||||
m_cmd_help_short = help;
|
||||
|
@ -79,6 +80,20 @@ CommandObject::GetHelpLong ()
|
|||
const char *
|
||||
CommandObject::GetSyntax ()
|
||||
{
|
||||
if (m_cmd_syntax.length() == 0)
|
||||
{
|
||||
StreamString syntax_str;
|
||||
syntax_str.Printf ("%s", GetCommandName());
|
||||
if (GetOptions() != NULL)
|
||||
syntax_str.Printf (" <cmd-options> ");
|
||||
if (m_arguments.size() > 0)
|
||||
{
|
||||
syntax_str.Printf (" ");
|
||||
GetFormattedCommandArguments (syntax_str);
|
||||
}
|
||||
m_cmd_syntax = syntax_str.GetData ();
|
||||
}
|
||||
|
||||
return m_cmd_syntax.c_str();
|
||||
}
|
||||
|
||||
|
@ -431,3 +446,188 @@ CommandObject::HelpTextContainsWord (const char *search_word)
|
|||
|
||||
return found_word;
|
||||
}
|
||||
|
||||
int
|
||||
CommandObject::GetNumArgumentEntries ()
|
||||
{
|
||||
return m_arguments.size();
|
||||
}
|
||||
|
||||
CommandObject::CommandArgumentEntry *
|
||||
CommandObject::GetArgumentEntryAtIndex (int idx)
|
||||
{
|
||||
if (idx < m_arguments.size())
|
||||
return &(m_arguments[idx]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CommandObject::ArgumentTableEntry *
|
||||
CommandObject::FindArgumentDataByType (CommandArgumentType arg_type)
|
||||
{
|
||||
const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
|
||||
|
||||
for (int i = 0; i < eArgTypeLastArg; ++i)
|
||||
if (table[i].arg_type == arg_type)
|
||||
return (ArgumentTableEntry *) &(table[i]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter)
|
||||
{
|
||||
const ArgumentTableEntry* table = CommandObject::GetArgumentTable();
|
||||
ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]);
|
||||
|
||||
// The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
|
||||
|
||||
if (entry->arg_type != arg_type)
|
||||
entry = CommandObject::FindArgumentDataByType (arg_type);
|
||||
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
StreamString name_str;
|
||||
name_str.Printf ("<%s>", entry->arg_name);
|
||||
|
||||
if (entry->help_function != NULL)
|
||||
interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", (*(entry->help_function)) (),
|
||||
name_str.GetSize());
|
||||
else
|
||||
interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize());
|
||||
}
|
||||
|
||||
const char *
|
||||
CommandObject::GetArgumentName (CommandArgumentType arg_type)
|
||||
{
|
||||
return CommandObject::GetArgumentTable()[arg_type].arg_name;
|
||||
}
|
||||
|
||||
void
|
||||
CommandObject::GetFormattedCommandArguments (Stream &str)
|
||||
{
|
||||
int num_args = m_arguments.size();
|
||||
for (int i = 0; i < num_args; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
str.Printf (" ");
|
||||
CommandArgumentEntry arg_entry = m_arguments[i];
|
||||
int num_alternatives = arg_entry.size();
|
||||
StreamString names;
|
||||
for (int j = 0; j < num_alternatives; ++j)
|
||||
{
|
||||
if (j > 0)
|
||||
names.Printf (" | ");
|
||||
names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type));
|
||||
}
|
||||
switch (arg_entry[0].arg_repetition)
|
||||
{
|
||||
case eArgRepeatPlain:
|
||||
str.Printf ("<%s>", names.GetData());
|
||||
break;
|
||||
case eArgRepeatPlus:
|
||||
str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData());
|
||||
break;
|
||||
case eArgRepeatStar:
|
||||
str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData());
|
||||
break;
|
||||
case eArgRepeatOptional:
|
||||
str.Printf ("[<%s>]", names.GetData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CommandArgumentType
|
||||
CommandObject::LookupArgumentName (const char *arg_name)
|
||||
{
|
||||
CommandArgumentType return_type = eArgTypeLastArg;
|
||||
|
||||
std::string arg_name_str (arg_name);
|
||||
size_t len = arg_name_str.length();
|
||||
if (arg_name[0] == '<'
|
||||
&& arg_name[len-1] == '>')
|
||||
arg_name_str = arg_name_str.substr (1, len-2);
|
||||
|
||||
for (int i = 0; i < eArgTypeLastArg; ++i)
|
||||
if (arg_name_str.compare (g_arguments_data[i].arg_name) == 0)
|
||||
return_type = g_arguments_data[i].arg_type;
|
||||
|
||||
return return_type;
|
||||
}
|
||||
|
||||
static const char *
|
||||
BreakpointIDHelpTextCallback ()
|
||||
{
|
||||
return "Breakpoint ID's consist major and minor numbers; the major number corresponds to the single entity that was created with a 'breakpoint set' command; the minor numbers correspond to all the locations that were actually found/set based on the major breakpoint. A full breakpoint ID might look like 3.14, meaning the 14th location set for the 3rd breakpoint. You can specify all the locations of a breakpoint by just indicating the major breakpoint number. A valid breakpoint id consists either of just the major id number, or the major number, a dot, and the location number (e.g. 3 or 3.2 could both be valid breakpoint ids).";
|
||||
}
|
||||
|
||||
static const char *
|
||||
BreakpointIDRangeHelpTextCallback ()
|
||||
{
|
||||
return "A 'breakpoint id range' is a manner of specifying multiple breakpoints. This can be done through several mechanisms. The easiest way is to just enter a space-separated list of breakpoint ids. To specify all the breakpoint locations under a major breakpoint, you can use the major breakpoint number followed by '.*', eg. '5.*' means all the locations under breakpoint 5. You can also indicate a range of breakpoints by using <start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a range can be any valid breakpoint ids. It is not legal, however, to specify a range using specific locations that cross major breakpoint numbers. I.e. 3.2 - 3.7 is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
|
||||
}
|
||||
|
||||
CommandObject::ArgumentTableEntry
|
||||
CommandObject::g_arguments_data[] =
|
||||
{
|
||||
{ eArgTypeAddress, "address", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeArchitecture, "architecture", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeBreakpointID, "breakpoint-id", CommandCompletions::eNoCompletion, BreakpointIDHelpTextCallback, NULL },
|
||||
{ eArgTypeBreakpointIDRange, "breakpoint-id-range", CommandCompletions::eNoCompletion, BreakpointIDRangeHelpTextCallback, NULL },
|
||||
{ eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeChannel, "channel", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeCount, "count", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeExpression, "expression", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeFilename, "filename", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeFormat, "format", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeFullName, "full-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeIndex, "index", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeLineNum, "line-num", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeMethod, "method", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeName, "name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeOther, "other", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypePath, "path", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypePathPrefix, "path-prefix", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypePathPrefixPair, "path-prefix-pair", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypePid, "pid", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSettingKey, "setting-key", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSettingVariableName, "setting-variable-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSourceFile, "source-file", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeSymbol, "symbol", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeUUID, "UUID", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeUnixSignalNumber, "unix-signal-number", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeVarName, "var-name", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeValue, "value", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeWidth, "width", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
{ eArgTypeNone, "none", CommandCompletions::eNoCompletion, NULL, "Help text goes here." },
|
||||
};
|
||||
|
||||
const CommandObject::ArgumentTableEntry*
|
||||
CommandObject::GetArgumentTable ()
|
||||
{
|
||||
return CommandObject::g_arguments_data;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -372,8 +372,13 @@ Options::GenerateOptionUsage
|
|||
const uint32_t save_indent_level = strm.GetIndentLevel();
|
||||
const char *name;
|
||||
|
||||
StreamString arguments_str;
|
||||
|
||||
if (cmd)
|
||||
{
|
||||
name = cmd->GetCommandName();
|
||||
cmd->GetFormattedCommandArguments (arguments_str);
|
||||
}
|
||||
else
|
||||
name = "";
|
||||
|
||||
|
@ -517,6 +522,8 @@ Options::GenerateOptionUsage
|
|||
}
|
||||
}
|
||||
}
|
||||
if (arguments_str.GetSize() > 0)
|
||||
strm.Printf (" %s", arguments_str.GetData());
|
||||
}
|
||||
strm.Printf ("\n\n");
|
||||
|
||||
|
|
Loading…
Reference in New Issue