diff options
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-decode.c | 15 | ||||
-rw-r--r-- | gdb/cli/cli-script.c | 23 |
2 files changed, 21 insertions, 17 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 99bd4c6..f48a9ad 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1875,6 +1875,21 @@ lookup_cmd (const char **line, struct cmd_list_element *list, return 0; } +/* See command.h. */ + +struct cmd_list_element * +lookup_cmd_exact (const char *name, + struct cmd_list_element *list, + bool ignore_help_classes) +{ + const char *tem = name; + struct cmd_list_element *cmd = lookup_cmd (&tem, list, "", NULL, -1, + ignore_help_classes); + if (cmd != nullptr && strcmp (name, cmd->name) != 0) + cmd = nullptr; + return cmd; +} + /* We are here presumably because an alias or command in TEXT is deprecated and a warning message should be generated. This function decodes TEXT and potentially generates a warning message diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 9d0dd77..0544f3e 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1391,7 +1391,7 @@ do_define_command (const char *comname, int from_tty, CMD_POST_HOOK }; struct cmd_list_element *c, *newc, *hookc = 0, **list; - const char *tem, *comfull; + const char *comfull; int hook_type = CMD_NO_HOOK; int hook_name_size = 0; @@ -1403,11 +1403,7 @@ do_define_command (const char *comname, int from_tty, comfull = comname; list = validate_comname (&comname); - /* Look it up, and verify that we got an exact match. */ - tem = comname; - c = lookup_cmd (&tem, *list, "", NULL, -1, 1); - if (c && strcmp (comname, c->name) != 0) - c = 0; + c = lookup_cmd_exact (comname, *list); if (c && commands == nullptr) { @@ -1448,11 +1444,9 @@ do_define_command (const char *comname, int from_tty, if (hook_type != CMD_NO_HOOK) { - /* Look up cmd it hooks, and verify that we got an exact match. */ - tem = comname + hook_name_size; - hookc = lookup_cmd (&tem, *list, "", NULL, -1, 0); - if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0) - hookc = 0; + /* Look up cmd it hooks. */ + hookc = lookup_cmd_exact (comname + hook_name_size, *list, + /* ignore_help_classes = */ false); if (!hookc && commands == nullptr) { warning (_("Your new `%s' command does not " @@ -1593,17 +1587,12 @@ static void define_prefix_command (const char *comname, int from_tty) { struct cmd_list_element *c, **list; - const char *tem; const char *comfull; comfull = comname; list = validate_comname (&comname); - /* Look it up, and verify that we got an exact match. */ - tem = comname; - c = lookup_cmd (&tem, *list, "", NULL, -1, 1); - if (c != nullptr && strcmp (comname, c->name) != 0) - c = nullptr; + c = lookup_cmd_exact (comname, *list); if (c != nullptr && c->theclass != class_user) error (_("Command \"%s\" is built-in."), comfull); |