From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6613 invoked by alias); 24 Feb 2012 23:22:37 -0000 Received: (qmail 6584 invoked by uid 22791); 24 Feb 2012 23:22:30 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,TW_MD,TW_RG,TW_SJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-outbound-1.vmware.com (HELO smtp-outbound-1.vmware.com) (208.91.2.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Feb 2012 23:22:12 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 15341285DA; Fri, 24 Feb 2012 15:22:11 -0800 (PST) Received: from sc9-exht08.vmware.com (sc9-exht08.vmware.com [10.113.190.38]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 0F44DB03BC; Fri, 24 Feb 2012 15:22:11 -0800 (PST) Received: from exch-mbx-111.vmware.com ([10.113.190.111]) by sc9-exht08.vmware.com ([10.113.190.38]) with mapi; Fri, 24 Feb 2012 15:22:11 -0800 From: Scott Goldman To: "gdb-patches@sourceware.org" CC: Phil Muldoon , "eliz@gnu.org" , Doug Evans Date: Fri, 24 Feb 2012 23:49:00 -0000 Subject: RE: [PATCH] Allow user-defined as a category for python gdb macros (resend) Message-ID: <03E840D17E263A48A5766AD576E0423A03DAB7B84A@exch-mbx-111.vmware.com> References: <03E840D17E263A48A5766AD576E0423A03D72B653F@exch-mbx-111.vmware.com> <4F3A5820.3080905@redhat.com> <03E840D17E263A48A5766AD576E0423A03D72B6547@exch-mbx-111.vmware.com> <03E840D17E263A48A5766AD576E0423A03DAB7AED1@exch-mbx-111.vmware.com>,,<03E840D17E263A48A5766AD576E0423A03D72B6554@exch-mbx-111.vmware.com> <03E840D17E263A48A5766AD576E0423A03D72B6555@exch-mbx-111.vmware.com> In-Reply-To: <03E840D17E263A48A5766AD576E0423A03D72B6555@exch-mbx-111.vmware.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-02/txt/msg00597.txt.bz2 Ping. I think all the reviewers (Phil, Doug, Eli) were ok with this most recent r= evision based on the comments. I would be happy to do further cleanup if ne= cessary. Otherwise, could this committed whenever someone gets a chance? thanks! -sjg > -----Original Message----- > From: Scott Goldman > Sent: Wednesday, February 22, 2012 11:52 PM > To: Doug Evans > Cc: Phil Muldoon; eliz@gnu.org; gdb-patches@sourceware.org > Subject: RE: [PATCH] Allow user-defined as a category for python gdb > macros (resend) >=20 > > Hi Doug. > > > >> Have you tested this? And is the entire docstring printed or just > the > >> first line? > >> [Guessing, I think it'll be just the first line, in which case I'd > >> reword that and just say the first line of the documentation or > >> docstring is included (if any). Or whatever.] > > > > I verified it, and you were right. I adjusted the documentation as > per your suggestion. All the python commands we're using currently have > one line docstrings, so it didn't even occur to me. >=20 > Err.. on second thought, I like Doug's wording better. >=20 > thanks, > -sjg > -- > gdb/doc/ChangeLog > 2012-02-15 Scott J. Goldman >=20 > * gdb.texinfo (Commands In Python): Put example python macro in > COMMAND_USER category rather than COMMAND_OBSCURE. > (User-defined Commands) : Update documentation to clarify > `set/show max-user-call-depth` and `show user` don't apply to > python > commands. > (User-defined Commands) : Update documentation to clarify > `help user-defined` may also include python commands defined as > COMMAND_USER >=20 > gdb/ChangLog > 2012-02-15 Scott J. Goldman >=20 > * 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. >=20 > gdb/testsuite/ChangeLog > 2012-02-15 Scott J. Goldman >=20 > * 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`. >=20 > diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c > index 983f017..49808b6 100644 > --- a/gdb/cli/cli-cmds.c > +++ b/gdb/cli/cli-cmds.c > @@ -1241,7 +1241,8 @@ show_user (char *args, int from_tty) > char *comname =3D args; >=20 > c =3D lookup_cmd (&comname, cmdlist, "", 0, 1); > - if (c->class !=3D class_user) > + /* c->user_commands would be NULL if it's a python command */ > + if (c->class !=3D class_user || !c->user_commands) > error (_("Not a user command.")); > 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.")); > set_cmd_completer (c, filename_completer); > 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\ > With no argument, show definitions of all user defined commands."), > &showlist); > add_com ("apropos", class_support, apropos_command, > @@ -1920,8 +1921,8 @@ With no argument, show definitions of all user > defined commands."), &showlist); >=20 > add_setshow_integer_cmd ("max-user-call-depth", no_class, > &max_user_call_depth, _("\ > -Set the max call depth for user-defined commands."), _("\ > -Show the max call depth for user-defined commands."), NULL, > +Set the max call depth for non-python user-defined commands."), _("\ > +Show the max call depth for non-python user-defined commands."), NULL, > NULL, > show_max_user_call_depth, > &setlist, &showlist); > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 9edc6ad..eee343a 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -21053,15 +21053,18 @@ command should not be repeated when the user > hits @key{RET} >=20 > @kindex help user-defined > @item help user-defined > -List all user-defined commands, with the first line of the > documentation > -(if any) for each. > +List all user-defined commands and all python commands defined in > class > +COMAND_USER. The first line of the documentation or docstring is > +included (if any). >=20 > @kindex show user > @item show user > @itemx show user @var{commandname} > Display the @value{GDBN} commands used to define @var{commandname} > (but > 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. >=20 > @cindex infinite recursion in user-defined commands > @kindex show max-user-call-depth > @@ -21070,7 +21073,8 @@ definitions for all user-defined commands. > @itemx set max-user-call-depth > The value of @code{max-user-call-depth} controls how many recursion > 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 >=20 > In addition to the above commands, user-defined commands frequently > @@ -21871,7 +21875,7 @@ to handle this case. Example: > >class HelloWorld (gdb.Command): > > """Greet the whole world.""" > > 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): > > argv =3D gdb.string_to_argv (args) > > if len (argv) !=3D 0: > @@ -23311,7 +23315,7 @@ class HelloWorld (gdb.Command): > """Greet the whole world.""" >=20 > def __init__ (self): > - super (HelloWorld, self).__init__ ("hello-world", > gdb.COMMAND_OBSCURE) > + super (HelloWorld, self).__init__ ("hello-world", > gdb.COMMAND_USER) >=20 > def invoke (self, arg, from_tty): > print "Hello, World!" > diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c > index aad1ab4..04476db 100644 > --- a/gdb/python/py-cmd.c > +++ b/gdb/python/py-cmd.c > @@ -436,7 +436,7 @@ cmdpy_init (PyObject *self, PyObject *args, > PyObject *kw) > && cmdtype !=3D class_files && cmdtype !=3D class_support > && cmdtype !=3D class_info && cmdtype !=3D class_breakpoint > && cmdtype !=3D class_trace && cmdtype !=3D class_obscure > - && cmdtype !=3D class_maintenance) > + && cmdtype !=3D class_maintenance && cmdtype !=3D class_user) > { > PyErr_Format (PyExc_RuntimeError, _("Invalid command class > argument.")); > return -1; > @@ -578,7 +578,8 @@ gdbpy_initialize_commands (void) > || PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE", > class_obscure) < 0 > || PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE", > - class_maintenance) < 0) > + class_maintenance) < 0 > + || PyModule_AddIntConstant (gdb_module, "COMMAND_USER", > class_user) < 0) > return; >=20 > for (i =3D 0; i < N_COMPLETERS; ++i) > diff --git a/gdb/testsuite/gdb.python/py-cmd.exp > b/gdb/testsuite/gdb.python/py-cmd.exp > index fc7cac0..36fa343 100644 > --- a/gdb/testsuite/gdb.python/py-cmd.exp > +++ b/gdb/testsuite/gdb.python/py-cmd.exp > @@ -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')" \ > {\['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 =3D %s\" % arg" "" \ > + "test_help ()" "" \ > + "end" "" > + > +gdb_test "test_help ugh" "test_cmd output, arg =3D 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`" > diff --git a/gdb/top.c b/gdb/top.c > index e41f56c..e73a772 100644 > --- a/gdb/top.c > +++ b/gdb/top.c > @@ -470,7 +470,8 @@ execute_command (char *p, int from_tty) > if (c->flags & DEPRECATED_WARN_USER) > deprecated_cmd_warning (&line); >=20 > - if (c->class =3D=3D class_user) > + /* c->user_commands would be NULL in the case of a python > command. */ > + if (c->class =3D=3D class_user && c->user_commands) > execute_user_command (c, arg); > else if (c->type =3D=3D set_cmd || c->type =3D=3D show_cmd) > do_setshow_command (arg, from_tty, c);