[PATCH 5/7] [python] API for macros: gdb.Objfile symtabs method.

matt rice
2011-08-24T15:11:52Z

2011-08-23 Matt Rice <ratmice@gmail.com>

* python/py-symtab.h: New file. Make symtab_to_symtab_object public.
* python/py-objfile.c (objfpy_symtabs): New method.
(objfile_object_methods): Ditto.
---
gdb/python/py-objfile.c | 42 ++++++++++++++++++++++++++++++++++++++++++
gdb/python/py-symtab.h | 26 ++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 0 deletions(-)
create mode 100644 gdb/python/py-symtab.h

diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index f9821f5..1c121ae 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -22,6 +22,7 @@
#include "charset.h"
#include "objfiles.h"
#include "language.h"
+#include "py-symtab.h"

typedef struct
{
@@ -118,6 +119,44 @@ objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
return 0;
}

+static PyObject *
+objfpy_symtabs (PyObject *self, PyObject *ignore)
+{
+ objfile_object *obj = (objfile_object *) self;
+ struct symtab *symtabs;
+ PyObject *list;
+ PyObject *py_symtab;
+
+ if (! obj->objfile)
+ return Py_None;
+
+ list = PyList_New (0);
+ if (!list)
+ return NULL;
+
+ symtabs = obj->objfile->symtabs;
+ while(symtabs)
+ {
+ py_symtab = symtab_to_symtab_object (symtabs);
+ if (! py_symtab)
+ goto fail;
+
+ if (PyList_Append (list, py_symtab) != 0)
+ goto fail;
+
+ Py_DECREF (py_symtab);
+
+ symtabs = symtabs->next;
+ }
+
+ return list;
+
+ fail:
+ Py_XDECREF (py_symtab);
+ Py_XDECREF (list);
+ return NULL;
+}
+
/* Implementation of gdb.Objfile.is_valid (self) -> Boolean.
Returns True if this object file still exists in GDB. */

@@ -200,6 +239,9 @@ static PyMethodDef objfile_object_methods[] =
{ "is_valid", objfpy_is_valid, METH_NOARGS,
"is_valid () -> Boolean.\n\
Return true if this object file is valid, false if not." },
+ { "symtabs", objfpy_symtabs, METH_NOARGS,
+ "symtabs () -> List.\n\
+A List containing the object file's valid symtabs." },

{ NULL }
};
diff --git a/gdb/python/py-symtab.h b/gdb/python/py-symtab.h
new file mode 100644
index 0000000..10c89cb
--- /dev/null
+++ b/gdb/python/py-symtab.h
@@ -0,0 +1,26 @@
+/* Python interface to Symtabs and Symtab_and_line's.
+
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GDB_PY_SYMTAB_H
+#define GDB_PY_SYMTAB_H
+
+PyObject *
+symtab_to_symtab_object (struct symtab *symtab);
+
+#endif /* GDB_PY_SYMTAB_H */
--
1.7.4.4