|
Boa now has a stable out of process debugger that can debug almost any Python application. This includes threads, most popular Python GUI toolkits, Zope Python debugging and even specialised support for debugging Zope Python Scripts.
To debug an application, save any unsaved changes and click the red play
button on the toolbar or choose
File->Debug application. This applies to application modules and any modules
part of an application. To debug an individual module that is part of an
application, choose File->Debug module.
The Debugger window should appear at the same place as the Inspector and
debugging will trace until the very first line of source.
Important: When debugging wxPython applications on wxPython versions
lower than 2.3.3 on windows, there is a bug in wxProcess/wxExecute which prevents
the main frame of the application from being displayed.
To work around this the main frame must be shown, hidden and shown again. e.g.
frame.Show();frame.Hide();frame.Show()
The standard debugging pages:
|
The first step is to start up the process that you want to debug on the remote machine, create a RemoteServer and install the tracer.
There are a few ways to do this.
One way is to create a script called e.g. bcrdb which looks like this:
#!/usr/bin/python
import sys
sys.path.append('/path/to/boa')
from Debugger.RemoteServer import start
start('username', 'password')
del sys.argv[0:1]
execfile(sys.argv[0], {'__name__': '__main__',
'__builtins__': __builtins__})
You can now use this script (bcrdb script) instead of Python (python script) to
debug remote scripts.
You have to add the following snippet to your program to turn on the tracer:
if hasattr(sys, 'debugger_control'):
sys.debugger_control.set_traceable()
Breakpoints encountered in code after the tracer was installed will be caught
by the Debug Server.
If Boa is installed normally on the remote machine, Boa.py -R script can be used instead of bcrdb script. (Boa.py imports almost nothing on this code path so no 'pollution' to worry about)
The second step is to connect to the Remote Debugger from the Boa IDE. From an open python module, select File->Attach to debugger, and fill in the dialog. You should now be attached to the remote debugger.
It is your responsibility to assure that the file paths to the source files are identical on both machines.
Firstly you may debug Zope as a normal Python application.
Open up z2.py in the Editor, set it's command-line parameter to -D
(File->Set command-line parameters). Now debug it like any other module.
Set a hard breakpoint in your Product code to break into your code.
Secondly you may directly debug and step through Zope Python Scripts.
You should have a working Zope Connection defined in the Explorer. Open the
Python Script you want to debug.
Now run Zope as described in the first step. The easiest way to break into a
Python Script (remember that they execute in a different thread than z2.py) is to
install the extremely small Zope Product found in Debugger/ZopeBreakpoint.zip.
All this product does is to allow Scripts to access sys.breakpoint.
Then using the normal sys.breakpoint() call in your Python Script will break
at that line. From now on, normal soft breakpoints will work for the Script.
If you don't want to install the Product you can still step through
Python Scripts by setting a hard break somewhere in the Zope code that runs in
the same thread as the Script. After hitting the hard break, normal breakpoints
in your Script should work.
Because of the new Signals support added to Zope 2.6. under unix platforms z2.py
must be patched on those platforms.
(Because the debugger doesn't run programs in the main thread and Signals require this).
To patch z2.py, from line 526, change:
# install signal handlers if on posix
if os.name == 'posix':
from Signals import Signals
Signals.registerZopeSignals()
to
# install signal handlers if on posix
if os.name == 'posix' and not hasattr(sys, 'boa_debugger'):
from Signals import Signals
Signals.registerZopeSignals()
There is limited support provided for debugging Page Templates too.
You may add soft breakpoints next to <tal:*> tags inside <metal:use-macro*>
sections. The debugger should stop at these breakpoints and you can inspect the
namespace with watches or the Debugger shell. Stepping is not supported.
Another way to debug Zope from Boa is to install the functions in the Debugger/BoaDebugServer.py module as ExternalMethods.
This allows you to start and hook Zope into the Boa Debug Server at runtime without
running z2.py in the debugger from the IDE.
(This also avoids the Signal problems problem on linux and works with an unpatched z2.py)
To install the runtime hooking follow the next steps:
To use the runtime hooking follow these steps:
A new way to manage a DebugServer in Zope it to install the BoaDebugger
product. The product can be downloaded seperately or built with the
Debugger/BoaDebugger/BuildProduct.py script.
|