/* Python interface to blocks.
- Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008-2016 Free Software Foundation, Inc.
This file is part of GDB.
typedef struct {
PyObject_HEAD
- /* The block dictionary of symbols. */
- struct dictionary *dict;
- /* The iterator for that dictionary. */
- struct dict_iterator iter;
+ /* The block. */
+ const struct block *block;
+ /* The iterator for that block. */
+ struct block_iterator iter;
/* Has the iterator been initialized flag. */
int initialized_p;
/* Pointer back to the original source block object. Needed to
} \
} while (0)
-static PyTypeObject block_syms_iterator_object_type;
+extern PyTypeObject block_syms_iterator_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object");
static const struct objfile_data *blpy_objfile_data_key;
static PyObject *
if (block_iter_obj == NULL)
return NULL;
- block_iter_obj->dict = BLOCK_DICT (block);
+ block_iter_obj->block = block;
block_iter_obj->initialized_p = 0;
Py_INCREF (self);
block_iter_obj->source = (block_object *) self;
if (objfile)
{
obj->objfile = objfile;
- obj->next = objfile_data (objfile, blpy_objfile_data_key);
+ obj->next = ((struct blpy_block_object *)
+ objfile_data (objfile, blpy_objfile_data_key));
if (obj->next)
obj->next->prev = obj;
set_objfile_data (objfile, blpy_objfile_data_key, obj);
if (!iter_obj->initialized_p)
{
- sym = dict_iterator_first (iter_obj->dict, &(iter_obj->iter));
+ sym = block_iterator_first (iter_obj->block, &(iter_obj->iter));
iter_obj->initialized_p = 1;
}
else
- sym = dict_iterator_next (&(iter_obj->iter));
+ sym = block_iterator_next (&(iter_obj->iter));
if (sym == NULL)
{
gdbpy_block_for_pc (PyObject *self, PyObject *args)
{
gdb_py_ulongest pc;
- struct block *block;
- struct obj_section *section;
- struct symtab *symtab;
+ const struct block *block = NULL;
+ struct compunit_symtab *cust = NULL;
if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
return NULL;
- section = find_pc_mapped_section (pc);
- symtab = find_pc_sect_symtab (pc, section);
- if (!symtab || symtab->objfile == NULL)
+ TRY
+ {
+ cust = find_pc_compunit_symtab (pc);
+
+ if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
+ block = block_for_pc (pc);
+ }
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
+
+ if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
{
PyErr_SetString (PyExc_RuntimeError,
_("Cannot locate object file for block."));
return NULL;
}
- block = block_for_pc (pc);
if (block)
- return block_to_block_object (block, symtab->objfile);
+ return block_to_block_object (block, COMPUNIT_OBJFILE (cust));
Py_RETURN_NONE;
}
static void
del_objfile_blocks (struct objfile *objfile, void *datum)
{
- block_object *obj = datum;
+ block_object *obj = (block_object *) datum;
while (obj)
{
}
}
-void
+int
gdbpy_initialize_blocks (void)
{
block_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_object_type) < 0)
- return;
+ return -1;
block_syms_iterator_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_syms_iterator_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate blocks when an object file is about to be
blpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
- Py_INCREF (&block_object_type);
- PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
+ if (gdb_pymodule_addobject (gdb_module, "Block",
+ (PyObject *) &block_object_type) < 0)
+ return -1;
- Py_INCREF (&block_syms_iterator_object_type);
- PyModule_AddObject (gdb_module, "BlockIterator",
- (PyObject *) &block_syms_iterator_object_type);
+ return gdb_pymodule_addobject (gdb_module, "BlockIterator",
+ (PyObject *) &block_syms_iterator_object_type);
}
\f
};
PyTypeObject block_object_type = {
- PyObject_HEAD_INIT (NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT (NULL, 0)
"gdb.Block", /*tp_name*/
sizeof (block_object), /*tp_basicsize*/
0, /*tp_itemsize*/
{NULL} /* Sentinel */
};
-static PyTypeObject block_syms_iterator_object_type = {
- PyObject_HEAD_INIT (NULL)
- 0, /*ob_size*/
+PyTypeObject block_syms_iterator_object_type = {
+ PyVarObject_HEAD_INIT (NULL, 0)
"gdb.BlockIterator", /*tp_name*/
sizeof (block_syms_iterator_object), /*tp_basicsize*/
0, /*tp_itemsize*/