From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25350 invoked by alias); 24 Aug 2011 15:11:52 -0000 Received: (qmail 25333 invoked by uid 22791); 24 Aug 2011 15:11:49 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_BJ,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-yw0-f41.google.com (HELO mail-yw0-f41.google.com) (209.85.213.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Aug 2011 15:11:20 +0000 Received: by ywm13 with SMTP id 13so997950ywm.0 for ; Wed, 24 Aug 2011 08:11:20 -0700 (PDT) Received: by 10.91.181.20 with SMTP id i20mr5035494agp.9.1314198679440; Wed, 24 Aug 2011 08:11:19 -0700 (PDT) Received: from localhost.localdomain (c-98-232-221-4.hsd1.or.comcast.net [98.232.221.4]) by mx.google.com with ESMTPS id d7sm968071anb.40.2011.08.24.08.11.18 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 08:11:19 -0700 (PDT) From: matt rice To: gdb-patches@sourceware.org Cc: matt rice Subject: [PATCH 5/7] [python] API for macros: gdb.Objfile symtabs method. Date: Wed, 24 Aug 2011 15:11:00 -0000 Message-Id: <1314198654-9008-6-git-send-email-ratmice@gmail.com> In-Reply-To: <1314198654-9008-1-git-send-email-ratmice@gmail.com> References: <1314198654-9008-1-git-send-email-ratmice@gmail.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-08/txt/msg00443.txt.bz2 2011-08-23 Matt Rice * 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 . */ + +#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