Graphical debugging of Grok with Komodo IDEΒΆ

Author:Sebastian Ware

Set up the Komodo IDE graphical debugger for your Grok project.

  1. Set the PYTHONPATH
  1. either in the terminal before you execute the “/bin/paster serve” command

    http://community.activestate.com/forum-topic/debugging-zope-apps

  2. or (if you start Grok from Komodo) by adding PYTHONPATH with a path to the

    Komodo debugger library. Go to “Preferences / Environment / New...” and

    add Name= PYTHONPATH, Value= /path/to/debugger_library

    The Komodo Python debugger library is called “dbgp”. In Macosx you can find it

    the Komodo IDE.app package under Contents/SharedSupport/. I actually copied it

    to another location but I don’t think that is necessary.

  1. Make sure that the Komodo debugger listens to the right port

Go to “Preferences / Debugger / Connection” and choose “a specific port”. I selected port 9000 (but I think anything above 1024 should be ok in Macosx).

  1. Add the following two lines anywhere in a .py file in your project (outside any class or method definition):
import dbgp.client dbgp.client.brk(host=”localhost”, port=9000)

Note that it supports remote debugging, but that requires you opening the firewall on the computer running the debugger.

  1. Start Grok from within Komodo IDE (I have a python virtualenv installation)

I use the following macro (search for “macro” in Komodo help to learn how to create a macro) and have a keybinding to “shift-command r”:

// Macro recorded on Tue Jun 19 2007 21:08:09 GMT+0200 (CEST)
var appname = 'MyApp';
var sandbox = '/path/to/my/projects';
var pythonCmd = sandbox + '/bin/python';
var startCmd = sandbox + '/' + appname + '/bin/paster serve ' + sandbox + '/' + appname + '/parts/etc/debug.ini';
komodo.assertMacroVersion(3);
ko.run.output.kill(-1);
if (komodo.view) { komodo.view.setFocus() };
setTimeout(function(ko, win) {
    ko.run.runEncodedCommand(win,  pythonCmd + ' ' + startCmd);
}, 200, ko, window);
// Note "200" is the delay before starting the server, allowing the output.kill command to
// execute properly. You might want to extend this on a slower computer.

Grok will pause execution at the “client.brk” command added in step 3. You can add and remove your break points and press the “Go / continue debugging” button in the toolbar. The Komodo debugger supports regular, conditional, variable based, function call, function return and exception base breakpoints. (At the time of writing I have only set regular line based breakpoints.)

Once the Komodo debugger breaks at a break point you can:

step into/over/return from statements inspect local/global/watch variables check the call stack enter interactive mode to perform arbitrary python code (this gives you a Python prompt, not the pdb prompt)