public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add an objfile getter to gdb.Type
@ 2019-05-23 18:40 Christian Biesinger via gdb-patches
  2019-05-23 19:01 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-05-23 18:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Biesinger

This allows users of the Python API to find the objfile where a type
was defined.

gdb/ChangeLog:

2019-05-22  Christian Biesinger  <cbiesinger@google.com>

	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  <cbiesinger@google.com>

	* 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 18:40 [PATCH] Add an objfile getter to gdb.Type Christian Biesinger via gdb-patches
@ 2019-05-23 19:01 ` Eli Zaretskii
  2019-05-23 19:34 ` Simon Marchi
  2019-05-23 20:32 ` Christian Biesinger via gdb-patches
  2 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2019-05-23 19:01 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: gdb-patches

> Date: Thu, 23 May 2019 13:39:35 -0500
> From: "Christian Biesinger via gdb-patches" <gdb-patches@sourceware.org>
> Cc: Christian Biesinger <cbiesinger@google.com>
> 
> This allows users of the Python API to find the objfile where a type
> was defined.
> 
> gdb/ChangeLog:
> 
> 2019-05-22  Christian Biesinger  <cbiesinger@google.com>
> 
> 	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  <cbiesinger@google.com>
> 
> 	* gdb/doc/python.texi: Document new objfile property

OK for the documentation parts, thanks.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 18:40 [PATCH] Add an objfile getter to gdb.Type Christian Biesinger via gdb-patches
  2019-05-23 19:01 ` Eli Zaretskii
@ 2019-05-23 19:34 ` Simon Marchi
  2019-05-23 20:36   ` Christian Biesinger via gdb-patches
  2019-05-23 20:32 ` Christian Biesinger via gdb-patches
  2 siblings, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2019-05-23 19:34 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches

Hi Christian,

On 2019-05-23 2:39 p.m., Christian Biesinger via gdb-patches wrote:
> 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.  */

copy-pasto: "type's objfile"

> +static PyObject *
> +typy_get_objfile (PyObject *self, void *closure)
> +{
> +  struct type *type = ((type_object *) self)->type;
> +  struct objfile *objfile = nullptr;
> +
> +  objfile = TYPE_OBJFILE(type);

You can write it as

  struct objfile *objfile = objfile = TYPE_OBJFILE (type);

directly.

We would need a corresponding test though.  It should be a relatively easy addition
to testsuite/gdb.python/py-type.exp.  See here for info about how to run just one
test:

https://sourceware.org/gdb/wiki/TestingGDB#Running_specific_tests

Thanks!

Simon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 18:40 [PATCH] Add an objfile getter to gdb.Type Christian Biesinger via gdb-patches
  2019-05-23 19:01 ` Eli Zaretskii
  2019-05-23 19:34 ` Simon Marchi
@ 2019-05-23 20:32 ` Christian Biesinger via gdb-patches
  2019-05-23 21:06   ` Simon Marchi
  2019-05-23 21:37   ` Christian Biesinger via gdb-patches
  2 siblings, 2 replies; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-05-23 20:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Biesinger

This allows users of the Python API to find the objfile where a type
was defined.

gdb/ChangeLog:

2019-05-22  Christian Biesinger  <cbiesinger@google.com>

	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  <cbiesinger@google.com>

	* gdb/doc/python.texi: Document new gdb.Type.objfile property

gdb/testsuite/ChangeLog:

2019-05-22  Christian Biesinger  <cbiesinger@google.com>

	* gdb/testsuite/gdb.python/py-type.exp: Test for new
	  gdb.Type.objfile property

---
 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);
+
+  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" \
+      "Check type.objfile"
     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"
+
   gdb_test "python print(gdb.lookup_type('char').array(1, 0))" \
       "char \\\[0\\\]"
 
-- 
2.22.0.rc1.257.g3120a18244-goog

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 19:34 ` Simon Marchi
@ 2019-05-23 20:36   ` Christian Biesinger via gdb-patches
  0 siblings, 0 replies; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-05-23 20:36 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Thu, May 23, 2019 at 2:34 PM Simon Marchi <simark@simark.ca> wrote:
> > +/* Return the type's tag, or None.  */
>
> copy-pasto: "type's objfile"

Done

> > +static PyObject *
> > +typy_get_objfile (PyObject *self, void *closure)
> > +{
> > +  struct type *type = ((type_object *) self)->type;
> > +  struct objfile *objfile = nullptr;
> > +
> > +  objfile = TYPE_OBJFILE(type);
>
> You can write it as
>
>   struct objfile *objfile = objfile = TYPE_OBJFILE (type);
>
> directly.
>
> We would need a corresponding test though.  It should be a relatively easy addition
> to testsuite/gdb.python/py-type.exp.  See here for info about how to run just one
> test:

Done. I sent the updated patch as a separate email, I hope I did it right.

Thanks,
Christian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 20:32 ` Christian Biesinger via gdb-patches
@ 2019-05-23 21:06   ` Simon Marchi
  2019-05-23 21:25     ` Christian Biesinger via gdb-patches
  2019-05-23 21:37   ` Christian Biesinger via gdb-patches
  1 sibling, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2019-05-23 21:06 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches

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  <cbiesinger@google.com>
> 
> 	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  <cbiesinger@google.com>
> 
> 	* gdb/doc/python.texi: Document new gdb.Type.objfile property
> 
> gdb/testsuite/ChangeLog:
> 
> 2019-05-22  Christian Biesinger  <cbiesinger@google.com>
> 
> 	* 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 21:06   ` Simon Marchi
@ 2019-05-23 21:25     ` Christian Biesinger via gdb-patches
  0 siblings, 0 replies; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-05-23 21:25 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Thu, May 23, 2019 at 4:06 PM Simon Marchi <simark@simark.ca> wrote:
> Just some formatting nits (don't worry that's common when starting on a project, but you get used to it quickly).

No problem! Will send a new version of the patch in a second.

> On 2019-05-23 4:32 p.m., Christian Biesinger via gdb-patches wrote:
> > 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.

This file is super inconsistent about both of those :/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 20:32 ` Christian Biesinger via gdb-patches
  2019-05-23 21:06   ` Simon Marchi
@ 2019-05-23 21:37   ` Christian Biesinger via gdb-patches
  2019-05-28 22:07     ` Tom Tromey
  1 sibling, 1 reply; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-05-23 21:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Biesinger

This allows users of the Python API to find the objfile where a type
was defined.

gdb/ChangeLog:

2019-05-23  Christian Biesinger  <cbiesinger@google.com>

	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-23  Christian Biesinger  <cbiesinger@google.com>

	* gdb/doc/python.texi: Document new gdb.Type.objfile property.

gdb/testsuite/ChangeLog:

2019-05-23  Christian Biesinger  <cbiesinger@google.com>

	* gdb/testsuite/gdb.python/py-type.exp: Test for new
	  gdb.Type.objfile property.

---
 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..7b99beacae 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);
+
+  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..da4d4a7228 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" \
+      "check type.objfile"
     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"
+
   gdb_test "python print(gdb.lookup_type('char').array(1, 0))" \
       "char \\\[0\\\]"
 
-- 
2.22.0.rc1.257.g3120a18244-goog

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-23 21:37   ` Christian Biesinger via gdb-patches
@ 2019-05-28 22:07     ` Tom Tromey
  2019-05-30 17:01       ` Christian Biesinger via gdb-patches
  0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2019-05-28 22:07 UTC (permalink / raw)
  To: Christian Biesinger via gdb-patches; +Cc: Christian Biesinger

>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:

Christian> This allows users of the Python API to find the objfile where a type
Christian> was defined.

Could you say what your motivation is for adding this?

The reason I ask is that I still harbor some hopes that we can complete
the "objfile splitting" project, and if so, then it wouldn't be possible
to associate a type with a single objfile.

I suppose maybe we could make the Python wrappers per-objfile.  So, this
patch maybe wouldn't necessarily limit this.

The patch itself looks fine to me.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-28 22:07     ` Tom Tromey
@ 2019-05-30 17:01       ` Christian Biesinger via gdb-patches
  2019-06-03 19:50         ` Tom Tromey
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-05-30 17:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Christian Biesinger via gdb-patches

On Tue, May 28, 2019 at 5:07 PM Tom Tromey <tom@tromey.com> wrote:
> >>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
> Christian> This allows users of the Python API to find the objfile where a type
> Christian> was defined.
>
> Could you say what your motivation is for adding this?
>
> The reason I ask is that I still harbor some hopes that we can complete
> the "objfile splitting" project, and if so, then it wouldn't be possible
> to associate a type with a single objfile.
>
> I suppose maybe we could make the Python wrappers per-objfile.  So, this
> patch maybe wouldn't necessarily limit this.

I'm not sure what the objfile splitting this is about, but the
motivation is as follows. I want to use this API for better supporting
a project called JsDbg, which is basically (for the purpose of this
question) a data structure visualizer for multiple debuggers
(https://github.com/MicrosoftEdge/JsDbg/blob/master/docs/FEATURES.md).
I would like access to the objfile (really I just care about the name
of the shared library/executable) to disambiguate typenames that may
be the same in different solibs. I know that this doesn't handle the
case where the different solibs are all loaded in the same process,
but that should be ok.

Does that sound reasonable?

Christian

>
> The patch itself looks fine to me.
>
> Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-05-30 17:01       ` Christian Biesinger via gdb-patches
@ 2019-06-03 19:50         ` Tom Tromey
  2019-06-03 20:28           ` Christian Biesinger via gdb-patches
  0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2019-06-03 19:50 UTC (permalink / raw)
  To: Christian Biesinger via gdb-patches; +Cc: Tom Tromey, Christian Biesinger

>>>>> ">" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:

Tom> I suppose maybe we could make the Python wrappers per-objfile.  So, this
Tom> patch maybe wouldn't necessarily limit this.

>> I'm not sure what the objfile splitting this is about, but the
>> motivation is as follows.
[...]

>> Does that sound reasonable?

Yeah, thanks for clarifying.  If you think you will be writing future
gdb changes, we should set you up with write-after-approval access.
Email me off-list to do that.  Otherwise, if you'd prefer, I can commit
it on your behalf.

thanks,
Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-06-03 19:50         ` Tom Tromey
@ 2019-06-03 20:28           ` Christian Biesinger via gdb-patches
  2019-06-04 15:47             ` Tom Tromey
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-06-03 20:28 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Christian Biesinger via gdb-patches

On Mon, Jun 3, 2019 at 2:50 PM Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> ">" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tom> I suppose maybe we could make the Python wrappers per-objfile.  So, this
> Tom> patch maybe wouldn't necessarily limit this.
>
> >> I'm not sure what the objfile splitting this is about, but the
> >> motivation is as follows.
> [...]
>
> >> Does that sound reasonable?
>
> Yeah, thanks for clarifying.  If you think you will be writing future
> gdb changes, we should set you up with write-after-approval access.
> Email me off-list to do that.  Otherwise, if you'd prefer, I can commit
> it on your behalf.

I don't think I'll be writing enough patches for that to be worth it,
so it would be great if you could commit this. Thanks!

Christian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-06-03 20:28           ` Christian Biesinger via gdb-patches
@ 2019-06-04 15:47             ` Tom Tromey
  2019-06-04 21:48               ` Pedro Alves
  0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2019-06-04 15:47 UTC (permalink / raw)
  To: Christian Biesinger via gdb-patches; +Cc: Tom Tromey, Christian Biesinger

>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:

Christian> I don't think I'll be writing enough patches for that to be worth it,
Christian> so it would be great if you could commit this. Thanks!

I checked it in.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-06-04 15:47             ` Tom Tromey
@ 2019-06-04 21:48               ` Pedro Alves
  2019-06-04 22:07                 ` Christian Biesinger via gdb-patches
  0 siblings, 1 reply; 16+ messages in thread
From: Pedro Alves @ 2019-06-04 21:48 UTC (permalink / raw)
  To: Tom Tromey, Christian Biesinger via gdb-patches; +Cc: Christian Biesinger

On 6/4/19 4:47 PM, Tom Tromey wrote:
>>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Christian> I don't think I'll be writing enough patches for that to be worth it,
> Christian> so it would be great if you could commit this. Thanks!
> 
> I checked it in.

FYI, I pushed in these fixes to the ChangeLog files.

Christian, the issue here is that entry paths are relative to the
corresponding ChangeLog file.

From d3238f7d90715dad7e8da2a8c2486d26124b0c84 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Tue, 4 Jun 2019 22:44:36 +0100
Subject: [PATCH] Fix paths to ChangeLog files

---
 gdb/ChangeLog           | 4 ++--
 gdb/doc/ChangeLog       | 2 +-
 gdb/testsuite/ChangeLog | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 933f23249ff..e36eae9ac16 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,8 +1,8 @@
 2019-06-04  Christian Biesinger  <cbiesinger@google.com>
 
 	Add objfile property to gdb.Type.
-	* gdb/NEWS: Mention Python API addition.
-	* gdb/python/py-type.c (typy_get_objfile): New method.
+	* NEWS: Mention Python API addition.
+	* python/py-type.c (typy_get_objfile): New method.
 
 2019-06-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ea98096845a..5da25996b1c 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,6 +1,6 @@
 2019-06-04  Christian Biesinger  <cbiesinger@google.com>
 
-	* gdb/doc/python.texi: Document new gdb.Type.objfile property.
+	* python.texi: Document new gdb.Type.objfile property.
 
 2019-06-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index af451fa4e12..722249f822c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,7 +1,6 @@
 2019-06-04  Christian Biesinger  <cbiesinger@google.com>
 
-	* gdb/testsuite/gdb.python/py-type.exp: Test for new
-	  gdb.Type.objfile property.
+	* gdb.python/py-type.exp: Test for new gdb.Type.objfile property.
 
 2019-06-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
-- 
2.14.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-06-04 21:48               ` Pedro Alves
@ 2019-06-04 22:07                 ` Christian Biesinger via gdb-patches
  2019-06-05  1:51                   ` Tom Tromey
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-06-04 22:07 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, Christian Biesinger via gdb-patches

On Tue, Jun 4, 2019 at 4:48 PM Pedro Alves <palves@redhat.com> wrote:
>
> On 6/4/19 4:47 PM, Tom Tromey wrote:
> >>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
> >
> > Christian> I don't think I'll be writing enough patches for that to be worth it,
> > Christian> so it would be great if you could commit this. Thanks!
> >
> > I checked it in.
>
> FYI, I pushed in these fixes to the ChangeLog files.
>
> Christian, the issue here is that entry paths are relative to the
> corresponding ChangeLog file.

Oh, sorry about that! Thanks for fixing!

Christian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] Add an objfile getter to gdb.Type
  2019-06-04 22:07                 ` Christian Biesinger via gdb-patches
@ 2019-06-05  1:51                   ` Tom Tromey
  0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-06-05  1:51 UTC (permalink / raw)
  To: Christian Biesinger
  Cc: Pedro Alves, Tom Tromey, Christian Biesinger via gdb-patches

>>>>> "Christian" == Christian Biesinger <cbiesinger@google.com> writes:

>> Christian, the issue here is that entry paths are relative to the
>> corresponding ChangeLog file.

Christian> Oh, sorry about that! Thanks for fixing!

Oops on me too, I should have read more closely.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-06-05  1:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23 18:40 [PATCH] Add an objfile getter to gdb.Type Christian Biesinger via gdb-patches
2019-05-23 19:01 ` Eli Zaretskii
2019-05-23 19:34 ` Simon Marchi
2019-05-23 20:36   ` Christian Biesinger via gdb-patches
2019-05-23 20:32 ` Christian Biesinger via gdb-patches
2019-05-23 21:06   ` Simon Marchi
2019-05-23 21:25     ` Christian Biesinger via gdb-patches
2019-05-23 21:37   ` Christian Biesinger via gdb-patches
2019-05-28 22:07     ` Tom Tromey
2019-05-30 17:01       ` Christian Biesinger via gdb-patches
2019-06-03 19:50         ` Tom Tromey
2019-06-03 20:28           ` Christian Biesinger via gdb-patches
2019-06-04 15:47             ` Tom Tromey
2019-06-04 21:48               ` Pedro Alves
2019-06-04 22:07                 ` Christian Biesinger via gdb-patches
2019-06-05  1:51                   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).