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.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@121779 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Interpreter/CommandInterpreter.cpp b/source/Interpreter/CommandInterpreter.cpp
index abd0943..8c4c884 100644
--- a/source/Interpreter/CommandInterpreter.cpp
+++ b/source/Interpreter/CommandInterpreter.cpp
@@ -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)
{