public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-pmuldoon-python-backtrace: Rough implementation of frame printing args
@ 2012-03-23 14:46 pmuldoon
0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2012-03-23 14:46 UTC (permalink / raw)
To: archer-commits
The branch, archer-pmuldoon-python-backtrace has been updated
via 999c175b15ed114fa5e7ffe0aff7891cd16845af (commit)
from 63da93e5e430b18bda11ca83dabc861ff60a0aef (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 999c175b15ed114fa5e7ffe0aff7891cd16845af
Author: Phil Muldoon <pmuldoon@redhat.com>
Date: Fri Mar 23 14:45:20 2012 +0000
Rough implementation of frame printing args
-----------------------------------------------------------------------
Summary of changes:
gdb/python/py-framefilter.c | 135 ++++++++++++++++++++++++++++
gdb/testsuite/gdb.python/py-framefilter.py | 31 +++++++
2 files changed, 166 insertions(+), 0 deletions(-)
First 500 lines of diff:
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index ea4edfc..b290280 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -262,6 +262,7 @@ print_frame (PyObject *filter,
char *filename = NULL;
int line = 0;
volatile struct gdb_exception except;
+ const struct language_defn *language;
/* First check to see if this frame is to be omitted. */
if (PyObject_HasAttrString (filter, "omit"))
@@ -293,6 +294,7 @@ print_frame (PyObject *filter,
goto error;
}
+ /* Print frame level. */
if (print_level)
{
if (PyObject_HasAttrString (filter, "level"))
@@ -313,6 +315,7 @@ print_frame (PyObject *filter,
level = frame_relative_level (frame);
}
+ /* Print frame address. */
if (PyObject_HasAttrString (filter, "address"))
{
PyObject *result = PyObject_CallMethod (filter, "address", NULL);
@@ -342,6 +345,7 @@ print_frame (PyObject *filter,
}
ui_out_text (out, " in ");
+ /* Print frame function. */
if (PyObject_HasAttrString (filter, "function"))
{
PyObject *result = PyObject_CallMethod (filter, "function", NULL);
@@ -368,6 +372,137 @@ print_frame (PyObject *filter,
annotate_frame_function_name ();
ui_out_field_string (out, "func", func);
+ /* Frame arguments. */
+ annotate_frame_args ();
+ ui_out_text (out, " (");
+ if (print_args)
+ {
+ if (PyObject_HasAttrString (filter, "frame_args"))
+ {
+ PyObject *result = PyObject_CallMethod (filter, "frame_args", NULL);
+ struct ui_stream *stb;
+ struct cleanup *old_chain;
+ const char *sym_name;
+
+ stb = ui_out_stream_new (out);
+ old_chain = make_cleanup_ui_out_stream_delete (stb);
+
+ if (result)
+ {
+ Py_ssize_t size, list_index;
+
+ if (! PyList_Check (result))
+ {
+ Py_DECREF (result);
+ PyErr_SetString (PyExc_RuntimeError,
+ _("frame_args must return a Python list."));
+ do_cleanups (old_chain);
+ goto error;
+ }
+
+ size = PyList_Size (result);
+
+ if (size > 0)
+ {
+ for (list_index = 0; list_index < size; list_index++)
+ {
+ PyObject *sym_tuple, *sym, *value;
+ char *symname;
+ struct value *val;
+ struct symbol *symbol;
+
+ sym_tuple = PyList_GetItem (result, list_index);
+ if (! sym_tuple)
+ {
+ Py_DECREF (result);
+ do_cleanups (old_chain);
+ goto error;
+ }
+
+ if (! PyTuple_Check (sym_tuple)
+ && PyTuple_Size (sym_tuple) != 2)
+ {
+ Py_DECREF (result);
+
+ PyErr_SetString (PyExc_RuntimeError,
+ _("frame_arg list must contain a Python tuple."));
+ do_cleanups (old_chain);
+ goto error;
+ }
+
+ /* Each element in the frame arguments list should be a
+ tuple containing two elements. The argument name,
+ which can be a string or a gdb.Symbol, and the
+ value. */
+
+ /* Name. */
+ sym = PyTuple_GetItem (sym_tuple, 0);
+ if (! sym)
+ {
+ Py_DECREF (result);
+ do_cleanups (old_chain);
+ goto error;
+ }
+
+ /* Value. */
+ value = PyTuple_GetItem (sym_tuple, 1);
+ if (! value)
+ {
+ Py_DECREF (result);
+ do_cleanups (old_chain);
+ goto error;
+ }
+
+ /* For arg name, the user can return a symbol or a
+ string. */
+ if (PyString_Check (sym))
+ {
+ sym_name = PyString_AsString (sym);
+ language = current_language;
+ if (! sym_name)
+ {
+ Py_DECREF (result);
+ do_cleanups (old_chain);
+ goto error;
+ }
+ }
+ else
+ {
+ symbol = symbol_object_to_symbol (sym);
+ sym_name = SYMBOL_PRINT_NAME (symbol);
+ if (language_mode == language_mode_auto)
+ language = language_def (SYMBOL_LANGUAGE (symbol));
+ else
+ language = current_language;
+ }
+
+ annotate_arg_begin ();
+ ui_out_field_string (out, "name", sym_name);
+ ui_out_text (out, "=");
+
+ val = value_object_to_value (value);
+
+ annotate_arg_value (value_type (val));
+
+ opts.deref_ref = 1;
+
+ /* True in "summary" mode, false otherwise. */
+ // opts.summary = !strcmp (print_frame_arguments, "scalars");
+ common_val_print (val, stb->stream, 2, &opts, language);
+ ui_out_field_stream (out, "value", stb);
+ if (size != 1 && list_index < size-1)
+ ui_out_text (out, ", ");
+ annotate_arg_end ();
+ }
+ Py_DECREF (result);
+ }
+ }
+ else
+ goto error;
+ }
+ }
+
+ ui_out_text (out, ")");
if (PyObject_HasAttrString (filter, "filename"))
{
PyObject *result = PyObject_CallMethod (filter, "filename", NULL);
diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py
index a3afe1a..0e9d40e 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.py
+++ b/gdb/testsuite/gdb.python/py-framefilter.py
@@ -63,6 +63,36 @@ class Main_filter:
else:
return "unknown"
+ def frame_args (self):
+ func = self.frame.function()
+ args = []
+ block = self.frame.block()
+
+ if not func:
+ return
+
+ for sym in block:
+ if not sym.is_argument:
+ continue;
+
+ if len (sym.linkage_name):
+ nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
+ if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
+ sym = nsym
+ try:
+ val = sym.value(self.frame)
+ if val != None:
+ val = val
+ else:
+ val="???"
+ except RuntimeError, text:
+ val = text
+
+ atuple = (sym.print_name, val)
+ args.append (atuple)
+
+ return args
+
def line (self):
sal = self.frame.find_sal()
if (sal):
@@ -70,6 +100,7 @@ class Main_filter:
else:
return "<unknown line>"
+
def register_frame_filters (frame, what, level, args):
# if (frame.name() == "main"):
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-03-23 14:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-23 14:46 [SCM] archer-pmuldoon-python-backtrace: Rough implementation of frame printing args 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).