cython-devel
changeset 1600:e279baa0c002
dump complete syntax tree path on compiler crashes, including nodes traversed in recursive calls that are not controlled by a transform
| author | Stefan Behnel <scoder@users.berlios.de> |
|---|---|
| date | Sat Jan 10 16:50:43 2009 +0100 (3 years ago) |
| parents | 3bf246dd7f44 |
| children | 55ccb1795a87 |
| files | Cython/Compiler/Visitor.py |
line diff
1.1 --- a/Cython/Compiler/Visitor.py Sat Jan 10 15:45:08 2009 +0100
1.2 +++ b/Cython/Compiler/Visitor.py Sat Jan 10 16:50:43 2009 +0100
1.3 @@ -93,7 +93,8 @@
1.4 self.access_path = []
1.5
1.6 def dump_node(self, node, indent=0):
1.7 - ignored = list(node.child_attrs) + [u'child_attrs', u'pos']
1.8 + ignored = list(node.child_attrs) + [u'child_attrs', u'pos',
1.9 + u'gil_message', u'subexprs']
1.10 values = []
1.11 pos = node.pos
1.12 if pos:
1.13 @@ -109,7 +110,10 @@
1.14 continue
1.15 if attr.startswith(u'_') or attr.endswith(u'_'):
1.16 continue
1.17 - value = getattr(node, attr, None)
1.18 + try:
1.19 + value = getattr(node, attr)
1.20 + except AttributeError:
1.21 + continue
1.22 if value is None:
1.23 continue
1.24 elif isinstance(value, list):
1.25 @@ -122,6 +126,23 @@
1.26 return u'%s(%s)' % (node.__class__.__name__,
1.27 u',\n '.join(values))
1.28
1.29 + def _find_node_path(self, stacktrace):
1.30 + import os.path
1.31 + last_traceback = stacktrace
1.32 + nodes = []
1.33 + while hasattr(stacktrace, 'tb_frame'):
1.34 + frame = stacktrace.tb_frame
1.35 + node = frame.f_locals.get(u'self')
1.36 + if isinstance(node, Nodes.Node):
1.37 + code = frame.f_code
1.38 + method_name = code.co_name
1.39 + pos = (os.path.basename(code.co_filename),
1.40 + code.co_firstlineno)
1.41 + nodes.append((node, method_name, pos))
1.42 + last_traceback = stacktrace
1.43 + stacktrace = stacktrace.tb_next
1.44 + return (last_traceback, nodes)
1.45 +
1.46 def visitchild(self, child, parent, attrname, idx):
1.47 self.access_path.append((parent, attrname, idx))
1.48 try:
1.49 @@ -141,9 +162,15 @@
1.50 trace.append(u'%s.%s%s = %s' % (
1.51 parent.__class__.__name__, attribute, index,
1.52 self.dump_node(node)))
1.53 + stacktrace, called_nodes = self._find_node_path(sys.exc_info()[2])
1.54 + last_node = child
1.55 + for node, method_name, pos in called_nodes:
1.56 + last_node = node
1.57 + trace.append(u"File '%s', line %d, in %s: %s" % (
1.58 + pos[0], pos[1], method_name, self.dump_node(node)))
1.59 raise Errors.CompilerCrash(
1.60 - node.pos, self.__class__.__name__,
1.61 - u'\n'.join(trace), e, sys.exc_info()[2])
1.62 + last_node.pos, self.__class__.__name__,
1.63 + u'\n'.join(trace), e, stacktrace)
1.64 self.access_path.pop()
1.65 return result
1.66
