From patchwork Sat Sep 15 18:45:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29396 Received: (qmail 98179 invoked by alias); 15 Sep 2018 18:46:17 -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 97772 invoked by uid 89); 15 Sep 2018 18:45:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=decimal, $decimal X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.147.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Sep 2018 18:45:50 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 5120D1F2FAC for ; Sat, 15 Sep 2018 13:45:33 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 1FZVgpfIeaSey1FZVgGRUg; Sat, 15 Sep 2018 13:45:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JO1zIwOQOB57iCToCb5EQZhZDeQJQL6G6cjPd1qc8bY=; b=bZneYu7yzY7ToVItJ3GpggS8if OZaJPw36qldsq3JSp7czBCRh6zYa+b1Xd7QLCW2jiG7wXZBqhUa9NuNsNsb+cGI9qIWE3bvfibiXC 8bhdvmkqhb12KSv/FYyR+XL4z; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:42910 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g1FZV-000A8v-40; Sat, 15 Sep 2018 13:45:33 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Add Inferior.architecture method Date: Sat, 15 Sep 2018 12:45:30 -0600 Message-Id: <20180915184530.3657-3-tom@tromey.com> In-Reply-To: <20180915184530.3657-1-tom@tromey.com> References: <20180915184530.3657-1-tom@tromey.com> I've written a couple of gdb unwinders in Python, and while doing so, I wanted to find the architecture of the inferior. (In an unwinder in particular, one can't use the frame's architecture, because there is no frame.) This patch adds Inferior.architecture to allow this. Normally I think I would have chosen an attribute and not a method here, but seeing that Frame.architecture is a method, I chose a method as well, for consistency. gdb/ChangeLog 2018-09-15 Tom Tromey PR python/19399: * python/py-inferior.c: Add "architecture" entry. (infpy_architecture): New function. gdb/doc/ChangeLog 2018-09-15 Tom Tromey PR python/19399: * python.texi (Inferiors In Python): Document Inferior.Architecture. gdb/testsuite/ChangeLog 2018-09-15 Tom Tromey PR python/19399: * gdb.python/py-inferior.exp: Add architecture test. --- gdb/ChangeLog | 6 ++++++ gdb/doc/ChangeLog | 6 ++++++ gdb/doc/python.texi | 7 +++++++ gdb/python/py-inferior.c | 15 +++++++++++++++ gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/py-inferior.exp | 8 ++++++++ 6 files changed, 47 insertions(+) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index bd444daff5a..751c400bf32 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2856,6 +2856,13 @@ when it is called. If there are no valid threads, the method will return an empty tuple. @end defun +@defun Inferior.architecture () +Return the @code{gdb.Architecture} (@pxref{Architectures In Python}) +for this inferior. This represents the architecture of the inferior +as a whole. Some platforms can have multiple architectures in a +single address space, so this may not match the architecture of a +particular frame (@pxref{Frames in Python}). + @findex Inferior.read_memory @defun Inferior.read_memory (address, length) Read @var{length} addressable memory units from the inferior, starting at diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 6db3df412eb..539c9958ec1 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -877,6 +877,18 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) return result; } +/* Implementation of gdb.Inferior.architecture. */ + +static PyObject * +infpy_architecture (PyObject *self, PyObject *args) +{ + inferior_object *inf = (inferior_object *) self; + + INFPY_REQUIRE_VALID (inf); + + return gdbarch_to_arch_object (inf->inferior->gdbarch); +} + /* Implement repr() for gdb.Inferior. */ static PyObject * @@ -1010,6 +1022,9 @@ Return a long with the address of a match, or None." }, METH_VARARGS | METH_KEYWORDS, "thread_from_thread_handle (handle) -> gdb.InferiorThread.\n\ Return thread object corresponding to thread handle." }, + { "architecture", (PyCFunction) infpy_architecture, METH_NOARGS, + "architecture () -> gdb.Architecture\n\ +Return architecture of this inferior." }, { NULL } }; diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 38f52573b19..7b1a01b3ea6 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -299,3 +299,11 @@ with_test_prefix "__repr__" { "\\\(, \\\)" \ "print all inferiors 2" } + +# Test architecture. +with_test_prefix "architecture" { + gdb_test "inferior 1" ".*" "switch to first inferior" + gdb_test "python print(gdb.selected_frame().architecture() is gdb.selected_inferior().architecture())" \ + "True" \ + "inferior architecture matches frame architecture" +}