public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: pmuldoon@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-pmuldoon-python-backtrace: Add frapy_frame_locals, and frapy_frame_arguments helper functions. These functions return lists of symbols that represent locals and arguments for that frame respectivley.  Also, reset FrameIterator on iteration end, and error.
Date: Wed, 04 Apr 2012 15:04:00 -0000	[thread overview]
Message-ID: <20120404150402.23447.qmail@sourceware.org> (raw)

The branch, archer-pmuldoon-python-backtrace has been updated
       via  0846ff85a01a83ec8c1d8089a6f22813298d2db1 (commit)
      from  313ec1898851d0162bb917768a2fa517220649fa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 0846ff85a01a83ec8c1d8089a6f22813298d2db1
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Wed Apr 4 16:01:57 2012 +0100

    Add frapy_frame_locals, and frapy_frame_arguments helper functions.
    These functions return lists of symbols that represent locals and
    arguments for that frame respectivley.  Also, reset FrameIterator on
    iteration end, and error.

-----------------------------------------------------------------------

Summary of changes:
 gdb/python/py-frame.c |  167 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 166 insertions(+), 1 deletions(-)

First 500 lines of diff:
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index f02c9a1..c5ab2fd 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -28,6 +28,7 @@
 #include "python-internal.h"
 #include "symfile.h"
 #include "objfiles.h"
+#include "dictionary.h"
 
 typedef struct frapy_type_object {
   PyObject_HEAD
@@ -528,6 +529,159 @@ gdbpy_newest_frame (PyObject *self, PyObject *args)
   return frame_obj;
 }
 
+
+/* Implementation of gdb.arguments () -> List
+   Returns a list of gdb.Symbols that constitute this frame's
+   arguments.  */
+
+static PyObject *
+frapy_frame_args (PyObject *self, PyObject *args)
+{
+  struct frame_info *fi;
+  struct symbol *func = NULL;
+  volatile struct gdb_exception except;
+  PyObject *list = NULL;
+  int err = 0, size = 0;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      FRAPY_REQUIRE_VALID (self, fi);
+
+      func = find_pc_function (get_frame_address_in_block (fi));
+
+      if (func)
+	{
+	  list = PyList_New (0);
+
+	  if (! list)
+	    err = 1;
+	  else
+	    {
+	      struct dict_iterator iter;
+	      struct block *b = SYMBOL_BLOCK_VALUE (func);
+	      struct symbol *arg_sym;
+
+	      for (arg_sym = dict_iterator_first (BLOCK_DICT (b), &iter);
+		   arg_sym != NULL;
+		   arg_sym = dict_iterator_next (&iter))
+		{
+		  PyObject *arg_obj = NULL;
+
+		  if (!SYMBOL_IS_ARGUMENT (arg_sym))
+		    continue;
+
+		  if (*SYMBOL_LINKAGE_NAME (arg_sym))
+		    {
+		      struct symbol *nsym;
+
+		      nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (arg_sym),
+					    b, VAR_DOMAIN, NULL);
+		      if (SYMBOL_CLASS (nsym) == LOC_REGISTER
+			  && !SYMBOL_IS_ARGUMENT (nsym))
+			{
+			  continue;
+			  /* skip.  */
+			}
+		      else
+			arg_sym = nsym;
+		    }
+
+		  size++;
+		  /* Cannot "return" in a exception handler.  */
+		  arg_obj = symbol_to_symbol_object (arg_sym);
+		  if (! arg_obj)
+		    {
+		      err = 1;
+		      break;
+		    }
+		  if (PyList_Append (list, arg_obj) == -1)
+		    {
+		      err = 1;
+		      break;
+		    }
+		}
+	    }
+	}
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  if (err)
+    {
+      Py_XDECREF (list);
+      return NULL;
+    }
+
+  /* No arguments, return None.  */
+  if (size ==0)
+    {
+      Py_XDECREF (list);
+      Py_RETURN_NONE;
+    }
+
+  return list;
+}
+
+static void
+do_build_locals_list (const char *print_name,
+		      struct symbol *sym,
+		      void *cb_data)
+{
+  PyObject *llist = (PyObject *) cb_data;
+  PyObject *psym = symbol_to_symbol_object (sym);
+
+  if (psym)
+    PyList_Append (llist, psym);
+}
+
+/* Implementation of gdb.locals () -> List
+   Returns a list of gdb.Symbols that constitute this frame's
+   local variables.  */
+
+static PyObject *
+frapy_frame_locals (PyObject *self, PyObject *args)
+{
+  struct frame_info *fi;
+  volatile struct gdb_exception except;
+  PyObject *list = NULL;
+  int err = 0;
+  struct block *b;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      FRAPY_REQUIRE_VALID (self, fi);
+
+      list = PyList_New (0);
+
+      if (! list)
+	err = 1;
+      else
+	{
+	  b = get_frame_block (fi, 0);
+	  iterate_over_block_local_vars (b,
+					 do_build_locals_list,
+					 list);
+	  if (PyErr_Occurred ())
+	    err = 1;
+	}
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  if (err)
+    {
+      Py_XDECREF (list);
+      return NULL;
+    }
+
+  /* No arguments, return None.  */
+  if (PyList_Size (list) <= 0)
+    {
+      Py_XDECREF (list);
+      Py_RETURN_NONE;
+    }
+
+  return list;
+}
+
 /* Implementation of gdb.selected_frame () -> gdb.Frame.
    Returns the selected frame object.  */
 
@@ -603,6 +757,7 @@ frapy_iter (PyObject *self)
 {
   struct frame_info *fi;
   frame_iterator_object *frame_iter_obj;
+
   FRAPY_REQUIRE_VALID (self, fi);
 
   frame_iter_obj = PyObject_New (frame_iterator_object,
@@ -635,7 +790,11 @@ frapy_iternext (PyObject *self)
   /* Iteration stops on error (preserve the exception), or when
      frapy_older returns None.  */
   if (result == NULL)
-    return NULL;
+    {
+      /* Reset the iterator.  */
+      iter_obj->current = NULL;
+      return NULL;
+    }
 
   iter_obj->current = (frame_object *)result;
   if (result == Py_None)
@@ -749,6 +908,12 @@ Return the frame's code block." },
   { "function", frapy_function, METH_NOARGS,
     "function () -> gdb.Symbol.\n\
 Returns the symbol for the function corresponding to this frame." },
+  { "arguments", frapy_frame_args, METH_NOARGS,
+    "arguments () -> List.\n\
+Returns a List containing symbols of all frame arguments, or None." },
+  { "locals", frapy_frame_locals, METH_NOARGS,
+    "locals () -> List.\n\
+Returns a List containing symbols of all frame locals, or None." },
   { "older", frapy_older, METH_NOARGS,
     "older () -> gdb.Frame.\n\
 Return the frame that called this frame." },


hooks/post-receive
--
Repository for Project Archer.


                 reply	other threads:[~2012-04-04 15:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20120404150402.23447.qmail@sourceware.org \
    --to=pmuldoon@sourceware.org \
    --cc=archer-commits@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).