public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-pmuldoon-python-backtrace: Make frame filters iterative. Add FrameWrapper. Remove bogus elide code.
@ 2012-04-05 18:40 pmuldoon
0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2012-04-05 18:40 UTC (permalink / raw)
To: archer-commits
The branch, archer-pmuldoon-python-backtrace has been updated
via 7c3454ab0110e70d0039241c17c819afb6b45f64 (commit)
from deb8867f8cbe4a5ffa97e1b9ec9aa0a104f59775 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 7c3454ab0110e70d0039241c17c819afb6b45f64
Author: Phil Muldoon <pmuldoon@redhat.com>
Date: Thu Apr 5 19:39:24 2012 +0100
Make frame filters iterative. Add FrameWrapper. Remove bogus elide
code.
-----------------------------------------------------------------------
Summary of changes:
gdb/data-directory/Makefile.in | 1 +
gdb/frame.c | 23 --
gdb/frame.h | 6 -
.../lib/gdb/FrameWrapper.py} | 44 +---
gdb/python/py-framefilter.c | 246 ++++++++++----------
gdb/python/python.h | 3 +-
gdb/stack.c | 73 +++----
gdb/testsuite/gdb.python/py-framefilter.exp | 4 +-
gdb/testsuite/gdb.python/py-framefilter.py | 89 ++------
9 files changed, 191 insertions(+), 298 deletions(-)
copy gdb/{testsuite/gdb.python/py-framefilter.py => python/lib/gdb/FrameWrapper.py} (67%)
First 500 lines of diff:
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 757a52c..77338e1 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -56,6 +56,7 @@ PYTHON_FILES = \
gdb/types.py \
gdb/printing.py \
gdb/prompt.py \
+ gdb/FrameWrapper.py \
gdb/command/__init__.py \
gdb/command/pretty_printers.py \
gdb/command/prompt.py \
diff --git a/gdb/frame.c b/gdb/frame.c
index 3e0cb40..e012f2d 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -127,11 +127,6 @@ struct frame_info
/* The reason why we could not set PREV, or UNWIND_NO_REASON if we
could. Only valid when PREV_P is set. */
enum unwind_stop_reason stop_reason;
-
- /* In Python frame-filtering, we can "elide" frames. Store state
- (during printing and processing) if this frame has been elided by
- another. */
- int elide;
};
/* A frame stash used to speed up frame lookups. */
@@ -2222,24 +2217,6 @@ frame_relative_level (struct frame_info *fi)
return fi->level;
}
-int
-frame_print_elide (struct frame_info *fi)
-{
- if (fi == NULL)
- return -1;
- else
- return fi->elide;
-}
-
-void
-set_frame_print_elide (struct frame_info *fi)
-{
- if (fi == NULL)
- return;
- else
- fi->elide = 1;
-}
-
enum frame_type
get_frame_type (struct frame_info *frame)
{
diff --git a/gdb/frame.h b/gdb/frame.h
index c027c81..7b42b56 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -428,12 +428,6 @@ extern CORE_ADDR get_frame_args_address (struct frame_info *);
for an invalid frame). */
extern int frame_relative_level (struct frame_info *fi);
-/* Whether this frame has been marked as elided for printing
- purposes. */
-extern int frame_print_elide (struct frame_info *fi);
-
-extern void set_frame_print_elide (struct frame_info *fi);
-
/* Return the frame's type. */
extern enum frame_type get_frame_type (struct frame_info *);
diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/python/lib/gdb/FrameWrapper.py
similarity index 67%
copy from gdb/testsuite/gdb.python/py-framefilter.py
copy to gdb/python/lib/gdb/FrameWrapper.py
index c1bf717..11f69ed 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.py
+++ b/gdb/python/lib/gdb/FrameWrapper.py
@@ -13,49 +13,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# This file is part of the GDB testsuite. It tests Python-based
-# frame-filters.
+import gdb
-class TestFilter:
- "Testcase filter"
+class FrameWrapper:
+ "Base Frame Wrapper"
- def __init__ (self, frame, what, level, args):
+ def __init__ (self, frame):
self.frame = frame
- self.what = what
- self.lvl = level
- self.args = args
def __new__ (self):
- fname = str (self.frame.function())
- if fname == "main":
- return None
- else:
- return self
+ return self
def omit (self):
- fname = str (self.frame.function())
- if fname == "func2":
- return True
- else:
- return False
+ return False
def elide (self):
- fname = str (self.frame.function())
- frame = self.frame
-
- if fname == "func3":
- frame = frame.older()
- frame = frame.older()
- frame = frame.older()
-
- return frame
+ return False
def function (self):
fname = str (self.frame.function())
- if fname == "func3":
- return "Composite frame " + str(self.frame.function())
+ if (fname == ""):
+ return "<unknown function>"
else:
- return str (self.frame.function())
+ return fname
def level (self, level):
return level
@@ -68,7 +48,7 @@ class TestFilter:
if (sal):
return sal.symtab.filename
else:
- return "unknown"
+ return "<unknown filename>"
def frame_args (self):
args = self.frame.arguments()
@@ -97,3 +77,5 @@ class TestFilter:
else:
return "<unknown line>"
+ def inferior_frame (self):
+ return self.frame
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 36dc7f1..c1d44e4 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -40,14 +40,15 @@
static PyObject *
search_frame_filter_list (PyObject *list, PyObject *frame,
- PyObject *level, PyObject *what,
- PyObject *args)
+ int limit)
{
Py_ssize_t list_size, list_index;
PyObject *function;
PyObject *filter = NULL;
-
+ PyObject *slimit;
+ PyObject *arg;
+
list_size = PyList_Size (list);
for (list_index = 0; list_index < list_size; list_index++)
{
@@ -73,8 +74,8 @@ search_frame_filter_list (PyObject *list, PyObject *frame,
continue;
}
- filter = PyObject_CallFunctionObjArgs (function, frame, level,
- what, args, NULL);
+ slimit = PyLong_FromLong (limit);
+ filter = PyObject_CallFunctionObjArgs (function, frame, slimit, NULL);
if (! filter)
return NULL;
@@ -95,8 +96,7 @@ search_frame_filter_list (PyObject *list, PyObject *frame,
frame filter function, suitably inc-ref'd. */
static PyObject *
-find_frame_filter_from_gdb (PyObject *frame, PyObject *level,
- PyObject *what, PyObject *args)
+find_frame_filter_from_gdb (PyObject *frame, int limit)
{
PyObject *filter_list;
PyObject *function;
@@ -112,8 +112,7 @@ find_frame_filter_from_gdb (PyObject *frame, PyObject *level,
Py_RETURN_NONE;
}
- function = search_frame_filter_list (filter_list, frame, level,
- what, args);
+ function = search_frame_filter_list (filter_list, frame, limit);
Py_XDECREF (filter_list);
return function;
}
@@ -124,8 +123,7 @@ find_frame_filter_from_gdb (PyObject *frame, PyObject *level,
pretty-printer function. */
static PyObject *
-find_frame_filter_from_objfiles (PyObject *frame, PyObject *level,
- PyObject *what, PyObject *args)
+find_frame_filter_from_objfiles (PyObject *frame, int limit)
{
PyObject *filter_list;
PyObject *function;
@@ -143,8 +141,7 @@ find_frame_filter_from_objfiles (PyObject *frame, PyObject *level,
filter_list = objfpy_get_frame_filters (objf, NULL);
- function = search_frame_filter_list (filter_list, frame, level,
- what, args);
+ function = search_frame_filter_list (filter_list, frame, limit);
Py_XDECREF (filter_list);
@@ -168,8 +165,7 @@ find_frame_filter_from_objfiles (PyObject *frame, PyObject *level,
is the pretty-printer function. */
static PyObject *
-find_frame_filter_from_progspace (PyObject *frame, PyObject *level,
- PyObject *what, PyObject *args)
+find_frame_filter_from_progspace (PyObject *frame, int limit)
{
PyObject *filter_list;
PyObject *function;
@@ -179,8 +175,8 @@ find_frame_filter_from_progspace (PyObject *frame, PyObject *level,
return NULL;
filter_list = pspy_get_frame_filters (obj, NULL);
- function = search_frame_filter_list (filter_list, frame, level,
- what, args);
+ function = search_frame_filter_list (filter_list, frame, limit);
+
Py_XDECREF (filter_list);
return function;
}
@@ -191,61 +187,29 @@ find_frame_filter_from_progspace (PyObject *frame, PyObject *level,
reference. On error, set the Python error and return NULL. */
static PyObject *
-find_frame_filter (PyObject *frame, int print_level,
- enum print_what print_what, int print_args)
-
+find_frame_filter (PyObject *frame, int limit)
{
PyObject *function = NULL;
- PyObject *py_print_level = NULL;
- PyObject *py_print_args = NULL;
- PyObject *py_print_what = NULL;
-
- /* Convert the parameters to Python objects. If any of them fail,
- abort. */
- py_print_level = PyBool_FromLong (print_level);
- if (!py_print_level)
- goto exit_func;
-
- py_print_args = PyBool_FromLong (print_args);
- if (!py_print_args)
- goto exit_func;
-
- py_print_what = PyLong_FromLong (print_what);
- if (!py_print_what)
- goto exit_func;
/* Look at the frame filter list for each objfile
in the current program-space. */
- function = find_frame_filter_from_objfiles (frame,
- py_print_level,
- py_print_what,
- py_print_args);
+ function = find_frame_filter_from_objfiles (frame, limit);
if (function == NULL || function != Py_None)
goto exit_func;
Py_DECREF (function);
/* Look at the frame filter list for the current program-space. */
- function = find_frame_filter_from_progspace (frame,
- py_print_level,
- py_print_what,
- py_print_args);
+ function = find_frame_filter_from_progspace (frame, limit);
if (function == NULL || function != Py_None)
goto exit_func;
Py_DECREF (function);
/* Look at the frame filter list in the gdb module. */
- function = find_frame_filter_from_gdb (frame,
- py_print_level,
- py_print_what,
- py_print_args);
- exit_func:
-
- Py_XDECREF (py_print_level);
- Py_XDECREF (py_print_what);
- Py_XDECREF (py_print_args);
+ function = find_frame_filter_from_gdb (frame, limit) ;
+exit_func:
return function;
}
@@ -384,7 +348,7 @@ py_print_args (PyObject *filter,
{
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
PyObject *result = NULL;
- struct ui_stream *stb = NULL;
+ struct ui_file *stb;
/* Frame arguments. */
annotate_frame_args ();
@@ -403,8 +367,8 @@ py_print_args (PyObject *filter,
Py_ssize_t size, list_index;
make_cleanup_py_decref (result);
- stb = ui_out_stream_new (out);
- make_cleanup_ui_out_stream_delete (stb);
+ stb = mem_fileopen ();
+ make_cleanup_ui_file_delete (stb);
if (! PyList_Check (result))
{
@@ -491,7 +455,7 @@ py_print_args (PyObject *filter,
TRY_CATCH (except, RETURN_MASK_ALL)
{
- common_val_print (val, stb->stream, 2, &opts, language);
+ common_val_print (val, stb, 2, &opts, language);
}
if (except.reason > 0)
{
@@ -523,23 +487,44 @@ py_print_args (PyObject *filter,
static int
py_print_frame (PyObject *filter,
- int print_level,
- enum print_what print_what,
- int print_args,
- const char *print_args_type,
- struct ui_out *out,
- struct value_print_options opts,
- struct frame_info *frame)
-
+ int print_level,
+ enum print_what print_what,
+ int print_args,
+ const char *print_args_type,
+ struct ui_out *out,
+ struct value_print_options opts)
{
int level = 0;
CORE_ADDR address = 0;
- struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct gdbarch *gdbarch = NULL;
char *func = NULL;
char *filename = NULL;
int line = 0;
+ struct frame_info *frame = NULL;
volatile struct gdb_exception except;
+ /* Get the frame. */
+ if (PyObject_HasAttrString (filter, "inferior_frame"))
+ {
+ PyObject *result = PyObject_CallMethod (filter, "inferior_frame", NULL);
+
+ if (! result)
+ goto error;
+ frame = frame_object_to_frame_info (result);
+ if (! frame)
+ {
+ Py_DECREF (result);
+ goto error;
+ }
+ gdbarch = get_frame_arch (frame);
+ }
+ else
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ _("frame filter must implement inferior_frame callback."));
+ goto error;
+ }
+
/* First check to see if this frame is to be omitted. */
if (PyObject_HasAttrString (filter, "omit"))
{
@@ -570,6 +555,35 @@ py_print_frame (PyObject *filter,
goto error;
}
+ if (PyObject_HasAttrString (filter, "elide"))
+ {
+ PyObject *result = PyObject_CallMethod (filter, "elide", NULL);
+
+ if (result)
+ {
+ int elide = 0;
+
+ if (! PyBool_Check (result))
+ {
+ Py_DECREF (result);
+ PyErr_SetString (PyExc_RuntimeError,
+ _("'elide' must return type boolean."));
+ goto error;
+ }
+
+ elide = PyObject_IsTrue (result);
+
+ Py_DECREF (result);
+
+ if (elide == -1)
+ goto error;
+ else if (elide)
+ ui_out_spaces (out, 4);
+ }
+ else
+ goto error;
+ }
+
/* Print frame level. */
if (print_level)
{
@@ -709,47 +723,6 @@ py_print_frame (PyObject *filter,
ui_out_text (out, "\n");
annotate_frame_end ();
- if (PyObject_HasAttrString (filter, "elide"))
- {
- PyObject *result = PyObject_CallMethod (filter, "elide", NULL);
-
- if (result)
- {
- struct frame_info *restart = NULL;
- struct frame_info *current = NULL;
- /* Fix result here. */
- TRY_CATCH (except, RETURN_MASK_ALL)
- {
- restart = frame_object_to_frame_info (result);
- }
- if (except.reason > 0)
- {
- Py_DECREF (result);
- PyErr_SetString (PyExc_RuntimeError,
- except.message);
- goto error;
- }
- if (! restart)
- {
- Py_DECREF (result);
- PyErr_SetString (PyExc_RuntimeError,
- _("Cannot locate frame to continue backtrace."));
- goto error;
- }
- if (restart != frame)
- {
- current=get_prev_frame (frame);
- while (current!=restart)
- {
- set_frame_print_elide (current);
- current = get_prev_frame (current);
- }
- }
- }
- else
- goto error;
- }
-
xfree (func);
xfree (filename);
return 1;
@@ -763,13 +736,12 @@ py_print_frame (PyObject *filter,
int
apply_frame_filter (struct frame_info *frame, int print_level,
enum print_what print_what, int print_args,
- const char *print_args_type,
- struct ui_out *out, int print_frame,
- int print_locals)
+ const char *print_args_type, struct ui_out *out,
+ int print_locals, int count)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
struct cleanup *cleanups;
- PyObject *frame_obj, *filter;
+ PyObject *frame_obj, *filter, *frame_iter, *iterable;
int result = 0;
int print_result = 0;
struct value_print_options opts;
@@ -782,7 +754,7 @@ apply_frame_filter (struct frame_info *frame, int print_level,
goto done;
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-04-05 18:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-05 18:40 [SCM] archer-pmuldoon-python-backtrace: Make frame filters iterative. Add FrameWrapper. Remove bogus elide code pmuldoon
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).