From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73074 invoked by alias); 21 Apr 2017 10:50:10 -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 72921 invoked by uid 89); 21 Apr 2017 10:50:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*m:tim X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Apr 2017 10:50:06 +0000 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Apr 2017 03:50:06 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga006.fm.intel.com with ESMTP; 21 Apr 2017 03:50:05 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id v3LAo46J023768; Fri, 21 Apr 2017 11:50:04 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id v3LAo4Vv026643; Fri, 21 Apr 2017 12:50:04 +0200 Received: (from twiederh@localhost) by ulvlx001.iul.intel.com with œ id v3LAo4DI026639; Fri, 21 Apr 2017 12:50:04 +0200 From: Tim Wiederhake To: gdb-patches@sourceware.org Cc: markus.t.metzger@intel.com, brobecker@adacore.com, qiyaoltc@gmail.com Subject: [PATCH v2 2/8] Python: Fix exception handling in py-record-btrace.c Date: Fri, 21 Apr 2017 10:50:00 -0000 Message-Id: <1492771786-26372-3-git-send-email-tim.wiederhake@intel.com> In-Reply-To: <1492771786-26372-1-git-send-email-tim.wiederhake@intel.com> References: <1492771786-26372-1-git-send-email-tim.wiederhake@intel.com> X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00599.txt.bz2 GDB_PY_HANDLE_EXCEPTION does not handle all exceptions. Replace with call to gdbpy_convert_exception. 2017-04-21 Tim Wiederhake gdb/ChangeLog: python/py-record-btrace.c (btpy_insn_sal, btpy_insn_data, btpy_insn_decode, recpy_bt_goto): Handle all exceptions. --- gdb/python/py-record-btrace.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c index 0f8d7ef..9d79e2b 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -227,7 +227,7 @@ btpy_insn_sal (PyObject *self, void *closure) } CATCH (except, RETURN_MASK_ALL) { - GDB_PY_HANDLE_EXCEPTION (except); + gdbpy_convert_exception (except); } END_CATCH @@ -320,10 +320,14 @@ btpy_insn_data (PyObject *self, void *closure) CATCH (except, RETURN_MASK_ALL) { xfree (buffer); - GDB_PY_HANDLE_EXCEPTION (except); + buffer = NULL; + gdbpy_convert_exception (except); } END_CATCH + if (buffer == NULL) + return NULL; + object = PyBytes_FromStringAndSize ((const char*) buffer, insn->size); xfree (buffer); @@ -348,6 +352,7 @@ btpy_insn_decode (PyObject *self, void *closure) const struct btrace_insn *insn; struct btrace_insn_iterator iter; string_file strfile; + int length = 0; BTPY_REQUIRE_VALID_INSN (obj, iter); @@ -364,15 +369,16 @@ btpy_insn_decode (PyObject *self, void *closure) TRY { - gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL); + length = gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL); } CATCH (except, RETURN_MASK_ALL) { gdbpy_convert_exception (except); - return NULL; } END_CATCH + if (length == 0) + return NULL; return PyBytes_FromString (strfile.string ().c_str ()); } @@ -871,6 +877,7 @@ recpy_bt_goto (PyObject *self, PyObject *args) { struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); const btpy_object *obj; + PyObject *ret = NULL; if (tinfo == NULL || btrace_is_empty (tinfo)) return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace.")); @@ -891,14 +898,17 @@ recpy_bt_goto (PyObject *self, PyObject *args) target_goto_record_end (); else target_goto_record (obj->number); + + Py_INCREF (Py_None); + ret = Py_None; } CATCH (except, RETURN_MASK_ALL) { - GDB_PY_HANDLE_EXCEPTION (except); + gdbpy_convert_exception (except); } END_CATCH - Py_RETURN_NONE; + return ret; } /* BtraceInstruction members. */ -- 2.7.4