From: Philippe Waroquiers Date: Sun, 10 May 2020 19:36:14 +0000 (+0200) Subject: Ensure class_alias is only used for user-defined aliases. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=57b4f16e494d8abdeb0748c69e72f911b3525b44;p=binutils-gdb.git Ensure class_alias is only used for user-defined aliases. This commit finally does the (small) change that started this patch series. It ensures that the class_alias is only used for user-defined aliases. So, the few GDB pre-defined aliases that were using the 'class_alias' class are now using a real help class, typically the class of the aliased command. gdb/ChangeLog 2020-05-15 Philippe Waroquiers * command.h (enum command_class): Improve comments, document that class_alias is for user-defined aliases, give the class name for each class, remove unused class_xdb. * cli/cli-decode.c (add_com_alias): Document THECLASS intended usage. * breakpoint.c (_initialize_breakpoint): Replace class_alias by a precise class. * infcmd.c (_initialize_infcmd): Likewise. * reverse.c (_initialize_reverse): Likewise. * stack.c (_initialize_stack): Likewise. * symfile.c (_initialize_symfile): Likewise. * tracepoint.c (_initialize_tracepoint): Likewise. gdb/testsuite/ChangeLog 2020-05-15 Philippe Waroquiers * gdb.base/alias.exp: Verify 'help aliases' shows user defined aliases. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f685addecd1..8823d23e803 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2020-05-15 Philippe Waroquiers + + * command.h (enum command_class): Improve comments, document + that class_alias is for user-defined aliases, give the class + name for each class, remove unused class_xdb. + * cli/cli-decode.c (add_com_alias): Document THECLASS intended usage. + * breakpoint.c (_initialize_breakpoint): Replace class_alias + by a precise class. + * infcmd.c (_initialize_infcmd): Likewise. + * reverse.c (_initialize_reverse): Likewise. + * stack.c (_initialize_stack): Likewise. + * symfile.c (_initialize_symfile): Likewise. + * tracepoint.c (_initialize_tracepoint): Likewise. + 2020-05-15 Philippe Waroquiers * cli/cli-decode.c (apropos_cmd): Produce output for aliases diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 480f0958769..15d76d4a9c1 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -15478,7 +15478,7 @@ A disabled breakpoint is not forgotten, but has no effect until re-enabled."), add_com_alias ("dis", "disable", class_breakpoint, 1); add_com_alias ("disa", "disable", class_breakpoint, 1); - add_cmd ("breakpoints", class_alias, disable_command, _("\ + add_cmd ("breakpoints", class_breakpoint, disable_command, _("\ Disable all or some breakpoints.\n\ Usage: disable breakpoints [BREAKPOINTNUM]...\n\ Arguments are breakpoint numbers with spaces in between.\n\ @@ -15498,7 +15498,7 @@ Also a prefix command for deletion of other GDB objects."), add_com_alias ("d", "delete", class_breakpoint, 1); add_com_alias ("del", "delete", class_breakpoint, 1); - add_cmd ("breakpoints", class_alias, delete_command, _("\ + add_cmd ("breakpoints", class_breakpoint, delete_command, _("\ Delete all or some breakpoints or auto-display expressions.\n\ Usage: delete breakpoints [BREAKPOINTNUM]...\n\ Arguments are breakpoint numbers with spaces in between.\n\ @@ -15686,10 +15686,10 @@ BREAK_ARGS_HELP ("trace") "\n\ Do \"help tracepoints\" for info on other tracepoint commands.")); set_cmd_completer (c, location_completer); - add_com_alias ("tp", "trace", class_alias, 0); - add_com_alias ("tr", "trace", class_alias, 1); - add_com_alias ("tra", "trace", class_alias, 1); - add_com_alias ("trac", "trace", class_alias, 1); + add_com_alias ("tp", "trace", class_breakpoint, 0); + add_com_alias ("tr", "trace", class_breakpoint, 1); + add_com_alias ("tra", "trace", class_breakpoint, 1); + add_com_alias ("trac", "trace", class_breakpoint, 1); c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ Set a fast tracepoint at specified location.\n\ diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 2b24e57d463..a4ef93c62b0 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1006,7 +1006,10 @@ add_com (const char *name, enum command_class theclass, return add_cmd (name, theclass, fun, doc, &cmdlist); } -/* Add an alias or abbreviation command to the list of commands. */ +/* Add an alias or abbreviation command to the list of commands. + For aliases predefined by GDB (such as bt), THECLASS must be + different of class_alias, as class_alias is used to identify + user defined aliases. */ struct cmd_list_element * add_com_alias (const char *name, const char *oldname, enum command_class theclass, diff --git a/gdb/command.h b/gdb/command.h index 0a1706c545e..04a380cba4a 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -29,21 +29,46 @@ struct completion_tracker; /* Command classes are top-level categories into which commands are broken down for "help" purposes. - Notes on classes: class_alias is for alias commands which are not - abbreviations of the original command. class-pseudo is for - commands which are not really commands nor help topics ("stop"). */ + The class_alias is used for the user-defined aliases, defined + using the "alias" command. + + Aliases pre-defined by GDB (e.g. the alias "bt" of the "backtrace" command) + are not using the class_alias. + Different pre-defined aliases of the same command do not necessarily + have the same classes. For example, class_stack is used for the + "backtrace" and its "bt" alias", while "info stack" (also an alias + of "backtrace" uses class_info. */ enum command_class { - /* Special args to help_list */ - class_deprecated = -3, all_classes = -2, all_commands = -1, + /* Classes of commands followed by a comment giving the name + to use in "help ". + Note that help accepts unambiguous abbreviated class names. */ + + /* Special classes to help_list */ + class_deprecated = -3, + all_classes = -2, /* help without */ + all_commands = -1, /* all */ + /* Classes of commands */ - no_class = -1, class_run = 0, class_vars, class_stack, class_files, - class_support, class_info, class_breakpoint, class_trace, - class_alias, class_bookmark, class_obscure, class_maintenance, - class_tui, class_user, class_xdb, - no_set_class /* Used for "show" commands that have no corresponding - "set" command. */ + no_class = -1, + class_run = 0, /* running */ + class_vars, /* data */ + class_stack, /* stack */ + class_files, /* files */ + class_support, /* support */ + class_info, /* status */ + class_breakpoint, /* breakpoints */ + class_trace, /* tracepoints */ + class_alias, /* aliases */ + class_bookmark, + class_obscure, /* obscure */ + class_maintenance, /* internals */ + class_tui, + class_user, /* user-defined */ + + /* Used for "show" commands that have no corresponding "set" command. */ + no_set_class }; /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 8b01f45828e..32905a7b591 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -3180,7 +3180,7 @@ is restored."), cmd_name = "inferior-tty"; c = lookup_cmd (&cmd_name, setlist, "", -1, 1); gdb_assert (c != NULL); - add_alias_cmd ("tty", c, class_alias, 0, &cmdlist); + add_alias_cmd ("tty", c, class_run, 0, &cmdlist); cmd_name = "args"; add_setshow_string_noescape_cmd (cmd_name, class_run, @@ -3318,14 +3318,14 @@ Step one instruction exactly.\n\ Usage: stepi [N]\n\ Argument N means step N times (or till program stops for another \ reason).")); - add_com_alias ("si", "stepi", class_alias, 0); + add_com_alias ("si", "stepi", class_run, 0); add_com ("nexti", class_run, nexti_command, _("\ Step one instruction, but proceed through subroutine calls.\n\ Usage: nexti [N]\n\ Argument N means step N times (or till program stops for another \ reason).")); - add_com_alias ("ni", "nexti", class_alias, 0); + add_com_alias ("ni", "nexti", class_run, 0); add_com ("finish", class_run, finish_command, _("\ Execute until selected stack frame returns.\n\ diff --git a/gdb/reverse.c b/gdb/reverse.c index 1ccb9d27971..583e0d02da2 100644 --- a/gdb/reverse.c +++ b/gdb/reverse.c @@ -330,7 +330,7 @@ _initialize_reverse () Step program backward until it reaches the beginning of another source line.\n\ Argument N means do this N times (or till program stops for another reason).") ); - add_com_alias ("rs", "reverse-step", class_alias, 1); + add_com_alias ("rs", "reverse-step", class_run, 1); add_com ("reverse-next", class_run, reverse_next, _("\ Step program backward, proceeding through subroutine calls.\n\ @@ -338,26 +338,26 @@ Like the \"reverse-step\" command as long as subroutine calls do not happen;\n\ when they do, the call is treated as one instruction.\n\ Argument N means do this N times (or till program stops for another reason).") ); - add_com_alias ("rn", "reverse-next", class_alias, 1); + add_com_alias ("rn", "reverse-next", class_run, 1); add_com ("reverse-stepi", class_run, reverse_stepi, _("\ Step backward exactly one instruction.\n\ Argument N means do this N times (or till program stops for another reason).") ); - add_com_alias ("rsi", "reverse-stepi", class_alias, 0); + add_com_alias ("rsi", "reverse-stepi", class_run, 0); add_com ("reverse-nexti", class_run, reverse_nexti, _("\ Step backward one instruction, but proceed through called subroutines.\n\ Argument N means do this N times (or till program stops for another reason).") ); - add_com_alias ("rni", "reverse-nexti", class_alias, 0); + add_com_alias ("rni", "reverse-nexti", class_run, 0); add_com ("reverse-continue", class_run, reverse_continue, _("\ Continue program being debugged but run it in reverse.\n\ If proceeding from breakpoint, a number N may be used as an argument,\n\ which means to set the ignore count of that breakpoint to N - 1 (so that\n\ the breakpoint won't break until the Nth time it is reached).")); - add_com_alias ("rc", "reverse-continue", class_alias, 0); + add_com_alias ("rc", "reverse-continue", class_run, 0); add_com ("reverse-finish", class_run, reverse_finish, _("\ Execute backward until just before selected stack frame is called.")); diff --git a/gdb/stack.c b/gdb/stack.c index f67a151aeee..d7e21205411 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -3485,7 +3485,7 @@ With a negative COUNT, print outermost -COUNT frames."), add_com_alias ("bt", "backtrace", class_stack, 0); - add_com_alias ("where", "backtrace", class_alias, 0); + add_com_alias ("where", "backtrace", class_stack, 0); add_info ("stack", backtrace_command, _("Backtrace of the stack, or innermost COUNT frames.")); add_info_alias ("s", "stack", 1); diff --git a/gdb/symfile.c b/gdb/symfile.c index 7c862d5513a..946443f07a8 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3906,8 +3906,8 @@ on its own."), &cmdlist); _("Commands for debugging overlays."), &overlaylist, "overlay ", 0, &cmdlist); - add_com_alias ("ovly", "overlay", class_alias, 1); - add_com_alias ("ov", "overlay", class_alias, 1); + add_com_alias ("ovly", "overlay", class_support, 1); + add_com_alias ("ov", "overlay", class_support, 1); add_cmd ("map-overlay", class_support, map_overlay_command, _("Assert that an overlay section is mapped."), &overlaylist); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index bf2b9384d26..c57ddf55cbf 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-05-15 Philippe Waroquiers + + * gdb.base/alias.exp: Verify 'help aliases' shows user defined aliases. + 2020-05-15 Philippe Waroquiers * gdb.base/help.exp: Test apropos and help for commands @@ -8,7 +12,7 @@ * gdb.base/alias.exp: Update help output check. -c2020-05-15 Philippe Waroquiers +2020-05-15 Philippe Waroquiers * gdb.base/default.exp: Update output following fixes. diff --git a/gdb/testsuite/gdb.base/alias.exp b/gdb/testsuite/gdb.base/alias.exp index 69cfde67c14..6993d426484 100644 --- a/gdb/testsuite/gdb.base/alias.exp +++ b/gdb/testsuite/gdb.base/alias.exp @@ -122,3 +122,6 @@ gdb_test_no_output "alias abcd = backtrace" gdb_test_no_output "alias abcde = backtrace" gdb_test_no_output "alias fghij = backtrace" gdb_test_no_output "alias fghi = backtrace" + +# Verify help aliases shows the user defined aliases +gdb_test "help aliases" ".*abcd --.*.*abcde --.*" diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 2e0f0df9ff4..f4a208f6169 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -4098,8 +4098,8 @@ one or more \"collect\" commands, to specify what to collect\n\ while single-stepping.\n\n\ Note: this command can only be used in a tracepoint \"actions\" list.")); - add_com_alias ("ws", "while-stepping", class_alias, 0); - add_com_alias ("stepping", "while-stepping", class_alias, 0); + add_com_alias ("ws", "while-stepping", class_trace, 0); + add_com_alias ("stepping", "while-stepping", class_trace, 0); add_com ("collect", class_trace, collect_pseudocommand, _("\ Specify one or more data items to be collected at a tracepoint.\n\