diff options
author | Mark Florisson <markflorisson88@gmail.com> | 2010-12-14 23:51:04 +0100 |
---|---|---|
committer | Mark Florisson <markflorisson88@gmail.com> | 2010-12-14 23:51:04 +0100 |
commit | e325fbee725fa21eb49941ad84ac49bfccf11021 (patch) | |
tree | 02445415aa2797484ec3a09c223ffd6620305a9b /Cython/Debugger/libpython.py | |
parent | da24fe3127464a2a908de2668856475dee8a5985 (diff) | |
download | cython-e325fbee725fa21eb49941ad84ac49bfccf11021.tar.gz |
Detect Python exceptions
Diffstat (limited to 'Cython/Debugger/libpython.py')
-rw-r--r-- | Cython/Debugger/libpython.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/Cython/Debugger/libpython.py b/Cython/Debugger/libpython.py index c83d7ddf3..75c785056 100644 --- a/Cython/Debugger/libpython.py +++ b/Cython/Debugger/libpython.py @@ -369,8 +369,8 @@ class PyObjectPtr(object): if tp_name in name_map: return name_map[tp_name] - if tp_flags & Py_TPFLAGS_HEAPTYPE: - return HeapTypeObjectPtr + if tp_flags & (Py_TPFLAGS_HEAPTYPE|Py_TPFLAGS_TYPE_SUBCLASS): + return PyTypeObjectPtr if tp_flags & Py_TPFLAGS_INT_SUBCLASS: return PyIntObjectPtr @@ -392,8 +392,6 @@ class PyObjectPtr(object): return PyDictObjectPtr if tp_flags & Py_TPFLAGS_BASE_EXC_SUBCLASS: return PyBaseExceptionObjectPtr - #if tp_flags & Py_TPFLAGS_TYPE_SUBCLASS: - # return PyTypeObjectPtr # Use the base class: return cls @@ -484,8 +482,8 @@ def _PyObject_VAR_SIZE(typeobj, nitems): ) & ~(SIZEOF_VOID_P - 1) ).cast(gdb.lookup_type('size_t')) -class HeapTypeObjectPtr(PyObjectPtr): - _typename = 'PyObject' +class PyTypeObjectPtr(PyObjectPtr): + _typename = 'PyTypeObject' def get_attr_dict(self): ''' @@ -545,10 +543,17 @@ class HeapTypeObjectPtr(PyObjectPtr): out.write('<...>') return visited.add(self.as_address()) - - pyop_attrdict = self.get_attr_dict() - _write_instance_repr(out, visited, - self.safe_tp_name(), pyop_attrdict, self.as_address()) + + try: + tp_name = self.field('tp_name').string() + except RuntimeError: + tp_name = 'unknown' + + out.write('<type %s at remote 0x%x>' % (tp_name, + self.as_address())) + # pyop_attrdict = self.get_attr_dict() + # _write_instance_repr(out, visited, + # self.safe_tp_name(), pyop_attrdict, self.as_address()) class ProxyException(Exception): def __init__(self, tp_name, args): @@ -1136,9 +1141,6 @@ class PyTupleObjectPtr(PyObjectPtr): else: out.write(')') -class PyTypeObjectPtr(PyObjectPtr): - _typename = 'PyTypeObject' - def _unichr_is_printable(char): # Logic adapted from Python 3's Tools/unicode/makeunicodedata.py @@ -2171,6 +2173,20 @@ class PythonInfo(LanguageInfo): except IOError, e: return None + def exc_info(self, frame): + try: + tstate = frame.read_var('tstate').dereference() + if gdb.parse_and_eval('tstate->frame == f'): + # tstate local variable initialized + inf_type = tstate['curexc_type'] + inf_value = tstate['curexc_value'] + if inf_type: + return 'An exception was raised: %s(%s)' % (inf_type, + inf_value) + except (ValueError, RuntimeError), e: + # Could not read the variable tstate or it's memory, it's ok + pass + def static_break_functions(self): yield 'PyEval_EvalFrameEx' |