Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Scott J. Goldman" <scottjg@vmware.com>
To: gdb-patches@sourceware.org
Cc: "Scott J. Goldman" <scottjg@vmware.com>
Subject: [PATCH] Add support for `user-defined` python commands
Date: Wed, 18 May 2011 23:28:00 -0000	[thread overview]
Message-ID: <1305761175-10188-1-git-send-email-scottjg@vmware.com> (raw)

For codebases with a large pre-existing set of legacy gdb macros, it's
nice to be able to use `help user-defined`, to refresh your memory wrt
to existing macros. Currently, python gdb commands can't put themselves
under the `user-defined` category. This patch aims to rectify that.
---
 gdb/ChangeLog       |    6 ++++++
 gdb/doc/ChangeLog   |    4 ++++
 gdb/doc/gdb.texinfo |   10 +++++++++-
 gdb/python/py-cmd.c |    6 ++++--
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3103398..9f9fade 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2011-05-18  Scott J. Goldman <scottjg@vmware.com>
+
+	Add support to define python commands as 'user-defined'
+	* py-cmd.c (gdbpy_initialize_commands): support COMMAND_USER type
+	(cmdpy_init): support class_user
+
 2011-05-18  Tom Tromey  <tromey@redhat.com>
 
 	* dwarf2read.c (dwarf2_add_field): Constify.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 0469b0a..d21c9ef 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2011-05-18 Scott J. Goldman <scottjg@vmware.com>
+
+	* gdb.texinfo: Document COMMAND_USER python command type
+
 2011-05-17  Pedro Alves  <pedro@codesourcery.com>
 
 	* gdb.texinfo (Remote Protocol) <Overview>: Mention vCont is
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 584a520..8b15ed2 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21124,7 +21124,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 = gdb.string_to_argv (args)
 >    if len (argv) != 0:
@@ -22450,6 +22450,14 @@ The command is only useful to @value{GDBN} maintainers.  The
 @code{maintenance} and @code{flushregs} commands are in this category.
 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
 commands in this category.
+
+@findex COMMAND_USER
+@findex gdb.COMMAND_USER
+@item COMMAND_USER
+The command is considered user-defined.  Old-style @value{GDBN}
+command macros always fall under this category.
+Type @kbd{help user-defined} at the @value{GDBN} prompt to see a list
+of commands in this category.
 @end table
 
 A new command can use a predefined completion function, either by
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index c0e3291..8b8e384 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 != class_files && cmdtype != class_support
       && cmdtype != class_info && cmdtype != class_breakpoint
       && cmdtype != class_trace && cmdtype != class_obscure
-      && cmdtype != class_maintenance)
+      && cmdtype != class_maintenance && cmdtype != class_user)
     {
       PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
       return -1;
@@ -576,7 +576,9 @@ 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;
 
   for (i = 0; i < N_COMPLETERS; ++i)
-- 
1.7.4.1


             reply	other threads:[~2011-05-18 23:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-18 23:28 Scott J. Goldman [this message]
2011-05-19  1:59 ` Doug Evans
2011-05-19  2:54   ` Scott Goldman
2011-05-19  3:08     ` Doug Evans
2011-05-19 16:44 ` Tom Tromey
2011-05-19 19:27   ` Scott Goldman
2011-05-19 20:23     ` Tom Tromey
2011-05-19 23:16     ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305761175-10188-1-git-send-email-scottjg@vmware.com \
    --to=scottjg@vmware.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox