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] Allow user-defined as a category for python gdb macros (resend)


Hi.

The VMware legal folks and FSF legal folks seem to be done with their
back and forth, and I am told it is now legally ok for this patch to be
committed.

This patch allows python macros to coexist with legacy gdb macros in
user-defined category. This way, it's possible to organize your macros
such that `help user` shows both legacy and python macros. I also
modified the documentation to use the `user` category in the example
python macro. It seemed like a more reasonable default category than
`obscure`.

2012-02-13  Scott J. Goldman <scottjg@vmware.com>

	* gdb.texinfo: put example python macro in COMMAND_USER category
	rather than COMMAND_OBSCURE.
	* 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.

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9edc6ad..2a26cbe 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21871,7 +21871,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:
@@ -23311,7 +23311,7 @@ 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, 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 != 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;
@@ -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;
 
   for (i = 0; i < N_COMPLETERS; ++i)
diff --git a/gdb/top.c b/gdb/top.c
index e41f56c..8a91735 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -470,7 +470,7 @@ execute_command (char *p, int from_tty)
       if (c->flags & DEPRECATED_WARN_USER)
 	deprecated_cmd_warning (&line);
 
-      if (c->class == class_user)
+      if (c->class == class_user && c->user_commands)
 	execute_user_command (c, arg);
       else if (c->type == set_cmd || c->type == show_cmd)
 	do_setshow_command (arg, from_tty, c);


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