Index: gdb/python/py-symtab.c |
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c |
index b6f45e6d8d8f43c83f3d8fb83897cc148f956dac..c4a3fea6a42de083e49671a04ad3c523d9ec9f44 100644 |
--- a/gdb/python/py-symtab.c |
+++ b/gdb/python/py-symtab.c |
@@ -1,6 +1,6 @@ |
/* Python interface to symbol tables. |
- Copyright (C) 2008-2012 Free Software Foundation, Inc. |
+ Copyright (C) 2008-2013 Free Software Foundation, Inc. |
This file is part of GDB. |
@@ -37,7 +37,8 @@ typedef struct stpy_symtab_object { |
struct stpy_symtab_object *next; |
} symtab_object; |
-static PyTypeObject symtab_object_type; |
+static PyTypeObject symtab_object_type |
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object"); |
static const struct objfile_data *stpy_objfile_data_key; |
/* Require a valid symbol table. All access to symtab_object->symtab |
@@ -67,7 +68,8 @@ typedef struct salpy_sal_object { |
struct salpy_sal_object *next; |
} sal_object; |
-static PyTypeObject sal_object_type; |
+static PyTypeObject sal_object_type |
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object"); |
static const struct objfile_data *salpy_objfile_data_key; |
/* Require a valid symbol table and line object. All access to |
@@ -91,7 +93,7 @@ stpy_str (PyObject *self) |
STPY_REQUIRE_VALID (self, symtab); |
- result = PyString_FromString (symtab->filename); |
+ result = PyString_FromString (symtab_to_filename_for_display (symtab)); |
return result; |
} |
@@ -101,11 +103,12 @@ stpy_get_filename (PyObject *self, void *closure) |
{ |
PyObject *str_obj; |
struct symtab *symtab = NULL; |
+ const char *filename; |
STPY_REQUIRE_VALID (self, symtab); |
+ filename = symtab_to_filename_for_display (symtab); |
- str_obj = PyString_Decode (symtab->filename, |
- strlen (symtab->filename), |
+ str_obj = PyString_Decode (filename, strlen (filename), |
host_charset (), NULL); |
return str_obj; |
} |
@@ -126,17 +129,14 @@ stpy_get_objfile (PyObject *self, void *closure) |
static PyObject * |
stpy_fullname (PyObject *self, PyObject *args) |
{ |
- char *fullname; |
+ const char *fullname; |
struct symtab *symtab = NULL; |
STPY_REQUIRE_VALID (self, symtab); |
fullname = symtab_to_fullname (symtab); |
- if (fullname) |
- return PyString_Decode (fullname, strlen (fullname), |
- host_charset (), NULL); |
- Py_RETURN_NONE; |
+ return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL); |
} |
/* Implementation of gdb.Symtab.is_valid (self) -> Boolean. |
@@ -186,10 +186,25 @@ stpy_static_block (PyObject *self, PyObject *args) |
return block_to_block_object (block, symtab->objfile); |
} |
+/* Implementation of gdb.Symtab.linetable (self) -> gdb.Linetable. |
+ Returns a gdb.Linetable object corresponding to this symbol |
+ table. */ |
+ |
+static PyObject * |
+stpy_get_linetable (PyObject *self, PyObject *args) |
+{ |
+ struct symtab *symtab = NULL; |
+ |
+ STPY_REQUIRE_VALID (self, symtab); |
+ |
+ return symtab_to_linetable_object (self); |
+} |
+ |
static PyObject * |
salpy_str (PyObject *self) |
{ |
- char *s, *filename; |
+ char *s; |
+ const char *filename; |
sal_object *sal_obj; |
PyObject *result; |
struct symtab_and_line *sal = NULL; |
@@ -198,7 +213,7 @@ salpy_str (PyObject *self) |
sal_obj = (sal_object *) self; |
filename = (sal_obj->symtab == (symtab_object *) Py_None) |
- ? "<unknown>" : sal_obj->symtab->symtab->filename; |
+ ? "<unknown>" : symtab_to_filename_for_display (sal_obj->symtab->symtab); |
s = xstrprintf ("symbol and line for %s, line %d", filename, |
sal->line); |
@@ -307,16 +322,15 @@ salpy_dealloc (PyObject *self) |
Py_DECREF (self_sal->symtab); |
xfree (self_sal->sal); |
- self_sal->ob_type->tp_free (self); |
+ Py_TYPE (self)->tp_free (self); |
} |
/* Given a sal, and a sal_object that has previously been allocated |
and initialized, populate the sal_object with the struct sal data. |
Also, register the sal_object life-cycle with the life-cycle of the |
object file associated with this sal, if needed. If a failure |
- occurs during the sal population, this function will return |
- NULL. */ |
-static int |
+ occurs during the sal population, this function will return -1. */ |
+static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION |
set_sal (sal_object *sal_obj, struct symtab_and_line sal) |
{ |
symtab_object *symtab_obj; |
@@ -327,7 +341,7 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal) |
/* If a symtab existed in the sal, but it cannot be duplicated, |
we exit. */ |
if (symtab_obj == NULL) |
- return 0; |
+ return -1; |
} |
else |
{ |
@@ -355,7 +369,7 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal) |
else |
sal_obj->next = NULL; |
- return 1; |
+ return 0; |
} |
/* Given a symtab, and a symtab_object that has previously been |
@@ -397,7 +411,6 @@ symtab_to_symtab_object (struct symtab *symtab) |
that encapsulates the symtab_and_line structure from GDB. */ |
PyObject * |
symtab_and_line_to_sal_object (struct symtab_and_line sal) |
- |
{ |
sal_object *sal_obj; |
int success = 0; |
@@ -405,8 +418,7 @@ symtab_and_line_to_sal_object (struct symtab_and_line sal) |
sal_obj = PyObject_New (sal_object, &sal_object_type); |
if (sal_obj) |
{ |
- success = set_sal (sal_obj, sal); |
- if (!success) |
+ if (set_sal (sal_obj, sal) < 0) |
{ |
Py_DECREF (sal_obj); |
return NULL; |
@@ -470,7 +482,10 @@ del_objfile_sal (struct objfile *objfile, void *datum) |
{ |
sal_object *next = obj->next; |
- obj->symtab = NULL; |
+ Py_DECREF (obj->symtab); |
+ obj->symtab = (symtab_object *) Py_None; |
+ Py_INCREF (Py_None); |
+ |
obj->next = NULL; |
obj->prev = NULL; |
xfree (obj->sal); |
@@ -480,16 +495,16 @@ del_objfile_sal (struct objfile *objfile, void *datum) |
} |
} |
-void |
+int |
gdbpy_initialize_symtabs (void) |
{ |
symtab_object_type.tp_new = PyType_GenericNew; |
if (PyType_Ready (&symtab_object_type) < 0) |
- return; |
+ return -1; |
sal_object_type.tp_new = PyType_GenericNew; |
if (PyType_Ready (&sal_object_type) < 0) |
- return; |
+ return -1; |
/* Register an objfile "free" callback so we can properly |
invalidate symbol tables, and symbol table and line data |
@@ -500,13 +515,12 @@ gdbpy_initialize_symtabs (void) |
salpy_objfile_data_key |
= register_objfile_data_with_cleanup (NULL, del_objfile_sal); |
- Py_INCREF (&symtab_object_type); |
- PyModule_AddObject (gdb_module, "Symtab", |
- (PyObject *) &symtab_object_type); |
+ if (gdb_pymodule_addobject (gdb_module, "Symtab", |
+ (PyObject *) &symtab_object_type) < 0) |
+ return -1; |
- Py_INCREF (&sal_object_type); |
- PyModule_AddObject (gdb_module, "Symtab_and_line", |
- (PyObject *) &sal_object_type); |
+ return gdb_pymodule_addobject (gdb_module, "Symtab_and_line", |
+ (PyObject *) &sal_object_type); |
} |
@@ -532,12 +546,14 @@ Return the global block of the symbol table." }, |
{ "static_block", stpy_static_block, METH_NOARGS, |
"static_block () -> gdb.Block.\n\ |
Return the static block of the symbol table." }, |
+ { "linetable", stpy_get_linetable, METH_NOARGS, |
+ "linetable () -> gdb.Linetable.\n\ |
+Return the Linetable associated with this symbol table" }, |
{NULL} /* Sentinel */ |
}; |
static PyTypeObject symtab_object_type = { |
- PyObject_HEAD_INIT (NULL) |
- 0, /*ob_size*/ |
+ PyVarObject_HEAD_INIT (NULL, 0) |
"gdb.Symtab", /*tp_name*/ |
sizeof (symtab_object), /*tp_basicsize*/ |
0, /*tp_itemsize*/ |
@@ -587,8 +603,7 @@ Return true if this symbol table and line is valid, false if not." }, |
}; |
static PyTypeObject sal_object_type = { |
- PyObject_HEAD_INIT (NULL) |
- 0, /*ob_size*/ |
+ PyVarObject_HEAD_INIT (NULL, 0) |
"gdb.Symtab_and_line", /*tp_name*/ |
sizeof (sal_object), /*tp_basicsize*/ |
0, /*tp_itemsize*/ |