diff options
author | Doug Evans <dje@google.com> | 2014-12-04 11:32:24 -0800 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2014-12-04 11:32:24 -0800 |
commit | 7c50a93137df660f7b2d9d68c0db748a9cb7868f (patch) | |
tree | b47c96bea08c023b78798039c98e18c9dafbd632 /gdb/python | |
parent | fbad6518c1397939ea2d832eea7e53f2147759a8 (diff) | |
download | gdb-7c50a93137df660f7b2d9d68c0db748a9cb7868f.zip gdb-7c50a93137df660f7b2d9d68c0db748a9cb7868f.tar.gz gdb-7c50a93137df660f7b2d9d68c0db748a9cb7868f.tar.bz2 |
New python attribute gdb.Objfile.build_id.
gdb/ChangeLog:
* NEWS: Mention gdb.Objfile.build_id.
* build-id.c (build_id_bfd_get): Make non-static.
* build-id.h (build_id_bfd_get): Add declaration.
* python/py-objfile.c: #include "build-id.h", "elf-bfd.h".
(OBJFPY_REQUIRE_VALID): New macro.
(objfpy_get_build_id): New function.
(objfile_getset): Add "build_id".
* utils.c (make_hex_string): New function.
* utils.h (make_hex_string): Add declaration.
gdb/doc/ChangeLog:
* python.texi (Objfiles In Python): Document Objfile.build_id.
gdb/testsuite/ChangeLog:
* lib/gdb.exp (get_build_id): New function.
(build_id_debug_filename_get): Rewrite to use it.
* gdb.python/py-objfile.exp: Add test for objfile.build_id.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-objfile.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index c99de87..05a7c21 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -22,6 +22,8 @@ #include "charset.h" #include "objfiles.h" #include "language.h" +#include "build-id.h" +#include "elf-bfd.h" typedef struct { @@ -51,9 +53,21 @@ static PyTypeObject objfile_object_type static const struct objfile_data *objfpy_objfile_data_key; +/* Require that OBJF be a valid objfile. */ +#define OBJFPY_REQUIRE_VALID(obj) \ + do { \ + if (!(obj)->objfile) \ + { \ + PyErr_SetString (PyExc_RuntimeError, \ + _("Objfile no longer exists.")); \ + return NULL; \ + } \ + } while (0) + /* An Objfile method which returns the objfile's file name, or None. */ + static PyObject * objfpy_get_filename (PyObject *self, void *closure) { @@ -66,6 +80,38 @@ objfpy_get_filename (PyObject *self, void *closure) Py_RETURN_NONE; } +/* An Objfile method which returns the objfile's build id, or None. */ + +static PyObject * +objfpy_get_build_id (PyObject *self, void *closure) +{ + objfile_object *obj = (objfile_object *) self; + struct objfile *objfile = obj->objfile; + const struct elf_build_id *build_id = NULL; + volatile struct gdb_exception except; + + OBJFPY_REQUIRE_VALID (obj); + + TRY_CATCH (except, RETURN_MASK_ALL) + { + build_id = build_id_bfd_get (objfile->obfd); + } + GDB_PY_HANDLE_EXCEPTION (except); + + if (build_id != NULL) + { + char *hex_form = make_hex_string (build_id->data, build_id->size); + PyObject *result; + + result = PyString_Decode (hex_form, strlen (hex_form), + host_charset (), NULL); + xfree (hex_form); + return result; + } + + Py_RETURN_NONE; +} + /* An Objfile method which returns the objfile's progspace, or None. */ static PyObject * @@ -364,6 +410,8 @@ static PyGetSetDef objfile_getset[] = "The __dict__ for this objfile.", &objfile_object_type }, { "filename", objfpy_get_filename, NULL, "The objfile's filename, or None.", NULL }, + { "build_id", objfpy_get_build_id, NULL, + "The objfile's build id, or None.", NULL }, { "progspace", objfpy_get_progspace, NULL, "The objfile's progspace, or None.", NULL }, { "pretty_printers", objfpy_get_printers, objfpy_set_printers, |