/* Python interface to objfiles.
- Copyright (C) 2008-2015 Free Software Foundation, Inc.
+ Copyright (C) 2008-2017 Free Software Foundation, Inc.
This file is part of GDB.
#include "objfiles.h"
#include "language.h"
#include "build-id.h"
-#include "elf-bfd.h"
#include "symtab.h"
+#include "py-ref.h"
typedef struct
{
/* The frame filter list of functions. */
PyObject *frame_filters;
+
+ /* The list of frame unwinders. */
+ PyObject *frame_unwinders;
+
/* The type-printer list. */
PyObject *type_printers;
PyObject *xmethods;
} objfile_object;
-static PyTypeObject objfile_object_type
+extern PyTypeObject objfile_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("objfile_object");
static const struct objfile_data *objfpy_objfile_data_key;
objfile_object *obj = (objfile_object *) self;
if (obj->objfile)
- return PyString_Decode (objfile_name (obj->objfile),
- strlen (objfile_name (obj->objfile)),
- host_charset (), NULL);
+ return host_string_to_python_string (objfile_name (obj->objfile));
Py_RETURN_NONE;
}
{
const char *username = obj->objfile->original_name;
- return PyString_Decode (username, strlen (username),
- host_charset (), NULL);
+ return host_string_to_python_string (username);
}
Py_RETURN_NONE;
{
objfile_object *obj = (objfile_object *) self;
struct objfile *objfile = obj->objfile;
- const struct elf_build_id *build_id = NULL;
- volatile struct gdb_exception except;
+ const struct bfd_build_id *build_id = NULL;
OBJFPY_REQUIRE_VALID (obj);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
build_id = build_id_bfd_get (objfile->obfd);
}
- GDB_PY_HANDLE_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
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);
+ result = host_string_to_python_string (hex_form);
xfree (hex_form);
return result;
}
Py_XDECREF (self->dict);
Py_XDECREF (self->printers);
Py_XDECREF (self->frame_filters);
+ Py_XDECREF (self->frame_unwinders);
Py_XDECREF (self->type_printers);
Py_XDECREF (self->xmethods);
Py_TYPE (self)->tp_free (self);
objfpy_initialize (objfile_object *self)
{
self->objfile = NULL;
- self->dict = NULL;
+
+ self->dict = PyDict_New ();
+ if (self->dict == NULL)
+ return 0;
self->printers = PyList_New (0);
if (self->printers == NULL)
if (self->frame_filters == NULL)
return 0;
+ self->frame_unwinders = PyList_New (0);
+ if (self->frame_unwinders == NULL)
+ return 0;
+
self->type_printers = PyList_New (0);
if (self->type_printers == NULL)
return 0;
static PyObject *
objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
{
- objfile_object *self = (objfile_object *) type->tp_alloc (type, 0);
+ gdbpy_ref<objfile_object> self ((objfile_object *) type->tp_alloc (type, 0));
- if (self)
+ if (self != NULL)
{
- if (!objfpy_initialize (self))
- {
- Py_DECREF (self);
- return NULL;
- }
+ if (!objfpy_initialize (self.get ()))
+ return NULL;
}
- return (PyObject *) self;
+ return (PyObject *) self.release ();
}
PyObject *
return 0;
}
+/* Return the frame unwinders attribute for this object file. */
+
+PyObject *
+objfpy_get_frame_unwinders (PyObject *o, void *ignore)
+{
+ objfile_object *self = (objfile_object *) o;
+
+ Py_INCREF (self->frame_unwinders);
+ return self->frame_unwinders;
+}
+
+/* Set this object file's frame unwinders list to UNWINDERS. */
+
+static int
+objfpy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
+{
+ PyObject *tmp;
+ objfile_object *self = (objfile_object *) o;
+
+ if (!unwinders)
+ {
+ PyErr_SetString (PyExc_TypeError,
+ _("Cannot delete the frame unwinders attribute."));
+ return -1;
+ }
+
+ if (!PyList_Check (unwinders))
+ {
+ PyErr_SetString (PyExc_TypeError,
+ _("The frame_unwinders attribute must be a list."));
+ return -1;
+ }
+
+ /* Take care in case the LHS and RHS are related somehow. */
+ tmp = self->frame_unwinders;
+ Py_INCREF (unwinders);
+ self->frame_unwinders = unwinders;
+ Py_XDECREF (tmp);
+
+ return 0;
+}
+
/* Get the 'type_printers' attribute. */
static PyObject *
static PyObject *
objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = { "file_name", NULL };
+ static const char *keywords[] = { "file_name", NULL };
objfile_object *obj = (objfile_object *) self;
const char *file_name;
- int symfile_flags = 0;
- volatile struct gdb_exception except;
OBJFPY_REQUIRE_VALID (obj);
- if (!PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
return NULL;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
- bfd *abfd = symfile_bfd_open (file_name);
+ gdb_bfd_ref_ptr abfd (symfile_bfd_open (file_name));
- symbol_file_add_separate (abfd, file_name, symfile_flags, obj->objfile);
+ symbol_file_add_separate (abfd.get (), file_name, 0, obj->objfile);
+ }
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
}
- GDB_PY_HANDLE_EXCEPTION (except);
+ END_CATCH
Py_RETURN_NONE;
}
It is assumed that objfpy_build_id_ok (string) returns TRUE. */
static int
-objfpy_build_id_matches (const struct elf_build_id *build_id,
+objfpy_build_id_matches (const struct bfd_build_id *build_id,
const char *string)
{
size_t i;
ALL_OBJFILES (objfile)
{
- const struct elf_build_id *obfd_build_id;
+ const struct bfd_build_id *obfd_build_id;
if (objfile->obfd == NULL)
continue;
PyObject *
gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = { "name", "by_build_id", NULL };
+ static const char *keywords[] = { "name", "by_build_id", NULL };
const char *name;
PyObject *by_build_id_obj = NULL;
int by_build_id;
struct objfile *objfile;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
- &name, &PyBool_Type, &by_build_id_obj))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
+ &name, &PyBool_Type, &by_build_id_obj))
return NULL;
by_build_id = 0;
static void
py_free_objfile (struct objfile *objfile, void *datum)
{
- struct cleanup *cleanup;
- objfile_object *object = datum;
-
- cleanup = ensure_python_env (get_objfile_arch (objfile), current_language);
+ gdbpy_enter enter_py (get_objfile_arch (objfile), current_language);
+ gdbpy_ref<objfile_object> object ((objfile_object *) datum);
object->objfile = NULL;
- Py_DECREF ((PyObject *) object);
- do_cleanups (cleanup);
}
/* Return a borrowed reference to the Python object of type Objfile
PyObject *
objfile_to_objfile_object (struct objfile *objfile)
{
- objfile_object *object;
-
- object = objfile_data (objfile, objfpy_objfile_data_key);
- if (!object)
+ gdbpy_ref<objfile_object> object
+ ((objfile_object *) objfile_data (objfile, objfpy_objfile_data_key));
+ if (object == NULL)
{
- object = PyObject_New (objfile_object, &objfile_object_type);
- if (object)
+ object.reset (PyObject_New (objfile_object, &objfile_object_type));
+ if (object != NULL)
{
- if (!objfpy_initialize (object))
- {
- Py_DECREF (object);
- return NULL;
- }
+ if (!objfpy_initialize (object.get ()))
+ return NULL;
object->objfile = objfile;
- set_objfile_data (objfile, objfpy_objfile_data_key, object);
+ set_objfile_data (objfile, objfpy_objfile_data_key, object.get ());
}
}
- return (PyObject *) object;
+ return (PyObject *) object.release ();
}
int
{ NULL }
};
-static PyGetSetDef objfile_getset[] =
+static gdb_PyGetSetDef objfile_getset[] =
{
{ "__dict__", gdb_py_generic_dict, NULL,
"The __dict__ for this objfile.", &objfile_object_type },
"Pretty printers.", NULL },
{ "frame_filters", objfpy_get_frame_filters,
objfpy_set_frame_filters, "Frame Filters.", NULL },
+ { "frame_unwinders", objfpy_get_frame_unwinders,
+ objfpy_set_frame_unwinders, "Frame Unwinders", NULL },
{ "type_printers", objfpy_get_type_printers, objfpy_set_type_printers,
"Type printers.", NULL },
{ "xmethods", objfpy_get_xmethods, NULL,
{ NULL }
};
-static PyTypeObject objfile_object_type =
+PyTypeObject objfile_object_type =
{
PyVarObject_HEAD_INIT (NULL, 0)
"gdb.Objfile", /*tp_name*/