binutils-gdb/gdb/python
Philippe Waroquiers cf00cd6faf default-args: allow to define default arguments for aliases
Currently, a user can define an alias, but cannot have default
arguments for this alias.

This patch modifies the 'alias' command so that default args can
be provided.
    (gdb) h alias
    Define a new command that is an alias of an existing command.
    Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]
    ALIAS is the name of the alias command to create.
    COMMAND is the command being aliased to.

    Options:
      -a
        Specify that ALIAS is an abbreviation of COMMAND.
        Abbreviations are not used in command completion..

    GDB will automatically prepend the provided DEFAULT-ARGS to the list
    of arguments explicitly provided when using ALIAS.
    Use "help aliases" to list all user defined aliases and their default args.

    Examples:
    Make "spe" an alias of "set print elements":
      alias spe set print elements
    Make "elms" an alias of "elements" in the "set print" command:
      alias -a set print elms set print elements
    Make "btf" an alias of "backtrace -full -past-entry -past-main" :
      alias btf = backtrace -full -past-entry -past-main
    Make "wLapPeu" an alias of 2 nested "with":
      alias wLapPeu = with language pascal -- with print elements unlimited --
    (gdb)

The way 'default-args' is implemented makes it trivial to set default
args also for GDB commands (such as "backtrace") and for GDB pre-defined
aliases (such as "bt").  It was however deemed better to not allow to
define default arguments for pre-defined commands and aliases, to avoid
users believing that e.g. default args for "backtrace" would apply to "bt".

If needed, default-args could be allowed for GDB predefined commands
and aliases by adding a command
'set default-args GDB_COMMAND_OR_PREDEFINED_ALIAS [DEFAULT-ARGS...]'.

* 'alias' command now has a completer that helps to complete:
     - ALIAS (if the user defines an alias after a prefix),
     - the aliased COMMAND
     - the possible options for the aliased COMMAND.

* Help and apropos commands show the definitions of the aliases
  that have default arguments, e.g.
        (gdb) help backtrace
        backtrace, btf, where, bt
          alias btf = backtrace -full -past-entry -past-main
        Print backtrace of all stack frames, or innermost COUNT frames.
        Usage: backtrace [OPTION]... [QUALIFIER]... [COUNT | -COUNT]

        Options:
          -entry-values no|only|preferred|if-needed|both|compact|default
            Set printing of function arguments at function entry.
        ...

gdb/ChangeLog
2020-06-22  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-cmds.c (lookup_cmd_for_default_args)
	(alias_command_completer)
	(make_alias_options_def_group): New functions.
	(alias_opts, alias_option_defs): New struct and array.
	(alias_usage_error): Update usage.
	(alias_command): Handles optional DEFAULT-ARGS... arguments.
	Use option framework.
	(_initialize_cli_cmds): Update alias command help.
	Update aliases command help.
	(show_user):
	Add NULL for new default_args lookup_cmd argument.
	(valid_command_p): Rename to validate_aliased_command.
	Add NULL for new default_args lookup_cmd argument.  Verify that the
	aliased_command has no default args.
	* cli/cli-decode.c (help_cmd): Show aliases definitions.
	(lookup_cmd_1, lookup_cmd): New argument default_args.
	(add_alias_cmd):
	Add NULL for new default_args lookup_cmd argument.
	(print_help_for_command): Show default args under the layout
	 alias some_alias = some_aliased_cmd some_alias_default_arg.
	* cli/cli-decode.h (struct cmd_list_element): New member default_args.
	xfree default_args in destructor.
	* cli/cli-script.c (process_next_line, do_define_command):
	Add NULL for new default_args lookup_cmd argument.
	* command.h: Declare new default_args argument in lookup_cmd
	and lookup_cmd_1.
	* completer.c (complete_line_internal_1):
	Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
	* guile/scm-cmd.c (gdbscm_parse_command_name): Likewise.
	* guile/scm-param.c (add_setshow_generic, pascm_parameter_defined_p):
	Likewise.
	* infcmd.c (_initialize_infcmd): Likewise.
	* python/py-auto-load.c (gdbpy_initialize_auto_load): Likewise.
	* python/py-cmd.c (gdbpy_parse_command_name): Likewise.
	* python/py-param.c (add_setshow_generic): Likewise.
	* remote.c (_initialize_remote): Likewise.
	* top.c (execute_command): Prepend default_args if command has some.
	(set_verbose):
	Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
	* tracepoint.c (validate_actionline, encode_actions_1):
	Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
2020-06-22 21:14:13 +02:00
..
lib/gdb [gdb/cli] Don't let python colorize strip leading newlines 2020-04-10 09:29:52 +02:00
py-all-events.def Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-arch.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-auto-load.c default-args: allow to define default arguments for aliases 2020-06-22 21:14:13 +02:00
py-block.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-bpevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-breakpoint.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-cmd.c default-args: allow to define default arguments for aliases 2020-06-22 21:14:13 +02:00
py-continueevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-event-types.def Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-event.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-event.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-events.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-evtregistry.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-evts.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-exitedevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-finishbreakpoint.c gdb: remove TYPE_CODE macro 2020-05-14 13:46:38 -04:00
py-frame.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-framefilter.c gdb: remove TYPE_CODE macro 2020-05-14 13:46:38 -04:00
py-function.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-gdb-readline.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-inferior.c Change get_objfile_arch to a method on objfile 2020-04-18 08:35:04 -06:00
py-infevents.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-infthread.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-instruction.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-instruction.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-lazy-string.c gdb: remove TYPE_CODE macro 2020-05-14 13:46:38 -04:00
py-linetable.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-newobjfileevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-objfile.c Change get_objfile_arch to a method on objfile 2020-04-18 08:35:04 -06:00
py-param.c default-args: allow to define default arguments for aliases 2020-06-22 21:14:13 +02:00
py-prettyprint.c Change extension language pretty-printers to use value API 2020-03-13 18:03:42 -06:00
py-progspace.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record-btrace.c Fix some spelling errors. 2020-01-16 16:46:25 -06:00
py-record-btrace.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record-full.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record-full.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-ref.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-signalevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-stopevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-stopevent.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-symbol.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-symtab.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-threadevent.c Multi-target support 2020-01-10 20:06:08 +00:00
py-tui.c Fix crash when TUI window creation fails 2020-06-16 17:48:38 -06:00
py-type.c gdb: remove TYPE_FIELD_TYPE macro 2020-06-08 15:26:31 -04:00
py-unwind.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-utils.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-value.c gdb: remove TYPE_CODE macro 2020-05-14 13:46:38 -04:00
py-varobj.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-xmethods.c gdb: remove TYPE_CODE macro 2020-05-14 13:46:38 -04:00
python-config.py configure uses incorrect link order when testing libpython 2018-05-04 10:08:09 -04:00
python-internal.h Change extension language pretty-printers to use value API 2020-03-13 18:03:42 -06:00
python.c Fix Python3.9 related runtime problems 2020-05-28 12:46:16 -07:00
python.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00