From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27620 invoked by alias); 23 Jul 2012 19:38:55 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 27589 invoked by uid 9514); 23 Jul 2012 19:38:54 -0000 Date: Mon, 23 Jul 2012 19:38:00 -0000 Message-ID: <20120723193854.27574.qmail@sourceware.org> From: pmuldoon@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-pmuldoon-python-backtrace: Do not use a tuple for args/var, specifiy and object and an interface instead. X-Git-Refname: refs/heads/archer-pmuldoon-python-backtrace X-Git-Reftype: branch X-Git-Oldrev: aea8f4bb1a33cfcddd55a6c8446e3d39e42b46ac X-Git-Newrev: 1380c3b69cef932b6a1bd65987a7578c47e07eb9 X-SW-Source: 2012-q3/txt/msg00015.txt.bz2 List-Id: The branch, archer-pmuldoon-python-backtrace has been updated via 1380c3b69cef932b6a1bd65987a7578c47e07eb9 (commit) from aea8f4bb1a33cfcddd55a6c8446e3d39e42b46ac (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 1380c3b69cef932b6a1bd65987a7578c47e07eb9 Author: Phil Muldoon Date: Mon Jul 23 20:38:23 2012 +0100 Do not use a tuple for args/var, specifiy and object and an interface instead. ----------------------------------------------------------------------- Summary of changes: gdb/python/lib/gdb/BaseFrameWrapper.py | 29 +++++-- gdb/python/py-framefilter.c | 137 ++++++++++++++++---------------- 2 files changed, 89 insertions(+), 77 deletions(-) First 500 lines of diff: diff --git a/gdb/python/lib/gdb/BaseFrameWrapper.py b/gdb/python/lib/gdb/BaseFrameWrapper.py index 242592a..c41e1f0 100644 --- a/gdb/python/lib/gdb/BaseFrameWrapper.py +++ b/gdb/python/lib/gdb/BaseFrameWrapper.py @@ -89,39 +89,52 @@ class BaseFrameWrapper (FrameWrapper): return self.base +class BaseSymValueWrapper (): + + def __init__(self, symbol, value): + self.sym = symbol + self.val = value + + def value (self): + return self.val + + def symbol (self): + return self.sym + class FrameVars (): def __init__(self,frame): self.frame = frame def fetch_frame_locals (self): - frame_vars = [] + lvars = [] block = self.frame.block() for sym in block: if sym.is_argument: continue; - frame_vars.append((sym, self.get_value (sym, block))) - if len(frame_vars) == 0: + lvars.append(BaseSymValueWrapper(sym, self.get_value(sym,block))) + + if len(lvars) == 0: return None - return iter (frame_vars) + return iter (lvars) def fetch_frame_args (self): - frame_args = [] + args = [] block = self.frame.block() for sym in block: if not sym.is_argument: continue; - frame_args.append((sym, self.get_value (sym,block))) + args.append(BaseSymValueWrapper(sym,self.get_value (sym,block))) - if len(frame_args) == 0: + if len(args) == 0: return None - return iter (frame_args) + return iter (args) def get_value (self, sym, block): if len (sym.linkage_name): diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index 330aee7..f6143bf 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -34,63 +34,82 @@ #include "python-internal.h" static int -extract_value (PyObject *tuple, char **name, - struct value **value, - const struct language_defn **language) +extract_sym_and_value (PyObject *obj, char **name, + struct value **value, + const struct language_defn **language) { - PyObject *sym, *pvalue; - - /* Each element in the locals arguments list should be a - tuple containing two elements. The local name, - which can be a string or a gdb.Symbol, and the - value. */ - - /* Name. */ - sym = PyTuple_GetItem (tuple, 0); - if (! sym) - return 0; - - /* Value. */ - pvalue = PyTuple_GetItem (tuple, 1); - if (! pvalue) - return 0; - - /* For arg name, the user can return a symbol or a - string. */ - if (PyString_Check (sym)) + if (PyObject_HasAttrString (obj, "symbol")) { - *name = python_string_to_host_string (sym); - if (! name) + PyObject *result = PyObject_CallMethod (obj, "symbol", NULL); + if (! result) return 0; - *language = current_language; + + /* For 'symbol' callback, the function can return a symbol or a + string. */ + if (PyString_Check (result)) + { + *name = python_string_to_host_string (result); + Py_DECREF (result); + + if (! name) + return 0; + *language = current_language; + } + else + { + struct symbol *symbol = symbol_object_to_symbol (result); + + Py_DECREF (result); + if (! symbol) + { + PyErr_SetString (PyExc_RuntimeError, + _("Unexpected value. Expecting a " \ + "gdb.Symbol or a Python string.")); + return 0; + } + + *name = xstrdup (SYMBOL_PRINT_NAME (symbol)); + + if (language_mode == language_mode_auto) + *language = language_def (SYMBOL_LANGUAGE (symbol)); + else + *language = current_language; + } } else { - struct symbol *symbol = symbol_object_to_symbol (sym); - if (! symbol) + PyErr_SetString (PyExc_RuntimeError, + _("Mandatory function 'symbol' not " \ + "implemented.")); + return 0; + } + + if (PyObject_HasAttrString (obj, "value")) + { + PyObject *result = PyObject_CallMethod (obj, "value", NULL); + + if (! result) { - PyErr_SetString (PyExc_RuntimeError, - _("Unexpected value in tuple. " \ - "Expecting being a gdb.Symbol or a " \ - "Python string.")); + xfree (*name); return 0; } - *name = xstrdup (SYMBOL_PRINT_NAME (symbol)); + *value = convert_value_from_python (result); - if (language_mode == language_mode_auto) - *language = language_def (SYMBOL_LANGUAGE (symbol)); - else - *language = current_language; + Py_DECREF (result); + if (! *value) + { + xfree (*name); + return 0; + } } - - *value = convert_value_from_python (pvalue); - if (! *value) + else { - xfree (*name); + PyErr_SetString (PyExc_RuntimeError, + _("Mandatory function 'value' not " \ + "implemented.")); return 0; } - return 1; } @@ -138,20 +157,10 @@ py_print_locals (PyObject *filter, if (! item) goto locals_error; - if (! PyTuple_Check (item) - && PyTuple_Size (item) != 2) - { - PyErr_SetString (PyExc_RuntimeError, - _("frame_locals iterator must " \ - "return Python tuples.")); - Py_DECREF (item); - Py_DECREF (iterator); - goto locals_error; - } - value_success = extract_value (item, &sym_name, - &val, - &language); + value_success = extract_sym_and_value (item, &sym_name, + &val, + &language); Py_DECREF (item); if (! value_success) @@ -254,20 +263,10 @@ py_print_args (PyObject *filter, int value_success = 0; volatile struct gdb_exception except; - if (! PyTuple_Check (item) - && PyTuple_Size (item) != 2) - { - PyErr_SetString (PyExc_RuntimeError, - _("frame_locals iterator must " \ - "return Python tuples.")); - Py_DECREF (item); - Py_DECREF (iterator); - goto args_error; - } - - value_success = extract_value (item, &sym_name, - &val, - &language); + value_success = extract_sym_and_value (item, + &sym_name, + &val, + &language); Py_DECREF (item); if (! value_success) hooks/post-receive -- Repository for Project Archer.