Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: matt rice <ratmice@gmail.com>
To: gdb-patches@sourceware.org
Cc: matt rice <ratmice@gmail.com>
Subject: [PATCH 4/7] [python] API for macros: Add methods to get a gdb.Macro.
Date: Wed, 24 Aug 2011 15:12:00 -0000	[thread overview]
Message-ID: <1314198654-9008-5-git-send-email-ratmice@gmail.com> (raw)
In-Reply-To: <1314198654-9008-1-git-send-email-ratmice@gmail.com>

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

	PR python/10807
	* py-symtab.c (stpy_dealloc): Call super's tp_free.
	(salpy_macros, stpy_macros, stpy_macro_named): New methods.
	(sal_object_methods, stpy_object_methods): Add new methods to method list.
---
 gdb/python/py-symtab.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 107cdec..1bceeb6 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -22,6 +22,8 @@
 #include "symtab.h"
 #include "source.h"
 #include "python-internal.h"
+#include "py-macro.h"
+#include "macroscope.h"
 #include "objfiles.h"
 
 typedef struct stpy_symtab_object {
@@ -138,6 +140,35 @@ stpy_fullname (PyObject *self, PyObject *args)
   Py_RETURN_NONE;
 }
 
+static PyObject *
+stpy_macros (PyObject *self, PyObject *args)
+{
+  struct symtab *st = symtab_object_to_symtab (self);
+  PyObject *result;
+  enum macro_walk_result walk_result;
+  struct macropy_user_data mud;
+
+  STPY_REQUIRE_VALID (self, st);
+
+  result = PyList_New (0);
+  if (result == NULL)
+    return NULL;
+
+  mud.list = result;
+  mud.objfile = macro_table_objfile (st->macro_table);
+  walk_result = macro_for_each (st->macro_table,
+				pymacro_add_macro_to_list,
+				&mud);
+
+  if (walk_result == macro_walk_aborted)
+    {
+      Py_DECREF (result);
+      return NULL;
+    }
+
+  return result;
+}
+
 /* Implementation of gdb.Symtab.is_valid (self) -> Boolean.
    Returns True if this Symbol table still exists in GDB.  */
 
@@ -191,6 +222,7 @@ stpy_dealloc (PyObject *obj)
   if (symtab->next)
     symtab->next->prev = symtab->prev;
   symtab->symtab = NULL;
+  obj->ob_type->tp_free (obj);
 }
 
 
@@ -242,6 +274,75 @@ salpy_is_valid (PyObject *self, PyObject *args)
   Py_RETURN_TRUE;
 }
 
+static PyObject *
+salpy_macros (PyObject *self, PyObject *args)
+{
+  struct symtab_and_line *sal;
+  PyObject *result;
+  enum macro_walk_result walk_result;
+  struct macropy_user_data mud;
+  struct macro_scope *ms;
+
+  SALPY_REQUIRE_VALID (self, sal);
+
+  ms = sal_macro_scope (*sal);
+
+  result = PyList_New (0);
+  if (result == NULL)
+    return NULL;
+
+  mud.list = result;
+  mud.objfile = macro_table_objfile (ms->file->table);
+  walk_result = macro_for_each_in_scope (ms->file, ms->line,
+					 pymacro_add_macro_to_list, &mud);
+
+  if (walk_result == macro_walk_aborted)
+    {
+      Py_DECREF (result);
+      return NULL;
+    }
+
+  return result;
+}
+
+static PyObject *
+salpy_macro_named (PyObject *self, PyObject *args)
+{
+  struct symtab_and_line *sal;
+  struct macro_scope *ms;
+  const struct macro_definition *mdef;
+  char *macro_name;
+  struct cleanup *cleanup_chain;
+  struct macro_source_file *file;
+  struct objfile *objfile;
+  PyObject *result;
+  int line;
+
+  if (!PyArg_ParseTuple (args, "s", &macro_name))
+    return NULL;
+
+  SALPY_REQUIRE_VALID (self, sal);
+
+  ms = sal_macro_scope (*sal);
+  cleanup_chain = make_cleanup (free_current_contents, &ms);
+  if (ms == NULL)
+    goto none_exit;
+
+  mdef = macro_lookup_definition (ms->file, ms->line, macro_name);
+  if (mdef == NULL)
+    goto none_exit;
+
+  file = macro_definition_location(ms->file, ms->line, macro_name, &line);
+  objfile = macro_table_objfile(ms->file->table);
+  result = macropy_object_create (objfile, macro_name, mdef, file, line);
+  do_cleanups (cleanup_chain);
+  return result;
+
+  none_exit:
+    do_cleanups (cleanup_chain);
+    return Py_None;
+}
+
 static void
 salpy_dealloc (PyObject *self)
 {
@@ -477,6 +578,9 @@ Return true if this symbol table is valid, false if not." },
   { "fullname", stpy_fullname, METH_NOARGS,
     "fullname () -> String.\n\
 Return the symtab's full source filename." },
+  { "macros", stpy_macros, METH_NOARGS,
+    "macros () -> List.\n\
+Return a list of macros in the symtab." },
   {NULL}  /* Sentinel */
 };
 
