This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add support for `user-defined` python commands


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]