[Lldb-commits] [lldb] r131020 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h source/Commands/CommandObjectCommands.cpp source/Interpreter/CommandInterpreter.cpp
Caroline Tice
ctice at apple.com
Fri May 6 14:42:20 PDT 2011
Author: ctice
Date: Fri May 6 16:37:15 2011
New Revision: 131020
URL: http://llvm.org/viewvc/llvm-project?rev=131020&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=131020&r1=131019&r2=131020&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Fri May 6 16:37:15 2011
@@ -90,6 +90,12 @@
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);
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=131020&r1=131019&r2=131020&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Fri May 6 16:37:15 2011
@@ -351,33 +351,13 @@
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 @@
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 @@
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.
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=131020&r1=131019&r2=131020&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Fri May 6 16:37:15 2011
@@ -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 @@
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 *
@@ -453,6 +532,59 @@
}
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)
{
return m_alias_dict.find(cmd) != m_alias_dict.end();
More information about the lldb-commits
mailing list