* NEWS: Mention new python command class gdb.COMMAND_USER.

* cli/cli-cmds.c (show_user): Print error when used on a python
	command.
	(init_cli_cmds): Update documentation strings for "show user" and
	"set/show max-user-call-depth" to clarify that it does not apply to
	python commands.
	* python/py-cmd.c (cmdpy_init): Treat class_user as a valid class in
	error check.
	(gdbpy_initialize_commands): Add COMMAND_USER as a constant in
	gdb python api.
	* top.c (execute_command): Only execute a user-defined command as a
	legacy macro if c->user_commands is set.

	doc/
	* gdb.texinfo (Commands In Python): Put example python macro in
	COMMAND_USER category rather than COMMAND_OBSCURE.
	Document gdb.COMMAND_USER.
	(User-defined Commands): Update documentation to clarify
	"set/show max-user-call-depth" and "show user" don't apply to python
	commands.  Update documentation to clarify "help user-defined" may
	also include python commands defined as COMMAND_USER.

	testsuite/
	* gdb.python/py-cmd.exp: Add test to verify that python commands can
	be put in the user-defined category and that the commands appear in
	"help user-defined".
This commit is contained in:
Doug Evans
2012-03-01 19:30:25 +00:00
parent e88acd9618
commit 7d74f2446c
9 changed files with 77 additions and 11 deletions

View File

@@ -1,3 +1,18 @@
2012-03-01 Scott J. Goldman <scottjg@vmware.com>
* NEWS: Mention new python command class gdb.COMMAND_USER.
* cli/cli-cmds.c (show_user): Print error when used on a python
command.
(init_cli_cmds): Update documentation strings for "show user" and
"set/show max-user-call-depth" to clarify that it does not apply to
python commands.
* python/py-cmd.c (cmdpy_init): Treat class_user as a valid class in
error check.
(gdbpy_initialize_commands): Add COMMAND_USER as a constant in
gdb python api.
* top.c (execute_command): Only execute a user-defined command as a
legacy macro if c->user_commands is set.
2012-03-01 Tom Tromey <tromey@redhat.com> 2012-03-01 Tom Tromey <tromey@redhat.com>
* valprint.h (struct generic_val_print_decorations): New. * valprint.h (struct generic_val_print_decorations): New.

View File

@@ -5,6 +5,9 @@
* Python scripting * Python scripting
** GDB commands implemented in Python can now be put in command class
"gdb.COMMAND_USER".
** The "maint set python print-stack on|off" is now deleted. ** The "maint set python print-stack on|off" is now deleted.
** A new class, gdb.printing.FlagEnumerationPrinter, can be used to ** A new class, gdb.printing.FlagEnumerationPrinter, can be used to

View File

