From patchwork Thu Apr 18 15:23:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vrany X-Patchwork-Id: 32335 Received: (qmail 25041 invoked by alias); 18 Apr 2019 15:24:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24954 invoked by uid 89); 18 Apr 2019 15:24:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: relay.fit.cvut.cz Received: from relay.fit.cvut.cz (HELO relay.fit.cvut.cz) (147.32.232.237) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Apr 2019 15:24:29 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [147.32.232.238]) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id x3IFOOwA093732 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Apr 2019 17:24:26 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Received: from localhost (02d97c6d.bb.sky.com [2.217.124.109] (may be forged)) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id x3IFON1P060435 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 18 Apr 2019 17:24:24 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [RFC 8/8] mi/python: Allow redefinition of python MI commands Date: Thu, 18 Apr 2019 16:23:37 +0100 Message-Id: <20190418152337.6376-9-jan.vrany@fit.cvut.cz> In-Reply-To: <20190418152337.6376-1-jan.vrany@fit.cvut.cz> References: <20190418152337.6376-1-jan.vrany@fit.cvut.cz> MIME-Version: 1.0 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 + + * 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 * 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> 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> 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 + + * 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 * 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') + +