From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3158 invoked by alias); 29 Aug 2013 11:15:09 -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 3146 invoked by uid 89); 29 Aug 2013 11:15:09 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Aug 2013 11:15:09 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,KHOP_THREADED,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7TBF7mS019872 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Aug 2013 07:15:07 -0400 Received: from localhost.localdomain (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7TBF59i015378; Thu, 29 Aug 2013 07:15:06 -0400 Message-ID: <521F2D39.3060309@redhat.com> Date: Thu, 29 Aug 2013 11:15:00 -0000 From: Phil Muldoon MIME-Version: 1.0 To: Tom Tromey CC: "gdb-patches@sourceware.org" Subject: Re: [patch] [python] PR python/15461 (gate architecture calls) References: <521DE761.6010403@redhat.com> <87k3j5x3yq.fsf@fleche.redhat.com> <521E1419.5040404@redhat.com> <87eh9dx12o.fsf@fleche.redhat.com> In-Reply-To: <87eh9dx12o.fsf@fleche.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-08/txt/msg00864.txt.bz2 On 28/08/13 16:54, Tom Tromey wrote: > Phil> I don't disagree on the efficiency argument, but my goal here was to > Phil> follow the pattern that other objects use to determine validity of the > Phil> underlying GDB data. To bring a sense of uniformity to how we do > Phil> things in Python. So how we check a gdb.Frame's, et al, validity, the > Phil> pattern will be the same, as far as possible, for other objects. > > Ok. > > If you look at other ones, they set the Python exception. At least that > is true for py-block.c (twice), py-inferior.c, py-inthread.c, > py-symbol.c, py-symtab.c (twice), etc. > > FWIW I don't mind inconsistency in these little details. What matters > is the context in which the macro is most useful. For some reason I totally misread your original comment. I re-read the thread this morning, and found my mistake. Mea Cupla. I thought you did not want the macro, but that was not the case. Your objection was to the error() call, and was totally correct. Not sure why I read that email so incorrectly. Apologies. So just ignore my previous comments ;) Updated the patch. ChangeLog remains the same. Cheers, Phil -- diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 7098a8a..a31ffdd 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -30,6 +30,18 @@ typedef struct arch_object_type_object { static struct gdbarch_data *arch_object_data = NULL; +/* Require a valid Architecture. */ +#define ARCHPY_REQUIRE_VALID(arch_obj, arch) \ + do { \ + arch = arch_object_to_gdbarch (arch_obj); \ + if (arch == NULL) \ + { \ + PyErr_SetString (PyExc_RuntimeError, \ + _("Architecture is invalid.")); \ + return NULL; \ + } \ + } while (0) + static PyTypeObject arch_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("arch_object"); @@ -82,9 +94,14 @@ gdbarch_to_arch_object (struct gdbarch *gdbarch) static PyObject * archpy_name (PyObject *self, PyObject *args) { - struct gdbarch *gdbarch = arch_object_to_gdbarch (self); - const char *name = (gdbarch_bfd_arch_info (gdbarch))->printable_name; - PyObject *py_name = PyString_FromString (name); + struct gdbarch *gdbarch = NULL; + const char *name; + PyObject *py_name; + + ARCHPY_REQUIRE_VALID (self, gdbarch); + + name = (gdbarch_bfd_arch_info (gdbarch))->printable_name; + py_name = PyString_FromString (name); return py_name; } @@ -104,7 +121,9 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) gdb_py_ulongest start_temp; long count = 0, i; PyObject *result_list, *end_obj = NULL, *count_obj = NULL; - struct gdbarch *gdbarch = arch_object_to_gdbarch (self); + struct gdbarch *gdbarch = NULL; + + ARCHPY_REQUIRE_VALID (self, gdbarch); if (!PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO", keywords, &start_temp, &end_obj, &count_obj)) diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp index 4e736b8..6fff256 100644 --- a/gdb/testsuite/gdb.python/py-arch.exp +++ b/gdb/testsuite/gdb.python/py-arch.exp @@ -26,6 +26,14 @@ if ![runto_main] { return -1 } +# Test python/15461. Invalid architectures should not trigger an +# internal GDB assert. +gdb_py_test_silent_cmd "python empty = gdb.Architecture()" "get empty arch" 0 +gdb_test "python print(empty.name())" ".*Architecture is invalid.*" \ + "Test empty architecture.name does not trigger an assert" +gdb_test "python print(empty.disassemble())" ".*Architecture is invalid.*" \ + "Test empty architecture.disassemble does not trigger an assert" + gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "get frame" 0 gdb_py_test_silent_cmd "python arch = frame.architecture()" "get arch" 0 gdb_py_test_silent_cmd "python pc = frame.pc()" "get pc" 0