@@ -1241,7 +1241,8 @@ show_user (char *args, int from_tty)
char *comname = args; char *comname = args;
c = lookup_cmd (&comname, cmdlist, "", 0, 1); c = lookup_cmd (&comname, cmdlist, "", 0, 1);
if (c->class != class_user) /* c->user_commands would be NULL if it's a python command. */
if (c->class != class_user || !c->user_commands)
error (_("Not a user command.")); error (_("Not a user command."));
show_user_1 (c, "", args, gdb_stdout); show_user_1 (c, "", args, gdb_stdout);
} }
@@ -1912,7 +1913,7 @@ Two arguments (separated by a comma) are taken as a range of memory to dump,\n\
Run the ``make'' program using the rest of the line as arguments.")); Run the ``make'' program using the rest of the line as arguments."));
set_cmd_completer (c, filename_completer); set_cmd_completer (c, filename_completer);
add_cmd ("user", no_class, show_user, _("\ add_cmd ("user", no_class, show_user, _("\
Show definitions of user defined commands.\n\ Show definitions of non-python user defined commands.\n\
Argument is the name of the user defined command.\n\ Argument is the name of the user defined command.\n\
With no argument, show definitions of all user defined commands."), &showlist); With no argument, show definitions of all user defined commands."), &showlist);
add_com ("apropos", class_support, apropos_command, add_com ("apropos", class_support, apropos_command,
@@ -1920,8 +1921,8 @@ With no argument, show definitions of all user defined commands."), &showlist);
add_setshow_integer_cmd ("max-user-call-depth", no_class, add_setshow_integer_cmd ("max-user-call-depth", no_class,
&max_user_call_depth, _("\ &max_user_call_depth, _("\
Set the max call depth for user-defined commands."), _("\ Set the max call depth for non-python user-defined commands."), _("\
Show the max call depth for user-defined commands."), NULL, Show the max call depth for non-python user-defined commands."), NULL,
NULL, NULL,
show_max_user_call_depth, show_max_user_call_depth,
&setlist, &showlist); &setlist, &showlist);

View File

@@ -1,3 +1,13 @@
2012-03-01 Scott J. Goldman <scottjg@vmware.com>
* gdb.texinfo (Commands In Python): Put example python macro in
COMMAND_USER category rather than COMMAND_OBSCURE.
Document gdb.COMMAND_USER.
(User-defined Commands): Update documentation to clarify
"set/show max-user-call-depth" and "show user" don't apply to python
commands. Update documentation to clarify "help user-defined" may
also include python commands defined as COMMAND_USER.
2012-02-25 Jan Kratochvil <jan.kratochvil@redhat.com> 2012-02-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (Startup): Add option -ex description to the option -x * gdb.texinfo (Startup): Add option -ex description to the option -x

View File

@@ -21133,8 +21133,9 @@ command should not be repeated when the user hits @key{RET}
@kindex help user-defined @kindex help user-defined
@item help user-defined @item help user-defined
List all user-defined commands, with the first line of the documentation List all user-defined commands and all python commands defined in class
(if any) for each. COMAND_USER. The first line of the documentation or docstring is
included (if any).
@kindex show user @kindex show user
@item show user @item show user
@@ -21142,6 +21143,7 @@ List all user-defined commands, with the first line of the documentation
Display the @value{GDBN} commands used to define @var{commandname} (but Display the @value{GDBN} commands used to define @var{commandname} (but
not its documentation). If no @var{commandname} is given, display the not its documentation). If no @var{commandname} is given, display the
definitions for all user-defined commands. definitions for all user-defined commands.
This does not work for user-defined python commands.
@cindex infinite recursion in user-defined commands @cindex infinite recursion in user-defined commands
@kindex show max-user-call-depth @kindex show max-user-call-depth
@@ -21151,6 +21153,7 @@ definitions for all user-defined commands.
The value of @code{max-user-call-depth} controls how many recursion The value of @code{max-user-call-depth} controls how many recursion
levels are allowed in user-defined commands before @value{GDBN} suspects an levels are allowed in user-defined commands before @value{GDBN} suspects an
infinite recursion and aborts the command. infinite recursion and aborts the command.
This does not apply to user-defined python commands.
@end table @end table
In addition to the above commands, user-defined commands frequently In addition to the above commands, user-defined commands frequently
@@ -21951,7 +21954,7 @@ to handle this case. Example:
>class HelloWorld (gdb.Command): >class HelloWorld (gdb.Command):
> """Greet the whole world.""" > """Greet the whole world."""
> def __init__ (self): > def __init__ (self):
> super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE) > super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
> def invoke (self, args, from_tty): > def invoke (self, args, from_tty):
> argv = gdb.string_to_argv (args) > argv = gdb.string_to_argv (args)
> if len (argv) != 0: > if len (argv) != 0:
@@ -23330,6 +23333,15 @@ The command has to do with tracepoints. For example, @code{trace},
@kbd{help tracepoints} at the @value{GDBN} prompt to see a list of @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
commands in this category. commands in this category.
@findex COMMAND_USER
@findex gdb.COMMAND_USER
@item gdb.COMMAND_USER
The command is a general purpose command for the user, and typically
does not fit in one of the other categories.
Type @kbd{help user-defined} at the @value{GDBN} prompt to see
a list of commands in this category, as well as the list of gdb macros
(@pxref{Sequences}).
@findex COMMAND_OBSCURE @findex COMMAND_OBSCURE
@findex gdb.COMMAND_OBSCURE @findex gdb.COMMAND_OBSCURE
@item gdb.COMMAND_OBSCURE @item gdb.COMMAND_OBSCURE
@@ -23391,7 +23403,7 @@ class HelloWorld (gdb.Command):
"""Greet the whole world.""" """Greet the whole world."""
def __init__ (self): def __init__ (self):
super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE) super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
def invoke (self, arg, from_tty): def invoke (self, arg, from_tty):
print "Hello, World!" print "Hello, World!"