@@ -526,6 +630,14 @@ static PyMethodDef sal_object_methods[] = {
   { "is_valid", salpy_is_valid, METH_NOARGS,
     "is_valid () -> Boolean.\n\
 Return true if this symbol table and line is valid, false if not." },
+  { "macro_named", salpy_macro_named, METH_VARARGS,
+    "macro_named (name) -> Macro.\n\
+Return the macro object for the given name, or None if the \
+macro cannot be found." },
+  { "macros", salpy_macros, METH_NOARGS,
+    "macros () -> List.\n\
+Return all the macros which are available at the symbol table and line \
+object's location." },
   {NULL}  /* Sentinel */
 };
 
-- 
1.7.4.4


  parent reply	other threads:[~2011-08-24 15:11 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-24 15:11 [PATCH 0/7] [python] API for macros matt rice
2011-08-24 15:11 ` [PATCH 5/7] [python] API for macros: gdb.Objfile symtabs method matt rice
2011-08-30 13:08   ` Phil Muldoon
2011-09-01 23:18     ` Matt Rice
2011-09-02  1:07       ` Paul_Koning
2011-08-30 17:34   ` Tom Tromey
2011-09-02  0:56     ` Matt Rice
2011-08-24 15:11 ` [PATCH 2/7] [python] API for macros: memory management quirks matt rice
2011-08-26 20:40   ` Tom Tromey
2011-08-30 11:47   ` Phil Muldoon
2011-09-01 22:46     ` Matt Rice
2011-08-24 15:11 ` [PATCH 1/7] [python] API for macros: abort or continuing macro iterators matt rice
2011-08-26 20:23   ` Tom Tromey
2011-08-30 11:10   ` Phil Muldoon
2011-09-01 21:48     ` Matt Rice
2011-08-24 15:12 ` [PATCH 6/7] [python] API for macros: Add docs matt rice
2011-08-24 20:10   ` Eli Zaretskii
2011-08-25 12:33     ` Matt Rice
2011-08-25 17:36       ` Eli Zaretskii
2011-08-26  8:04         ` Matt Rice
2011-08-26 10:42           ` Eli Zaretskii
2011-08-26 11:17             ` Matt Rice
2011-08-26 12:08               ` Eli Zaretskii
2011-08-26 14:06                 ` Matt Rice
2011-08-26 15:05                   ` Eli Zaretskii
2011-08-24 15:12 ` matt rice [this message]
2011-08-30 13:04   ` [PATCH 4/7] [python] API for macros: Add methods to get a gdb.Macro Phil Muldoon
2011-08-30 17:41     ` Tom Tromey
2011-08-30 20:28       ` Phil Muldoon
2011-08-30 20:35         ` Phil Muldoon
2011-09-01 23:13           ` Matt Rice
2011-09-02  1:15             ` Paul_Koning
2011-09-02 10:04               ` Paul_Koning
2011-09-02 12:04             ` Phil Muldoon
2011-08-30 20:38         ` Tom Tromey
2011-08-30 20:58           ` Phil Muldoon
2011-08-24 15:12 ` [PATCH 3/7] [python] API for macros: Add gdb.Macro class matt rice
2011-08-30 12:45   ` Phil Muldoon
2011-09-01 22:57     ` Matt Rice
2011-08-24 15:12 ` [PATCH 7/7] [python] API for macros: Add tests matt rice
2011-08-30 13:12   ` Phil Muldoon
2011-08-30 15:54   ` Tom Tromey
2011-08-30  9:44 ` [PATCH 0/7] [python] API for macros Phil Muldoon
2011-09-01 21:33   ` Matt Rice

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1314198654-9008-5-git-send-email-ratmice@gmail.com \
    --to=ratmice@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox