[4/4] python support for fetching separate debug files: is_separate_debug_file

Message ID yjt27fypo97a.fsf@ruffy.mtv.corp.google.com
State New, archived
Headers

Commit Message

Doug Evans Nov. 20, 2014, 9:26 p.m. UTC
  This patch adds the ability for Python code to determine if an objfile
is a separate debug file: the new_objfile event gets called for them
too.

2014-11-20  Doug Evans  <dje@google.com>

	* NEWS: Mention gdb.Objfile.is_separate_debug_file.
	* python/py-objfile.c (objfpy_is_separate_debug_file): New function.
	(objfile_getset): Add "is_separate_debug_file".

	doc/
	* python.texi (Objfiles In Python): Document
	Objfile.is_separate_debug_file.

	testsuite/
	* gdb.python/py-objfile.exp: Add tests for
	objfile.is_separate_debug_file.
  

Comments

Eli Zaretskii Nov. 21, 2014, 7:59 a.m. UTC | #1
> From: Doug Evans <dje@google.com>
> Date: Thu, 20 Nov 2014 13:26:01 -0800
> 
> This patch adds the ability for Python code to determine if an objfile
> is a separate debug file: the new_objfile event gets called for them
> too.
> 
> 2014-11-20  Doug Evans  <dje@google.com>
> 
> 	* NEWS: Mention gdb.Objfile.is_separate_debug_file.
> 	* python/py-objfile.c (objfpy_is_separate_debug_file): New function.
> 	(objfile_getset): Add "is_separate_debug_file".
> 
> 	doc/
> 	* python.texi (Objfiles In Python): Document
> 	Objfile.is_separate_debug_file.
> 
> 	testsuite/
> 	* gdb.python/py-objfile.exp: Add tests for
> 	objfile.is_separate_debug_file.

OK for the documentation parts.

Thanks.
  
Doug Evans Nov. 21, 2014, 6:20 p.m. UTC | #2
On Thu, Nov 20, 2014 at 1:26 PM, Doug Evans <dje@google.com> wrote:
> This patch adds the ability for Python code to determine if an objfile
> is a separate debug file: the new_objfile event gets called for them
> too.
>
> 2014-11-20  Doug Evans  <dje@google.com>
>
>         * NEWS: Mention gdb.Objfile.is_separate_debug_file.
>         * python/py-objfile.c (objfpy_is_separate_debug_file): New function.
>         (objfile_getset): Add "is_separate_debug_file".
>
>         doc/
>         * python.texi (Objfiles In Python): Document
>         Objfile.is_separate_debug_file.
>
>         testsuite/
>         * gdb.python/py-objfile.exp: Add tests for
>         objfile.is_separate_debug_file.

btw, one thought I had here was to instead provide "objfile_owner" or
some such that is either the "backlink" field to the objfile that this
objfile is providing debug symbols for, or None if the objfile is a
"real" objfile.
We could also export the debug file chain
(objfile.separate_debug_objfile_link) but I have no current need for
it so I punted.
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 6f2271e..ca33862 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -11,6 +11,9 @@ 
   ** New attribute 'producer' for gdb.Symtab objects.
   ** gdb.Objfile objects have a new attribute "progspace",
      which is the gdb.Progspace object of the containing program space.
+  ** gdb.Objfile objects have a new attribute "is_separate_debug_file",
+     which is True if the objfile contains debug information for another
+     objfile.
   ** gdb.Objfile objects have a new attribute "build_id",
      which is the build ID generated when the file was built.
   ** gdb.Objfile objects have a new attribute "have_debug_info", which is
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index b6beec7..79bc49b 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3446,6 +3446,10 @@  class.
 The file name of the objfile as a string.
 @end defvar
 
+@defvar Objfile.is_separate_debug_file
+True if the objfile contains debug information for another objfile.
+@end defvar
+
 @defvar Objfile.build_id
 The build ID of the objfile as a string.
 If the objfile does not have a build ID then the value is @code{None}.
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 7a35652f..49c0604 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -80,6 +80,25 @@  objfpy_get_filename (PyObject *self, void *closure)
   Py_RETURN_NONE;
 }
 
+/* An Objfile method which returns a boolean indicating whether the objfile
+   is a separate debug file or not.  */
+
+static PyObject *
+objfpy_get_is_separate_debug_file (PyObject *self, void *closure)
+{
+  objfile_object *obj = (objfile_object *) self;
+  struct objfile *objfile = obj->objfile;
+  int is_separate_debug_file;
+
+  OBJFPY_REQUIRE_VALID (obj);
+
+  is_separate_debug_file = objfile->separate_debug_objfile_backlink != NULL;
+
+  if (is_separate_debug_file)
+    Py_RETURN_TRUE;
+  Py_RETURN_FALSE;
+}
+
 /* An Objfile method which returns the objfile's build id, or None.  */
 
 static PyObject *
@@ -468,6 +487,9 @@  static PyGetSetDef objfile_getset[] =
     "The __dict__ for this objfile.", &objfile_object_type },
   { "filename", objfpy_get_filename, NULL,
     "The objfile's filename, or None.", NULL },
+  { "is_separate_debug_file", objfpy_get_is_separate_debug_file, NULL,
+    "True if the objfile contains debug information for another objfile.",
+    NULL },
   { "build_id", objfpy_get_build_id, NULL,
     "The objfile's build id, or None.", NULL },
   { "have_debug_info", objfpy_get_have_debug_info, NULL,
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index b3de807..b66a6d6 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -79,6 +79,9 @@  if ![runto_main] {
 gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \
     "Get no-debug objfile file" 1
 
+gdb_test "python print (objfile.is_separate_debug_file)" "False" \
+    "Test is_separate_debug_info on real objfile."
+
 gdb_test "python print (objfile.have_debug_info)" "False" \
     "Get objfile have_debug_info"
 
@@ -91,6 +94,9 @@  gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${binfile}\")"
 gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \
     "Get separate debug info objfile" 1
 
+gdb_test "python print (sep_objfile.is_separate_debug_file)" "True" \
+    "Test is_separate_debug_info on separate debug file"
+
 gdb_test "python print (objfile.have_debug_info)" "True" \
     "Get have_debug_info on separate debug file"