diff options
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-cmds.c | 25 | ||||
-rw-r--r-- | gdb/cli/cli-decode.c | 15 |
2 files changed, 31 insertions, 9 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index c17521b..8538fad 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1694,8 +1694,29 @@ alias_command (const char *args, int from_tty) /* ALIAS must not exist. */ std::string alias_string (argv_to_string (alias_argv, alias_argc)); alias = alias_string.c_str (); - if (valid_command_p (alias)) - error (_("Alias already exists: %s"), alias); + { + cmd_list_element *alias_cmd, *prefix_cmd, *cmd; + + if (lookup_cmd_composition (alias, &alias_cmd, &prefix_cmd, &cmd)) + { + const char *alias_name = alias_argv[alias_argc-1]; + + /* If we found an existing ALIAS_CMD, check that the prefix differ or + the name differ. */ + + if (alias_cmd != nullptr + && alias_cmd->prefix == prefix_cmd + && strcmp (alias_name, alias_cmd->name) == 0) + error (_("Alias already exists: %s"), alias); + + /* Check ALIAS differs from the found CMD. */ + + if (cmd->prefix == prefix_cmd + && strcmp (alias_name, cmd->name) == 0) + error (_("Alias %s is the name of an existing command"), alias); + } + } + /* If ALIAS is one word, it is an alias for the entire COMMAND. Example: alias spe = set print elements diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index d951ead..78b8901 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1843,6 +1843,8 @@ lookup_cmd_composition (const char *text, cur_list = cmdlist; + text = skip_spaces (text); + while (1) { /* Go through as many command lists as we need to, @@ -1850,9 +1852,6 @@ lookup_cmd_composition (const char *text, prev_cmd = *cmd; - while (*text == ' ' || *text == '\t') - (text)++; - /* Identify the name of the command. */ len = find_command_name_length (text); @@ -1861,7 +1860,7 @@ lookup_cmd_composition (const char *text, return 0; /* TEXT is the start of the first command word to lookup (and - it's length is len). We copy this into a local temporary. */ + it's length is LEN). We copy this into a local temporary. */ command = (char *) alloca (len + 1); memcpy (command, text, len); @@ -1890,12 +1889,14 @@ lookup_cmd_composition (const char *text, } *prefix_cmd = prev_cmd; } - if ((*cmd)->prefixlist) + + text += len; + text = skip_spaces (text); + + if ((*cmd)->prefixlist && *text != '\0') cur_list = *(*cmd)->prefixlist; else return 1; - - text += len; } } |