|
|
/ Hathaway Weblog / How Boa Constructor's ZPT debugger works |
Stephan Richter asked me how Boa Constructor is able to debug Zope page templates. The answer is surprisingly simple, so I thought I'd share my answer with everyone.
The trick is to provide a "view" of the Python stack and make the debugger use that view instead of inspecting the Python stack directly. ZopeScriptDebugServer (in Boa's Debugger package) is a view of the program stack. It implements a notional "program stack" interface. Each time the debugger hits a frame, the debugger asks the debug server whether it should stop at that point. The debug server has a policy that tells the debugger to stop only in a PythonScript or when the TAL interpreter is executing a setPosition byte code.
To gather stack information, the debugger uses the debug server to inspect the stack rather than accessing the stack directly. The debug server digs deep into the Python stack and generates a stack that contains ZPT filenames and line numbers rather than Python code references. This trick seems to be sufficient to turn a Python debugger into a good ZPT debugger.
ZopeScriptDebugServer uses brittle introspection methods, since TALInterpreter provides no explicit debugging hooks, but the concept is sound. It would be cool to integrate the concept of a replaceable stack view into a debugger that's smaller than Boa.
