Replace calls to HandleCommand in lldb core with more appropriate

direct function calls.  As part of this, collect code that processes
arguments & options for aliases into a single function.

llvm-svn: 131020
This commit is contained in:
Caroline Tice 2011-05-06 21:37:15 +00:00
parent bceca20ab9
commit ca90c47eed
3 changed files with 183 additions and 84 deletions

View File

@ -90,6 +90,12 @@ public:
OptionArgVectorSP
GetAliasOptions (const char *alias_name);
bool
ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
const char *options_args,
OptionArgVectorSP &option_arg_vector_sp);
void
RemoveAliasOptions (const char *alias_name);

View File

@ -351,33 +351,13 @@ public:
OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
// Check to see if there's anything left in the input command string.
if (raw_command_string.size() > 0)
CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
if (!m_interpreter.ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp))
{
// Check to see if the command being aliased can take any command options.
Options *options = cmd_obj->GetOptions();
if (options)
{
// See if any options were specified as part of the alias; if so, handle them appropriately
options->NotifyOptionParsingStarting ();
Args tmp_args (raw_command_string.c_str());
args.Unshift ("dummy_arg");
args.ParseAliasOptions (*options, result, option_arg_vector, raw_command_string);
args.Shift ();
if (result.Succeeded())
options->VerifyPartialOptions (result);
if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
{
result.AppendError ("Unable to create requested alias.\n");
return false;
}
}
// Anything remaining must be plain raw input. Push it in as a single raw input argument.
if (raw_command_string.size() > 0)
option_arg_vector->push_back (OptionArgPair ("<argument>",
OptionArgValue (-1,
raw_command_string)));
result.AppendError ("Unable to create requested alias.\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
// Create the alias
@ -394,7 +374,6 @@ public:
alias_command.c_str());
}
CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
if (cmd_obj_sp)
{
m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp);
@ -483,37 +462,19 @@ public:
if (args.GetArgumentCount () > 0)
{
if ((!use_subcommand && (cmd_obj->GetOptions() != NULL))
|| (use_subcommand && (sub_cmd_obj->GetOptions() != NULL)))
{
Options *options;
if (use_subcommand)
options = sub_cmd_obj->GetOptions();
else
options = cmd_obj->GetOptions();
options->NotifyOptionParsingStarting ();
std::string empty_string;
args.Unshift ("dummy_arg");
args.ParseAliasOptions (*options, result, option_arg_vector, empty_string);
args.Shift ();
if (result.Succeeded())
options->VerifyPartialOptions (result);
if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
{
result.AppendError ("Unable to create requested command alias.\n");
return false;
}
}
// Anything remaining in args must be a plain argument.
argc = args.GetArgumentCount();
for (size_t i = 0; i < argc; ++i)
if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
option_arg_vector->push_back
(OptionArgPair ("<argument>",
OptionArgValue (-1,
std::string (args.GetArgumentAtIndex (i)))));
CommandObjectSP tmp_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
if (use_subcommand)
tmp_sp = m_interpreter.GetCommandSPExact (sub_cmd_obj->GetCommandName(), false);
std::string args_string;
args.GetCommandString (args_string);
if (!m_interpreter.ProcessAliasOptionsArgs (tmp_sp, args_string.c_str(), option_arg_vector_sp))
{
result.AppendError ("Unable to create requested alias.\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
}
// Create the alias.

View File

@ -39,6 +39,7 @@
#include "../Commands/CommandObjectVersion.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/InputReader.h"
#include "lldb/Core/Stream.h"
@ -92,33 +93,111 @@ CommandInterpreter::Initialize ()
LoadCommandDictionary ();
// Set up some initial aliases.
HandleCommand ("command alias q quit", false, result);
HandleCommand ("command alias run process launch --", false, result);
HandleCommand ("command alias r process launch --", false, result);
HandleCommand ("command alias c process continue", false, result);
HandleCommand ("command alias continue process continue", false, result);
HandleCommand ("command alias expr expression", false, result);
HandleCommand ("command alias exit quit", false, result);
HandleCommand ("command alias b _regexp-break", false, result);
HandleCommand ("command alias bt thread backtrace", false, result);
HandleCommand ("command alias si thread step-inst", false, result);
HandleCommand ("command alias step thread step-in", false, result);
HandleCommand ("command alias s thread step-in", false, result);
HandleCommand ("command alias next thread step-over", false, result);
HandleCommand ("command alias n thread step-over", false, result);
HandleCommand ("command alias f thread step-out", false, result);
HandleCommand ("command alias finish thread step-out", false, result);
HandleCommand ("command alias x memory read", false, result);
HandleCommand ("command alias l source list", false, result);
HandleCommand ("command alias list source list", false, result);
HandleCommand ("command alias p expression --", false, result);
HandleCommand ("command alias print expression --", false, result);
HandleCommand ("command alias po expression -o --", false, result);
HandleCommand ("command alias up _regexp-up", false, result);
HandleCommand ("command alias down _regexp-down", false, result);
HandleCommand ("command alias file target create", false, result);
HandleCommand ("command alias image target modules", false, result);
CommandObjectSP cmd_obj_sp = GetCommandSPExact ("quit", false);
if (cmd_obj_sp)
{
AddAlias ("q", cmd_obj_sp);
AddAlias ("exit", cmd_obj_sp);
}
cmd_obj_sp = GetCommandSPExact ("process continue", false);
if (cmd_obj_sp)
{
AddAlias ("c", cmd_obj_sp);
AddAlias ("continue", cmd_obj_sp);
}
cmd_obj_sp = GetCommandSPExact ("_regexp-break",false);
if (cmd_obj_sp)
AddAlias ("b", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("thread backtrace", false);
if (cmd_obj_sp)
AddAlias ("bt", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("thread step-inst", false);
if (cmd_obj_sp)
AddAlias ("si", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("thread step-in", false);
if (cmd_obj_sp)
{
AddAlias ("s", cmd_obj_sp);
AddAlias ("step", cmd_obj_sp);
}
cmd_obj_sp = GetCommandSPExact ("thread step-over", false);
if (cmd_obj_sp)
{
AddAlias ("n", cmd_obj_sp);
AddAlias ("next", cmd_obj_sp);
}
cmd_obj_sp = GetCommandSPExact ("thread step-out", false);
if (cmd_obj_sp)
{
AddAlias ("f", cmd_obj_sp);
AddAlias ("finish", cmd_obj_sp);
}
cmd_obj_sp = GetCommandSPExact ("source list", false);
if (cmd_obj_sp)
{
AddAlias ("l", cmd_obj_sp);
AddAlias ("list", cmd_obj_sp);
}
cmd_obj_sp = GetCommandSPExact ("memory read", false);
if (cmd_obj_sp)
AddAlias ("x", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-up", false);
if (cmd_obj_sp)
AddAlias ("up", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-down", false);
if (cmd_obj_sp)
AddAlias ("down", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("target create", false);
if (cmd_obj_sp)
AddAlias ("file", cmd_obj_sp);
cmd_obj_sp = GetCommandSPExact ("target modules", false);
if (cmd_obj_sp)
AddAlias ("image", cmd_obj_sp);
OptionArgVectorSP alias_arguments_vector_sp (new OptionArgVector);
cmd_obj_sp = GetCommandSPExact ("expression", false);
if (cmd_obj_sp)
{
AddAlias ("expr", cmd_obj_sp);
ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
AddAlias ("p", cmd_obj_sp);
AddAlias ("print", cmd_obj_sp);
AddOrReplaceAliasOptions ("p", alias_arguments_vector_sp);
AddOrReplaceAliasOptions ("print", alias_arguments_vector_sp);
alias_arguments_vector_sp.reset (new OptionArgVector);
ProcessAliasOptionsArgs (cmd_obj_sp, "-o --", alias_arguments_vector_sp);
AddAlias ("po", cmd_obj_sp);
AddOrReplaceAliasOptions ("po", alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("process launch", false);
if (cmd_obj_sp)
{
alias_arguments_vector_sp.reset (new OptionArgVector);
ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
AddAlias ("r", cmd_obj_sp);
AddAlias ("run", cmd_obj_sp);
AddOrReplaceAliasOptions ("r", alias_arguments_vector_sp);
AddOrReplaceAliasOptions ("run", alias_arguments_vector_sp);
}
}
const char *
@ -452,6 +531,59 @@ CommandInterpreter::CommandExists (const char *cmd)
return m_command_dict.find(cmd) != m_command_dict.end();
}
bool
CommandInterpreter::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
const char *options_args,
OptionArgVectorSP &option_arg_vector_sp)
{
bool success = true;
OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
if (!options_args || (strlen (options_args) < 1))
return true;
std::string options_string (options_args);
Args args (options_args);
CommandReturnObject result;
// Check to see if the command being aliased can take any command options.
Options *options = cmd_obj_sp->GetOptions ();
if (options)
{
// See if any options were specified as part of the alias; if so, handle them appropriately.
options->NotifyOptionParsingStarting ();
args.Unshift ("dummy_arg");
args.ParseAliasOptions (*options, result, option_arg_vector, options_string);
args.Shift ();
if (result.Succeeded())
options->VerifyPartialOptions (result);
if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
{
result.AppendError ("Unable to create requested alias.\n");
return false;
}
}
if (options_string.size() > 0)
{
if (cmd_obj_sp->WantsRawCommandString ())
option_arg_vector->push_back (OptionArgPair ("<argument>",
OptionArgValue (-1,
options_string)));
else
{
int argc = args.GetArgumentCount();
for (size_t i = 0; i < argc; ++i)
if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
option_arg_vector->push_back
(OptionArgPair ("<argument>",
OptionArgValue (-1,
std::string (args.GetArgumentAtIndex (i)))));
}
}
return success;
}
bool
CommandInterpreter::AliasExists (const char *cmd)
{