From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25008 invoked by alias); 18 Apr 2019 15:24:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24707 invoked by uid 89); 18 Apr 2019 15:24:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.1 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:18 +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 x3IFOD5X093721 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Apr 2019 17:24:15 +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 x3IFOCQ2060394 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 18 Apr 2019 17:24:13 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [RFC 6/8] mi/python: Handle python exception when executiong python-defined MI commands Date: Thu, 18 Apr 2019 15:24:00 -0000 Message-Id: <20190418152337.6376-7-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 Content-Transfer-Encoding: 8bit X-SW-Source: 2019-04/txt/msg00335.txt.bz2 Respond with ^error,msg="..." when an unhandled python exception is thrown while invoking python-defined MI command. The error message is taken from python exception object. gdb/Changelog: * python/py-micmd.c (py_mi_invoke): Handle exceptions thrown in Python code. --- gdb/ChangeLog | 5 +++++ gdb/python/py-micmd.c | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8bbaaba5ad..1fd49e703f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-12-10 Jan Vrany + + * python/py-micmd.c (py_mi_invoke): Handle exceptions thrown in Python + code. + 2018-12-10 Jan Vrany * python/py-micmd.c (parse_mi_result): Polish to make the output diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c index bbd746fa32..a099bb48cd 100644 --- a/gdb/python/py-micmd.c +++ b/gdb/python/py-micmd.c @@ -115,14 +115,28 @@ py_mi_invoke (void *py_obj, char **argv, int argc) error (_("Failed to create the python arguments list.")); } } - + + gdb_assert (PyErr_Occurred () == NULL); gdbpy_ref<> result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst, argobj.get (), NULL)); + if (PyErr_Occurred () != NULL) + { + gdbpy_err_fetch ex; + gdb::unique_xmalloc_ptr ex_msg (ex.to_string()); - if (result != nullptr) + if (ex_msg == NULL || *ex_msg == '\0') + error (_("Failed to execute command")); + else + error (_(ex_msg.get ())); + } + else if (result != nullptr) { if (Py_None != result) parse_mi_result (result.get (), "result"); } + else + { + error (_("Command invoke() method returned NULL but no python exception is set")); + } } /* Parse the name of the MI command to register. -- 2.20.1