View File

@@ -436,7 +436,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
&& cmdtype != class_files && cmdtype != class_support && cmdtype != class_files && cmdtype != class_support
&& cmdtype != class_info && cmdtype != class_breakpoint && cmdtype != class_info && cmdtype != class_breakpoint
&& cmdtype != class_trace && cmdtype != class_obscure && cmdtype != class_trace && cmdtype != class_obscure
&& cmdtype != class_maintenance) && cmdtype != class_maintenance && cmdtype != class_user)
{ {
PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument.")); PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
return -1; return -1;
@@ -578,7 +578,8 @@ gdbpy_initialize_commands (void)
|| PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE", || PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE",
class_obscure) < 0 class_obscure) < 0
|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE", || PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE",
class_maintenance) < 0) class_maintenance) < 0
|| PyModule_AddIntConstant (gdb_module, "COMMAND_USER", class_user) < 0)
return; return;
for (i = 0; i < N_COMPLETERS; ++i) for (i = 0; i < N_COMPLETERS; ++i)

View File

@@ -1,3 +1,9 @@
2012-03-01 Scott J. Goldman <scottjg@vmware.com>
* gdb.python/py-cmd.exp: Add test to verify that python commands can
be put in the user-defined category and that the commands appear in
"help user-defined".
2012-02-29 Joel Brobecker <brobecker@adacore.com> 2012-02-29 Joel Brobecker <brobecker@adacore.com>
* gdb.ada/tagged_not_init: New testcase. * gdb.ada/tagged_not_init: New testcase.

View File

@@ -138,3 +138,20 @@ gdb_test "python print gdb.string_to_argv ('\"1 2\" 3')" \
gdb_test "python print gdb.string_to_argv ('1\\ 2 3')" \ gdb_test "python print gdb.string_to_argv ('1\\ 2 3')" \
{\['1 2', '3'\]} \ {\['1 2', '3'\]} \
"string_to_argv ('1\\ 2 3')" "string_to_argv ('1\\ 2 3')"
# Test user-defined python commands.
gdb_py_test_multiple "input simple user-defined command" \
"python" "" \
"class test_help (gdb.Command):" "" \
" \"\"\"Docstring\"\"\"" "" \
" def __init__ (self):" "" \
" super (test_help, self).__init__ (\"test_help\", gdb.COMMAND_USER)" "" \
" def invoke (self, arg, from_tty):" "" \
" print \"test_cmd output, arg = %s\" % arg" "" \
"test_help ()" "" \
"end" ""
gdb_test "test_help ugh" "test_cmd output, arg = ugh" "call simple user-defined command"
# Make sure the command shows up in `help user-defined`.
gdb_test "help user-defined" "User-defined commands.\[\r\n\]+The commands in this class are those defined by the user.\[\r\n\]+Use the \"define\" command to define a command.\[\r\n\]+\[\r\n\]+List of commands:\[\r\n\]+\[\r\n\]+test_help -- Docstring\[\r\n\]+\[\r\n\]+Type \"help\" followed by command name for full documentation.\[\r\n\]+Type \"apropos word\" to search for commands related to \"word\".\[\r\n\]+Command name abbreviations are allowed if unambiguous.\[\r\n\]+" "see user-defined command in `help user-defined`"

View File

@@ -470,7 +470,8 @@ execute_command (char *p, int from_tty)
if (c->flags & DEPRECATED_WARN_USER) if (c->flags & DEPRECATED_WARN_USER)
deprecated_cmd_warning (&line); deprecated_cmd_warning (&line);
if (c->class == class_user) /* c->user_commands would be NULL in the case of a python command. */
if (c->class == class_user && c->user_commands)
execute_user_command (c, arg); execute_user_command (c, arg);
else if (c->type == set_cmd || c->type == show_cmd) else if (c->type == set_cmd || c->type == show_cmd)
do_setshow_command (arg, from_tty, c); do_setshow_command (arg, from_tty, c);