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]

[RFC 8/8] mi/python: Allow redefinition of python MI commands


Redefining python MI commands is especially useful when developing
then.

gdb/Changelog:

	* mi/mi-cmds.h (mi_command::is_py_command): New method.
	(mi_command_py::is_py_command) New method.
	* gdb/mi/mi-cmds.c: (mi_command::is_py_command): New method.
	(mi_command_py::is_py_command) New method.
	(insert_mi_cmd_entry): Allow redefinition of python-defined MI commands.

gdb/testsuite/Changelog:

	* gdb.python/py-mi-cmd.exp: Add tests for python-defined MI command
	redefinition.
	* gdb.python/py-mi-cmd-2.py: New file.
---
 gdb/ChangeLog                           |  8 ++++++++
 gdb/mi/mi-cmds.c                        | 17 ++++++++++++++++-
 gdb/mi/mi-cmds.h                        |  5 +++++
 gdb/testsuite/ChangeLog                 |  6 ++++++
 gdb/testsuite/gdb.python/py-mi-cmd-2.py | 13 +++++++++++++
 5 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.python/py-mi-cmd-2.py

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1fd49e703f..1fb1cfc2e2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2018-12-12  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmds.h (mi_command::is_py_command): New method.
+	(mi_command_py::is_py_command) New method.
+	* gdb/mi/mi-cmds.c: (mi_command::is_py_command): New method.
+	(mi_command_py::is_py_command) New method.
+	(insert_mi_cmd_entry): Allow redefinition of python-defined MI commands.
+
 2018-12-10  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
 	* python/py-micmd.c (py_mi_invoke): Handle exceptions thrown in Python
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index c4332e59cf..95abdac080 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -43,7 +43,8 @@ insert_mi_cmd_entry (mi_cmd_up command)
   const std::string &name = command->name ();
 
   if (mi_cmd_table.find (name) != mi_cmd_table.end ())
-    return false;
+    if (! mi_cmd_table[name]->is_py_command ())
+      return false;
 
   mi_cmd_table[name] = std::move (command);
 
@@ -82,6 +83,13 @@ mi_command::mi_command (const char *name, int *suppress_notification)
     m_suppress_notification (suppress_notification)
 {}
 
+bool
+mi_command::is_py_command()
+{
+  return false;
+}
+
+
 std::unique_ptr<scoped_restore_tmpl<int>>
 mi_command::do_suppress_notification ()
 {
@@ -152,6 +160,13 @@ mi_command_py::invoke (struct mi_parse *parse)
 
 }
 
+bool
+mi_command_py::is_py_command()
+{
+  return true;
+}
+
+
 /* Initialize the available MI commands.  */
 
 static void
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index a89e265de7..1f199a6434 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -140,6 +140,9 @@ class mi_command
     /* Execute the MI command.  */
     virtual void invoke (struct mi_parse *parse) = 0;
 
+    /* Return TRUE if command is python command, FALSE otherwise. */
+    virtual bool is_py_command();
+    
   protected:
     std::unique_ptr<scoped_restore_tmpl<int>> do_suppress_notification ();
 
@@ -188,6 +191,8 @@ class mi_command_py : public mi_command
 		   void *object);
     void invoke (struct mi_parse *parse) override;
 
+    bool is_py_command() override;
+
   private:
     void *pyobj;
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a71b3f25db..0172eada9e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-12-12  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.python/py-mi-cmd.exp: Add tests for python-defined MI command
+	redefinition. 
+	* gdb.python/py-mi-cmd-2.py: New file.
+
 2018-12-10  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
 	* gdb.python/py-mi-cmd.exp: New file.
diff --git a/gdb/testsuite/gdb.python/py-mi-cmd-2.py b/gdb/testsuite/gdb.python/py-mi-cmd-2.py
new file mode 100644
index 0000000000..5d5929d2fd
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-mi-cmd-2.py
@@ -0,0 +1,13 @@
+import gdb
+
+class pycmd(gdb.MICommand):
+    def invoke(self, argv):
+        if argv[0] == 'bogus':
+            return "not really"
+        else:
+            raise gdb.GdbError("Invalid parameter: %s" % argv[0])
+
+pycmd('-pycmd')
+pycmd('-info-gdb-mi-command')
+
+
-- 
2.20.1


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