mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
cf00cd6faf
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.
106 lines
3.7 KiB
C
106 lines
3.7 KiB
C
/* GDB routines for supporting auto-loaded scripts.
|
||
|
||
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
||
|
||
This file is part of GDB.
|
||
|
||
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
|
||
the Free Software Foundation; either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
#include "defs.h"
|
||
#include "top.h"
|
||
#include "gdbcmd.h"
|
||
#include "objfiles.h"
|
||
#include "python.h"
|
||
#include "auto-load.h"
|
||
#include "python-internal.h"
|
||
|
||
/* User-settable option to enable/disable auto-loading of Python scripts:
|
||
set auto-load python-scripts on|off
|
||
This is true if we should auto-load associated Python scripts when an
|
||
objfile is opened, false otherwise. */
|
||
static bool auto_load_python_scripts = true;
|
||
|
||
/* "show" command for the auto_load_python_scripts configuration variable. */
|
||
|
||
static void
|
||
show_auto_load_python_scripts (struct ui_file *file, int from_tty,
|
||
struct cmd_list_element *c, const char *value)
|
||
{
|
||
fprintf_filtered (file, _("Auto-loading of Python scripts is %s.\n"), value);
|
||
}
|
||
|
||
/* Return non-zero if auto-loading Python scripts is enabled.
|
||
This is the extension_language_script_ops.auto_load_enabled "method". */
|
||
|
||
int
|
||
gdbpy_auto_load_enabled (const struct extension_language_defn *extlang)
|
||
{
|
||
return auto_load_python_scripts;
|
||
}
|
||
|
||
/* Wrapper for "info auto-load python-scripts". */
|
||
|
||
static void
|
||
info_auto_load_python_scripts (const char *pattern, int from_tty)
|
||
{
|
||
auto_load_info_scripts (pattern, from_tty, &extension_language_python);
|
||
}
|
||
|
||
int
|
||
gdbpy_initialize_auto_load (void)
|
||
{
|
||
struct cmd_list_element *cmd;
|
||
const char *cmd_name;
|
||
|
||
add_setshow_boolean_cmd ("python-scripts", class_support,
|
||
&auto_load_python_scripts, _("\
|
||
Set the debugger's behaviour regarding auto-loaded Python scripts."), _("\
|
||
Show the debugger's behaviour regarding auto-loaded Python scripts."), _("\
|
||
If enabled, auto-loaded Python scripts are loaded when the debugger reads\n\
|
||
an executable or shared library.\n\
|
||
This options has security implications for untrusted inferiors."),
|
||
NULL, show_auto_load_python_scripts,
|
||
auto_load_set_cmdlist_get (),
|
||
auto_load_show_cmdlist_get ());
|
||
|
||
add_setshow_boolean_cmd ("auto-load-scripts", class_support,
|
||
&auto_load_python_scripts, _("\
|
||
Set the debugger's behaviour regarding auto-loaded Python scripts, "
|
||
"deprecated."),
|
||
_("\
|
||
Show the debugger's behaviour regarding auto-loaded Python scripts, "
|
||
"deprecated."),
|
||
NULL, NULL, show_auto_load_python_scripts,
|
||
&setlist, &showlist);
|
||
cmd_name = "auto-load-scripts";
|
||
cmd = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
|
||
deprecate_cmd (cmd, "set auto-load python-scripts");
|
||
|
||
/* It is needed because lookup_cmd updates the CMD_NAME pointer. */
|
||
cmd_name = "auto-load-scripts";
|
||
cmd = lookup_cmd (&cmd_name, showlist, "", NULL, -1, 1);
|
||
deprecate_cmd (cmd, "show auto-load python-scripts");
|
||
|
||
add_cmd ("python-scripts", class_info, info_auto_load_python_scripts,
|
||
_("Print the list of automatically loaded Python scripts.\n\
|
||
Usage: info auto-load python-scripts [REGEXP]"),
|
||
auto_load_info_cmdlist_get ());
|
||
|
||
cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
|
||
Print the list of automatically loaded Python scripts, deprecated."));
|
||
deprecate_cmd (cmd, "info auto-load python-scripts");
|
||
|
||
return 0;
|
||
}
|