X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fcli%2Fcli-decode.c;h=e7b7a110fcf8f3e82ca5edc9d49958d3f24a9a9b;hb=7170dadf5950e1444ab09cdfc4e07dd2698fc275;hp=b9110976b94fcdf84fda5de1806e7371fc381231;hpb=95a6b0a106fac6ea35670421534d461a3663c0ba;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index b9110976b9..e7b7a110fc 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1,6 +1,6 @@ /* Handle lists of commands, their decoding and documentation, for GDB. - Copyright (C) 1986-2017 Free Software Foundation, Inc. + Copyright (C) 1986-2018 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -193,7 +193,8 @@ static struct cmd_list_element * do_add_cmd (const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list) { - struct cmd_list_element *c = XNEW (struct cmd_list_element); + struct cmd_list_element *c = new struct cmd_list_element (name, theclass, + doc); struct cmd_list_element *p, *iter; /* Turn each alias of the old command into an alias of the new @@ -227,34 +228,6 @@ do_add_cmd (const char *name, enum command_class theclass, p->next = c; } - c->name = name; - c->theclass = theclass; - set_cmd_context (c, NULL); - c->doc = doc; - c->cmd_deprecated = 0; - c->deprecated_warn_user = 0; - c->malloced_replacement = 0; - c->doc_allocated = 0; - c->replacement = NULL; - c->pre_show_hook = NULL; - c->hook_in = 0; - c->prefixlist = NULL; - c->prefixname = NULL; - c->allow_unknown = 0; - c->prefix = NULL; - c->abbrev_flag = 0; - set_cmd_completer (c, symbol_completer); - c->completer_handle_brkchars = NULL; - c->destroyer = NULL; - c->type = not_set_cmd; - c->var = NULL; - c->var_type = var_boolean; - c->enums = NULL; - c->user_commands = NULL; - c->cmd_pointer = NULL; - c->alias_chain = NULL; - c->suppress_notification = NULL; - return c; } @@ -278,6 +251,23 @@ add_cmd (const char *name, enum command_class theclass, return result; } +/* Add an element with a suppress notification to the LIST of commands. */ + +struct cmd_list_element * +add_cmd_suppress_notification (const char *name, enum command_class theclass, + cmd_const_cfunc_ftype *fun, const char *doc, + struct cmd_list_element **list, + int *suppress_notification) +{ + struct cmd_list_element *element; + + element = add_cmd (name, theclass, fun, doc, list); + element->suppress_notification = suppress_notification; + + return element; +} + + /* Deprecates a command CMD. REPLACEMENT is the name of the command which should be used in place of this command, or NULL if no such command exists. @@ -389,6 +379,25 @@ add_prefix_cmd (const char *name, enum command_class theclass, return c; } +/* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the + new command list element. */ + +struct cmd_list_element * +add_prefix_cmd_suppress_notification + (const char *name, enum command_class theclass, + cmd_const_cfunc_ftype *fun, + const char *doc, struct cmd_list_element **prefixlist, + const char *prefixname, int allow_unknown, + struct cmd_list_element **list, + int *suppress_notification) +{ + struct cmd_list_element *element + = add_prefix_cmd (name, theclass, fun, doc, prefixlist, + prefixname, allow_unknown, list); + element->suppress_notification = suppress_notification; + return element; +} + /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */ struct cmd_list_element * @@ -522,16 +531,20 @@ add_setshow_enum_cmd (const char *name, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, - struct cmd_list_element **show_list) + struct cmd_list_element **show_list, + void *context) { - struct cmd_list_element *c; + struct cmd_list_element *c, *show; add_setshow_cmd_full (name, theclass, var_enum, var, set_doc, show_doc, help_doc, set_func, show_func, set_list, show_list, - &c, NULL); + &c, &show); c->enums = enumlist; + + set_cmd_context (c, context); + set_cmd_context (show, context); } const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL }; @@ -841,8 +854,6 @@ delete_cmd (const char *name, struct cmd_list_element **list, *prehookee = iter->hookee_pre; if (iter->hookee_post) iter->hookee_post->hook_post = 0; - if (iter->doc && iter->doc_allocated) - xfree ((char *) iter->doc); *posthook = iter->hook_post; *posthookee = iter->hookee_post; @@ -866,7 +877,7 @@ delete_cmd (const char *name, struct cmd_list_element **list, *prevp = iter->alias_chain; } - xfree (iter); + delete iter; /* We won't see another command with the same name. */ break; @@ -922,12 +933,8 @@ add_com_suppress_notification (const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, int *suppress_notification) { - struct cmd_list_element *element; - - element = add_cmd (name, theclass, fun, doc, &cmdlist); - element->suppress_notification = suppress_notification; - - return element; + return add_cmd_suppress_notification (name, theclass, fun, doc, + &cmdlist, suppress_notification); } /* Recursively walk the commandlist structures, and print out the @@ -1084,9 +1091,9 @@ help_list (struct cmd_list_element *list, const char *cmdtype, if (len) { cmdtype1[0] = ' '; - strncpy (cmdtype1 + 1, cmdtype, len - 1); + memcpy (cmdtype1 + 1, cmdtype, len - 1); cmdtype1[len] = 0; - strncpy (cmdtype2, cmdtype, len - 1); + memcpy (cmdtype2, cmdtype, len - 1); strcpy (cmdtype2 + len - 1, " sub"); } @@ -1386,7 +1393,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, int ignore_help_classes) { char *command; - int len, tmp, nfound; + int len, nfound; struct cmd_list_element *found, *c; const char *line = *text; @@ -1590,7 +1597,6 @@ lookup_cmd (const char **line, struct cmd_list_element *list, } error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype, *line, ambbuf); - return 0; /* lint */ } } else @@ -1715,7 +1721,7 @@ lookup_cmd_composition (const char *text, struct cmd_list_element **cmd) { char *command; - int len, tmp, nfound; + int len, nfound; struct cmd_list_element *cur_list; struct cmd_list_element *prev_cmd; @@ -1816,8 +1822,6 @@ complete_on_cmdlist (struct cmd_list_element *list, && (!ignore_help_classes || ptr->func || ptr->prefixlist)) { - char *match; - if (pass == 0) { if (ptr->cmd_deprecated) @@ -1827,22 +1831,8 @@ complete_on_cmdlist (struct cmd_list_element *list, } } - match = (char *) xmalloc (strlen (word) + strlen (ptr->name) + 1); - if (word == text) - strcpy (match, ptr->name); - else if (word > text) - { - /* Return some portion of ptr->name. */ - strcpy (match, ptr->name + (word - text)); - } - else - { - /* Return some of text plus ptr->name. */ - strncpy (match, word, text - word); - match[text - word] = '\0'; - strcat (match, ptr->name); - } - tracker.add_completion (gdb::unique_xmalloc_ptr (match)); + tracker.add_completion + (make_completion_match_str (ptr->name, text, word)); got_matches = true; } @@ -1876,26 +1866,7 @@ complete_on_enum (completion_tracker &tracker, for (i = 0; (name = enumlist[i]) != NULL; i++) if (strncmp (name, text, textlen) == 0) - { - char *match; - - match = (char *) xmalloc (strlen (word) + strlen (name) + 1); - if (word == text) - strcpy (match, name); - else if (word > text) - { - /* Return some portion of name. */ - strcpy (match, name + (word - text)); - } - else - { - /* Return some of text plus name. */ - strncpy (match, word, text - word); - match[text - word] = '\0'; - strcat (match, name); - } - tracker.add_completion (gdb::unique_xmalloc_ptr (match)); - } + tracker.add_completion (make_completion_match_str (name, text, word)); }