+/* 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;
+}
+