From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 79293 invoked by alias); 23 May 2019 18:40:05 -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 79285 invoked by uid 89); 23 May 2019 18:40:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=christian, Christian, H*MI:google X-HELO: mail-qt1-f201.google.com Received: from mail-qt1-f201.google.com (HELO mail-qt1-f201.google.com) (209.85.160.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 May 2019 18:40:03 +0000 Received: by mail-qt1-f201.google.com with SMTP id z7so6190929qtq.13 for ; Thu, 23 May 2019 11:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=rC5VEv3OjPcyPTJ7nl4IDLRS6j557Hy7KGO66WHAfT0=; b=ffI7/qw/bRu63sxl2WJy8Lh22PU76XNGYyP3gwrIbr3VICoV74qVFoemp2GusHoCbb TSu8njIVdEtshdLgeV3x78HTdXZvq2pBqYsF6Mhmv5TPJ7x1V9wqzdttyRtgpQAFLckQ 0RyEi0g+M2vEuWIi0ExoZ60IPSNCQQrcoRn3V1TZQabjIOujKVXXpDwGML/I6Hl3ZyAp B7hkWTDu7/N2N4cvTlxaJuFGZUXpeEVfiXB9RMZv3waE7h7v8NBW9ilQLojPqm9im9do +kGIrw6V3lmLYxA9Tuf+HI7f4lxh1IDb7t5oa3X/5VUSYpUi2QSi3Tbj+wlQvYMtD7f4 bkLg== Date: Thu, 23 May 2019 18:40:00 -0000 Message-Id: <20190523183935.209380-1-cbiesinger@google.com> Mime-Version: 1.0 Subject: [PATCH] Add an objfile getter to gdb.Type From: "Christian Biesinger via gdb-patches" Reply-To: Christian Biesinger To: gdb-patches@sourceware.org Cc: Christian Biesinger Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2019-05/txt/msg00539.txt.bz2 This allows users of the Python API to find the objfile where a type was defined. gdb/ChangeLog: 2019-05-22 Christian Biesinger Add objfile property to gdb.Type * gdb/NEWS: Mention Python API addition * gdb/python/py-type.c (typy_get_objfile): New method gdb/doc/ChangeLog 2019-05-22 Christian Biesinger * gdb/doc/python.texi: Document new objfile property --- gdb/NEWS | 3 +++ gdb/doc/python.texi | 5 +++++ gdb/python/py-type.c | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 792548139e..c715bd6bca 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -27,6 +27,9 @@ 'array_indexes', 'symbols', 'unions', 'deref_refs', 'actual_objects', 'static_members', 'max_elements', 'repeat_threshold', and 'format'. + ** gdb.Type has a new property 'objfile' which returns the objfile the + type was defined in. + * New commands set may-call-functions [on|off] diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 98e52bb770..f769ad03a2 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1087,6 +1087,11 @@ languages have this concept. If this type has no tag name, then @code{None} is returned. @end defvar +@defvar Type.objfile +The @code{gdb.Objfile} that this type was defined in, or @code{None} if +there is no associated objfile. +@end defvar + The following methods are provided: @defun Type.fields () diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 22cc658a8b..722960e032 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -413,6 +413,20 @@ typy_get_tag (PyObject *self, void *closure) return PyString_FromString (tagname); } +/* Return the type's tag, or None. */ +static PyObject * +typy_get_objfile (PyObject *self, void *closure) +{ + struct type *type = ((type_object *) self)->type; + struct objfile *objfile = nullptr; + + objfile = TYPE_OBJFILE(type); + + if (objfile == nullptr) + Py_RETURN_NONE; + return objfile_to_objfile_object (objfile).release (); +} + /* Return the type, stripped of typedefs. */ static PyObject * typy_strip_typedefs (PyObject *self, PyObject *args) @@ -1419,6 +1433,8 @@ static gdb_PyGetSetDef type_object_getset[] = "The size of this type, in bytes.", NULL }, { "tag", typy_get_tag, NULL, "The tag name for this type, or None.", NULL }, + { "objfile", typy_get_objfile, NULL, + "The objfile this type was defined in, or None.", NULL }, { NULL } }; -- 2.21.0.1020.gf2820cf01a-goog