[Lldb-commits] [lldb] r121779 - in /lldb/trunk/source: Commands/CommandObjectCommands.cpp Interpreter/CommandInterpreter.cpp
Caroline Tice
ctice at apple.com
Tue Dec 14 10:51:39 PST 2010
Author: ctice
Date: Tue Dec 14 12:51:39 2010
New Revision: 121779
URL: http://llvm.org/viewvc/llvm-project?rev=121779&view=rev
Log:
Fix small bugs:
- Make sure cmd_obj & cmd_obj_sp contain a valid objects before attempting to
dereference, in CommandObjectCommandsAlias::Execute and
CommandInterpreter::HandleCommand.
- Modify CommandInterpreter::GetCommandSPExact to properly handle
multi-word command inputs.
Modified:
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=121779&r1=121778&r2=121779&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Tue Dec 14 12:51:39 2010
@@ -359,10 +359,18 @@
}
CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
- m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp);
- if (option_arg_vector->size() > 0)
- m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ if (cmd_obj_sp)
+ {
+ m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp);
+ if (option_arg_vector->size() > 0)
+ m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ }
+ else
+ {
+ result.AppendError ("Unable to create requested alias.\n");
+ result.SetStatus (eReturnStatusFailed);
+ }
}
return result.Succeeded();
}
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=121779&r1=121778&r2=121779&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Dec 14 12:51:39 2010
@@ -314,7 +314,45 @@
CommandObjectSP
CommandInterpreter::GetCommandSPExact (const char *cmd_cstr, bool include_aliases)
{
- return GetCommandSP(cmd_cstr, include_aliases, true, NULL);
+ Args cmd_words (cmd_cstr); // Break up the command string into words, in case it's a multi-word command.
+ CommandObjectSP ret_val; // Possibly empty return value.
+
+ if (cmd_cstr == NULL)
+ return ret_val;
+
+ if (cmd_words.GetArgumentCount() == 1)
+ return GetCommandSP(cmd_cstr, include_aliases, true, NULL);
+ else
+ {
+ // We have a multi-word command (seemingly), so we need to do more work.
+ // First, get the cmd_obj_sp for the first word in the command.
+ CommandObjectSP cmd_obj_sp = GetCommandSP (cmd_words.GetArgumentAtIndex (0), include_aliases, true, NULL);
+ if (cmd_obj_sp.get() != NULL)
+ {
+ // Loop through the rest of the words in the command (everything passed in was supposed to be part of a
+ // command name), and find the appropriate sub-command SP for each command word....
+ size_t end = cmd_words.GetArgumentCount();
+ for (size_t j= 1; j < end; ++j)
+ {
+ if (cmd_obj_sp->IsMultiwordObject())
+ {
+ cmd_obj_sp = ((CommandObjectMultiword *) cmd_obj_sp.get())->GetSubcommandSP
+ (cmd_words.GetArgumentAtIndex (j));
+ if (cmd_obj_sp.get() == NULL)
+ // The sub-command name was invalid. Fail and return the empty 'ret_val'.
+ return ret_val;
+ }
+ else
+ // We have more words in the command name, but we don't have a multiword object. Fail and return
+ // empty 'ret_val'.
+ return ret_val;
+ }
+ // We successfully looped through all the command words and got valid command objects for them. Assign the
+ // last object retrieved to 'ret_val'.
+ ret_val = cmd_obj_sp;
+ }
+ }
+ return ret_val;
}
CommandObject *
@@ -720,8 +758,10 @@
BuildAliasResult (next_word.c_str(), command_string, alias_result, cmd_obj, result);
revised_command_line.Printf ("%s", alias_result.c_str());
if (cmd_obj)
+ {
wants_raw_input = cmd_obj->WantsRawCommandString ();
- actual_cmd_name_len = strlen (cmd_obj->GetCommandName());
+ actual_cmd_name_len = strlen (cmd_obj->GetCommandName());
+ }
}
else if (!cmd_obj)
{
More information about the lldb-commits
mailing list