[Zope] - debugging notes (zope/python/emacs/windows)

Simon Michael simon@joyful.com
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