Log in |
Server side debugging of Zope[Zope] - debugging notes (zope/python/emacs/windows)Simon Michael [email protected]Tue, 5 Jan 1999 07:59:37 -0800 Here are some rough notes from my recent zope debugging efforts - I hope
that others will find them useful, or post corrections/improvements.
- Environment: I am using NT Emacs and the cygwin bash shell on windows 98.
So my paths generally have forward slashes.
- I wanted to step through the code of an external method which was not
working. So I tried debugging it with ZPublisher/Test.py, described in the
zope docs. The command line I'm using now is:
$Z/bin/python -i $Z/lib/python/ZPublisher/Test.py -d $Z/lib/python/Main
/files/find_results
python with the '-i' flag is required to get the interactive prompt in an
emacs shell window. Also it ensures that I know exactly which version of
python is being used. $Z is the path to my zope installation.
/files/find_results is the url path to a DTML Document which calls my
external method.
- I could not set a breakpoint on my external method, apparently due to
limitations of the standard pdb class. So I tried stepping right through
zope's execution to that point, but it became clear that I needed a
higher-level tool with good source display. So I explored various
incarnations & versions of debugging tools: pdb, pydb, emacs modes, ddd.
Eventually, I:
- downloaded the latest python, 1.5.2b1. The pdb/bdb/cmd classes in this
version incorporate various enhancements, in particular you can set a
breakpoint in any file which is in your sys.path, as follows:
pdb> import sys
pdb> sys.path.append('/tools/zope/Extensions')
pdb> b ExtranetFind.py:19
- running zope with the latest python gave warnings about API versions.
Things were not working well at the time so for paranoia I copied the new
pdb/bdb/cmd classes into zope's lib/python1.5 and used that. Either version
seems to work fine aside from the warnings.
- I downloaded the latest NT Emacs, 20.3.3.1.1. This fixed some problems,
and has an up-to-date gud.el with pdb support.
- I made a change to .../emacs/lisp/gud.el to get "M-x pdb" to work on
windows:
(defvar gud-pdb-marker-regexp
"^>
\\([-a-zA-Z0-9_/.:\\]*\\|<string>\\)(\\([0-9]+\\))\\([a-zA-Z0-9_]*\\|\\?\\)(
)\\(->[^\n]*\\)?\n") ;fix for windows/dos pathnames - SKWM
- I downloaded the latest python-mode.el from www.python.org
- I added this in my ~/.emacs to match Test.py's altered pdb prompt
(cosmetic fix):
(add-hook 'pdb-mode-hook '(lambda () (setq comint-prompt-regexp "^pdb> *")))
; for zope debugging
- These made for a more convenient debug prompt:
(eval-after-load "comint" '(define-key comint-mode-map "\M-p"
'comint-previous-matching-input-from-input))
(eval-after-load "comint" '(define-key comint-mode-map "\M-n"
'comint-next-matching-input-from-input))
(eval-after-load "comint" '(define-key comint-mode-map "\C-a" 'comint-bol))
(setq comint-input-ring-size 100)
- NOW, I can step through zope in emacs with full source fontifying, etc
(get help on the "gud-mode" function for keybindings). Type "M-x pdb", and
at the "Run pdb" prompt enter the Test.py command line above.
- In this situation, you can use "python -u" instead of "python -i" to skip
the python prompt at the end of a run.
-Simon
[Zope] - debugging notes, part 2Simon Michael [email protected]Tue, 5 Jan 1999 07:59:45 -0800
Ok, so now I can debug zope in emacs, and set breakpoints where I want.
Back to the earlier problem! Some breakpoints which I think should get hit,
do not get hit. Eg, a breakpoint on my external method. I don't yet know why
this happens.
*TWO MORE MISC CHANGES:
- So that I could run Test.py with the '-t' flag on windows, I changed
instances of '/dev/null' to '/zopetest.tmp'
- For quicker debugging, I made a change at ExternalMethod/ExternalMethod.py
line 244, to reload external methods every time:
# SKWM - always reload (todo: check debug flag)
# try: f=self._v_f
# except: f=self.getFunction()
f=self.getFunction(1,1)
*SWITCHED TO PDOCUMENTTEMPLATE
- I tried again to step through zope's publishing process and into my
method.. still haven't quite managed it.
- I thought, "well it goes through c code at some point (cDocumentTemplate)
and maybe that's confusing the debugger". Not to mention me. So, in order to
try pDocumentTemplate, I:
- renamed lib/python/DocumentTemplate/cDocumentTemplate.pyd (to hide it);
- changed DT_Util.py:
#SKWM
#except: from pDocumentTemplate import InstanceDict, TemplateDict,
render_blocks
except:
from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
class cDocument: pass
- made a fix, or at least a change, in pDocumentTemplate.py, line 159
(allowed me to manage Documents again) :
#SKWM r=str(inst)
r=str(inst)
- And now, zope appears to run fine using the pDocumentTemplate and I can
step through it as far as I want. As before, some breakpoints which I would
expect to get hit, don't.
- With one exception - running with pDocumentTemplate appears to break
access control. Same with BOBO_DEBUG_MODE=1.
On with the battle! Advice welcome!
-Simon
Hacking on through the zope jungle <chop> <bash> <ouch>
Avoiding a fatal squeeze from certain large snakes <oof>
I wonder if there's an easier trail around here somewhere.
Here are some more brief notes, on the theory that someone may benefit.. or
shoot me before I catch jungle madness..
- PYTHON SETTINGS
I said that "python -u ..." also works when doing "M-x pdb" in emacs. Not
true, stick with "python -i ..." to avoid problems.
Added a whole bunch of zope dirs to the PYTHONPATH environment variable to
allow imports. Works for python 1.5.2b1, but not for zope's python.
- BREAKPOINTS AGAIN
I wrote:
> Ok, so now I can debug zope in emacs, and set breakpoints where I want.
Spoke too soon. pdb's "b filename:lineno" doesn't work. Test.py's fbreak()
function does work. Breakpoints can be configured in a .bobodb file. Eg:
import ExternalMethod
breakpoints = [ExternalMethod.ExternalMethod.__call__,]
Doesn't matter if you use cDocumentTemplate or pDocumentTemplate.
A breakpoint on the external method itself doesn't work. If I step in from
the above, I can then set one that works.
- DEBUGGING IN WEBSERVER MODE
When running in Test.py's command-line mode, the #with statement which calls
my method is initialized but never rendered (why ?). It works fine in normal
webserver mode. I changed Test.py to fire up the whole zopeHTTPserver:
# db.run('publish_module(file,environ=env,debug=1)',Publish.__dict__,
{'file':file, 'env':env})
sys.argv = []
db.run('import serve',Publish.__dict__,{'file':file, 'env':env})
Run Test.py in debug mode with "M-x pdb", as before. It reads breakpoints
from .bobodb (I hardcoded the path to make sure). Continue a few times and
the webserver's running. Access the url with a browser to trigger the
ExternalMethod breakpoint, step into your method and there you are (my holy
grail).
-Simon
|