From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 43739 invoked by alias); 23 May 2019 21:06:16 -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 43731 invoked by uid 89); 23 May 2019 21:06:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 May 2019 21:06:14 +0000 Received: from [172.16.0.120] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 1EEA21E0A9; Thu, 23 May 2019 17:06:13 -0400 (EDT) Subject: Re: [PATCH] Add an objfile getter to gdb.Type To: Christian Biesinger , gdb-patches@sourceware.org References: <20190523183935.209380-1-cbiesinger@google.com> <20190523203227.260432-1-cbiesinger@google.com> From: Simon Marchi Message-ID: <3fb153fb-5ef5-d756-11be-caff4d73e517@simark.ca> Date: Thu, 23 May 2019 21:06:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190523203227.260432-1-cbiesinger@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-05/txt/msg00552.txt.bz2 Hi Christian, Just some formatting nits (don't worry that's common when starting on a project, but you get used to it quickly). On 2019-05-23 4:32 p.m., Christian Biesinger via gdb-patches wrote: > 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 gdb.Type.objfile property > > gdb/testsuite/ChangeLog: > > 2019-05-22 Christian Biesinger > > * gdb/testsuite/gdb.python/py-type.exp: Test for new > gdb.Type.objfile property Use periods at the end of ChangeLog entries. > > --- > gdb/NEWS | 3 +++ > gdb/doc/python.texi | 5 +++++ > gdb/python/py-type.c | 14 ++++++++++++++ > gdb/testsuite/gdb.python/py-type.exp | 4 ++++ > 4 files changed, 26 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..379038f8c6 100644 > --- a/gdb/python/py-type.c > +++ b/gdb/python/py-type.c > @@ -413,6 +413,18 @@ typy_get_tag (PyObject *self, void *closure) > return PyString_FromString (tagname); > } > > +/* Return the type's objfile, or None. */ > +static PyObject * > +typy_get_objfile (PyObject *self, void *closure) > +{ > + struct type *type = ((type_object *) self)->type; > + struct objfile *objfile = TYPE_OBJFILE(type); Ah, I forgot to explicitly mention to add a space after TYPE_OBJFILE. > + > + 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 +1431,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 } > }; > > diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp > index 734f9b40fd..c299fa3410 100644 > --- a/gdb/testsuite/gdb.python/py-type.exp > +++ b/gdb/testsuite/gdb.python/py-type.exp > @@ -98,6 +98,8 @@ proc test_fields {lang} { > gdb_py_test_silent_cmd "print (st)" "print value (st)" 1 > gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 > gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields from st.type" 1 > + gdb_test "python print (st.type.objfile.filename == gdb.current_progspace().filename)" "True" \ Space after current_progspace as well. > + "Check type.objfile" We use lower case letters for test names. > gdb_test "python print (len(fields))" "2" "check number of fields (st)" > gdb_test "python print (fields\[0\].name)" "a" "check structure field a name" > gdb_test "python print (fields\[1\].name)" "b" "check structure field b name" > @@ -269,6 +271,8 @@ if { [build_inferior "${binfile}" "c"] == 0 } { > # Skip all tests if Python scripting is not enabled. > if { [skip_python_tests] } { continue } > > + gdb_test "python print(gdb.lookup_type('char').objfile)" "None" Spaces before parentheses (even though there's a bad example just below). Let's give a few days for others to comment if they want to. With these fixed the patch LGTM. Simon