From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28685 invoked by alias); 1 Mar 2012 19:31:30 -0000 Received: (qmail 28670 invoked by uid 22791); 1 Mar 2012 19:31:26 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,TW_MD,TW_RG,TW_SJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-yw0-f41.google.com (HELO mail-yw0-f41.google.com) (209.85.213.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Mar 2012 19:31:11 +0000 Received: by yhr47 with SMTP id 47so550287yhr.0 for ; Thu, 01 Mar 2012 11:31:10 -0800 (PST) Received-SPF: pass (google.com: domain of dje@google.com designates 10.60.28.229 as permitted sender) client-ip=10.60.28.229; Authentication-Results: mr.google.com; spf=pass (google.com: domain of dje@google.com designates 10.60.28.229 as permitted sender) smtp.mail=dje@google.com; dkim=pass header.i=dje@google.com Received: from mr.google.com ([10.60.28.229]) by 10.60.28.229 with SMTP id e5mr2790397oeh.63.1330630270826 (num_hops = 1); Thu, 01 Mar 2012 11:31:10 -0800 (PST) Received: by 10.60.28.229 with SMTP id e5mr2358393oeh.63.1330630270752; Thu, 01 Mar 2012 11:31:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.60.28.229 with SMTP id e5mr2358380oeh.63.1330630270550; Thu, 01 Mar 2012 11:31:10 -0800 (PST) Received: by 10.182.66.14 with HTTP; Thu, 1 Mar 2012 11:31:10 -0800 (PST) In-Reply-To: <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> <03E840D17E263A48A5766AD576E0423A03DAB7B84A@exch-mbx-111.vmware.com> Date: Thu, 01 Mar 2012 19:31:00 -0000 Message-ID: Subject: Re: [PATCH] Allow user-defined as a category for python gdb macros (resend) From: Doug Evans To: Scott Goldman Cc: "gdb-patches@sourceware.org" , Phil Muldoon , "eliz@gnu.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-Gm-Message-State: ALoCoQnNGAHBYwtAJUkimHbC9KMs9rGvAjRAx2k6clCiM5xsmF48p9ooehXklZWq30AJMlzreE2RXY5yBsIIsM7Vycp09rrYrWUuBPTQ/gQFXXLgTwFSbPZH8cUekxWXmnuKnhsKTakbVhce7H5VumqBV9jI6vtbXg== X-IsSubscribed: yes 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-03/txt/msg00038.txt.bz2 Hi. Committed. On Fri, Feb 24, 2012 at 3:22 PM, Scott Goldman wrote: > Ping. > > I think all the reviewers (Phil, Doug, Eli) were ok with this most recent= revision based on the comments. I would be happy to do further cleanup if = necessary. 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) >> >> > 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). =A0Or 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. >> >> Err.. on second thought, I like Doug's wording better. >> >> thanks, >> -sjg >> -- >> gdb/doc/ChangeLog >> 2012-02-15 =A0Scott J. Goldman >> >> =A0 =A0 =A0 =A0 * gdb.texinfo (Commands In Python): Put example python m= acro in >> =A0 =A0 =A0 =A0 COMMAND_USER category rather than COMMAND_OBSCURE. >> =A0 =A0 =A0 =A0 (User-defined Commands) : Update documentation to clarify >> =A0 =A0 =A0 =A0 `set/show max-user-call-depth` and `show user` don't app= ly to >> python >> =A0 =A0 =A0 =A0 =A0commands. >> =A0 =A0 =A0 =A0 (User-defined Commands) : Update documentation to clarify >> =A0 =A0 =A0 =A0`help user-defined` may also include python commands defi= ned as >> =A0 =A0 =A0 =A0 COMMAND_USER >> >> gdb/ChangLog >> 2012-02-15 =A0Scott J. Goldman >> >> =A0 =A0 =A0 =A0 * cli/cli-cmds.c (show_user): Print error when used on a= python >> command. >> =A0 =A0 =A0 =A0 (init_cli_cmds): Update documentation strings for `show = user` >> and >> =A0 =A0 =A0 =A0 `set/show max-user-call-depth` to clarify that it does n= ot >> apply to >> =A0 =A0 =A0 =A0 python commands. >> =A0 =A0 =A0 =A0 * python/py-cmd.c (cmdpy_init): Treat class_user as a va= lid >> class in error >> =A0 =A0 =A0 =A0 check >> =A0 =A0 =A0 =A0 (gdbpy_initialize_commands): Add COMMAND_USER as a const= ant in >> =A0 =A0 =A0 =A0 gdb python api. >> =A0 =A0 =A0 =A0 * top.c (execute_command): Only execute a user-defined c= ommand >> as a >> =A0 =A0 =A0 =A0 legacy macro if c->user_commands is set. >> >> gdb/testsuite/ChangeLog >> 2012-02-15 =A0Scott J. Goldman >> >> =A0 =A0 =A0 =A0 * gdb.python/py-cmd.exp: Add test to verify that python >> commands can >> =A0 =A0 =A0 =A0 be put in the user-defined category and that the commands >> appear in >> =A0 =A0 =A0 =A0`help user-defined`. >> >> 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) >> =A0 =A0 =A0 =A0char *comname =3D args; >> >> =A0 =A0 =A0 =A0c =3D lookup_cmd (&comname, cmdlist, "", 0, 1); >> - =A0 =A0 =A0if (c->class !=3D class_user) >> + =A0 =A0 =A0/* c->user_commands would be NULL if it's a python command = */ >> + =A0 =A0 =A0if (c->class !=3D class_user || !c->user_commands) >> =A0 =A0 =A0 error (_("Not a user command.")); >> =A0 =A0 =A0 =A0show_user_1 (c, "", args, gdb_stdout); >> =A0 =A0 =A0} >> @@ -1912,7 +1913,7 @@ Two arguments (separated by a comma) are taken as >> a range of memory to dump,\n\ >> =A0Run the ``make'' program using the rest of the line as arguments.")); >> =A0 =A0set_cmd_completer (c, filename_completer); >> =A0 =A0add_cmd ("user", no_class, show_user, _("\ >> -Show definitions of user defined commands.\n\ >> +Show definitions of non-python user defined commands.\n\ >> =A0Argument is the name of the user defined command.\n\ >> =A0With no argument, show definitions of all user defined commands."), >> &showlist); >> =A0 =A0add_com ("apropos", class_support, apropos_command, >> @@ -1920,8 +1921,8 @@ With no argument, show definitions of all user >> defined commands."), &showlist); >> >> =A0 =A0add_setshow_integer_cmd ("max-user-call-depth", no_class, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&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, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0NULL, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0show_max_user_call_de= pth, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&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} >> >> =A0@kindex help user-defined >> =A0@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. =A0The first line of the documentation or docstring is >> +included (if any). >> >> =A0@kindex show user >> =A0@item show user >> =A0@itemx show user @var{commandname} >> =A0Display the @value{GDBN} commands used to define @var{commandname} >> (but >> =A0not its documentation). =A0If no @var{commandname} is given, display = the >> -definitions for all user-defined commands. >> +definitions for all user-defined commands. =A0This does not work for >> user-defined >> +python commands. >> >> =A0@cindex infinite recursion in user-defined commands >> =A0@kindex show max-user-call-depth >> @@ -21070,7 +21073,8 @@ definitions for all user-defined commands. >> =A0@itemx set max-user-call-depth >> =A0The value of @code{max-user-call-depth} controls how many recursion >> =A0levels are allowed in user-defined commands before @value{GDBN} >> suspects an >> -infinite recursion and aborts the command. >> +infinite recursion and aborts the command. =A0This does not apply to >> user-defined >> +python commands. >> =A0@end table >> >> =A0In addition to the above commands, user-defined commands frequently >> @@ -21871,7 +21875,7 @@ to handle this case. =A0Example: >> =A0>class HelloWorld (gdb.Command): >> =A0> =A0"""Greet the whole world.""" >> =A0> =A0def __init__ (self): >> -> =A0 =A0super (HelloWorld, self).__init__ ("hello-world", >> gdb.COMMAND_OBSCURE) >> +> =A0 =A0super (HelloWorld, self).__init__ ("hello-world", >> gdb.COMMAND_USER) >> =A0> =A0def invoke (self, args, from_tty): >> =A0> =A0 =A0argv =3D gdb.string_to_argv (args) >> =A0> =A0 =A0if len (argv) !=3D 0: >> @@ -23311,7 +23315,7 @@ class HelloWorld (gdb.Command): >> =A0 =A0"""Greet the whole world.""" >> >> =A0 =A0def __init__ (self): >> - =A0 =A0super (HelloWorld, self).__init__ ("hello-world", >> gdb.COMMAND_OBSCURE) >> + =A0 =A0super (HelloWorld, self).__init__ ("hello-world", >> gdb.COMMAND_USER) >> >> =A0 =A0def invoke (self, arg, from_tty): >> =A0 =A0 =A0print "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) >> =A0 =A0 =A0 =A0&& cmdtype !=3D class_files && cmdtype !=3D class_support >> =A0 =A0 =A0 =A0&& cmdtype !=3D class_info && cmdtype !=3D class_breakpoi= nt >> =A0 =A0 =A0 =A0&& cmdtype !=3D class_trace && cmdtype !=3D class_obscure >> - =A0 =A0 =A0&& cmdtype !=3D class_maintenance) >> + =A0 =A0 =A0&& cmdtype !=3D class_maintenance && cmdtype !=3D class_use= r) >> =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0PyErr_Format (PyExc_RuntimeError, _("Invalid command class >> argument.")); >> =A0 =A0 =A0 =A0return -1; >> @@ -578,7 +578,8 @@ gdbpy_initialize_commands (void) >> =A0 =A0 =A0 =A0|| PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 class_ob= scure) < 0 >> =A0 =A0 =A0 =A0|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENA= NCE", >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 class_main= tenance) < 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 class_main= tenance) < 0 >> + =A0 =A0 =A0|| PyModule_AddIntConstant (gdb_module, "COMMAND_USER", >> class_user) < 0) >> =A0 =A0 =A0return; >> >> =A0 =A0for (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')" \ >> =A0gdb_test "python print gdb.string_to_argv ('1\\ 2 3')" \ >> =A0 =A0{\['1 2', '3'\]} \ >> =A0 =A0 =A0"string_to_argv ('1\\ 2 3')" >> + >> +# Test user-defined python commands. >> +gdb_py_test_multiple "input simple user-defined command" \ >> + =A0"python" "" \ >> + =A0"class test_help (gdb.Command):" "" \ >> + =A0" =A0\"\"\"Docstring\"\"\"" "" \ >> + =A0" =A0def __init__ (self):" "" \ >> + =A0" =A0 =A0super (test_help, self).__init__ (\"test_help\", >> gdb.COMMAND_USER)" "" \ >> + =A0" =A0def invoke (self, arg, from_tty):" "" \ >> + =A0" =A0 =A0print \"test_cmd output, arg =3D %s\" % arg" "" \ >> + =A0"test_help ()" "" \ >> + =A0"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) >> =A0 =A0 =A0 =A0if (c->flags & DEPRECATED_WARN_USER) >> =A0 =A0 =A0 deprecated_cmd_warning (&line); >> >> - =A0 =A0 =A0if (c->class =3D=3D class_user) >> + =A0 =A0 =A0/* c->user_commands would be NULL in the case of a python >> command. */ >> + =A0 =A0 =A0if (c->class =3D=3D class_user && c->user_commands) >> =A0 =A0 =A0 execute_user_command (c, arg); >> =A0 =A0 =A0 =A0else if (c->type =3D=3D set_cmd || c->type =3D=3D show_cm= d) >> =A0 =A0 =A0 do_setshow_command (arg, from_tty, c);