1 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
3 <title>Twisted Documentation: Debugging Python(Twisted) with Emacs</title>
4 <link href="stylesheet.css" rel="stylesheet" type="text/css"/>
8 <h1 class="title">Debugging Python(Twisted) with Emacs</h1>
9 <div class="toc"><ol/></div>
13 <img src="http://yellow5.com/pokey/archive/pokey411_3.gif"/>
14 <a href="#footnote-1" title="POKEY THE PENGUIN IS COPYRIGHT © 1998-2002 THE AUTHORS"><super>1</super></a>
17 <li>Open up your project files. sometimes emacs can't find them if you
18 don't have them open before-hand.</li>
20 <li>Make sure you have a program called <code class="shell">pdb</code> somewhere
21 in your PATH, with the following contents:
23 <pre class="shell" xml:space="preserve">#!/bin/sh
24 exec python2.3 /usr/lib/python2.3/pdb.py $1 $2 $3 $4 $5 $6 $7 $8 $9
27 <li>Run <code class="shell">M-x pdb</code> in emacs. If you usually run your
28 program as <code class="shell">python foo.py</code>, your command line should be <code class="shell">pdb
29 foo.py</code>, for <code class="shell">twistd</code> and <code class="shell">trial</code> just
30 add -b to the command line, e.g.: <code class="shell">twistd -b -y my.tac</code></li>
32 <li>While pdb waits for your input, go to a place in your code and hit
33 <code class="shell">C-x SPC</code> to insert a break-point. pdb should say something happy.
34 Do this in as many points as you wish.</li>
36 <li>Go to your pdb buffer and hit <code class="shell">c</code>; this runs as normal until a
37 break-point is found.</li>
39 <li>Once you get to a breakpoint, use <code class="shell">s</code> to step, <code class="shell">n</code> to run the
40 current line without stepping through the functions it calls, <code class="shell">w</code>
41 to print out the current stack, <code class="shell">u</code> and <code class="shell">d</code> to go up and down a
42 level in the stack, <code class="shell">p foo</code> to print result of expression <code class="shell">foo</code>.</li>
44 <li>Recommendations for effective debugging:
46 <li>use <code class="shell">p self</code> a lot; just knowing the class where the current code
47 is isn't enough most of the time.</li>
48 <li>use <code class="shell">w</code> to get your bearings, it'll re-display the current-line/arrow</li>
49 <li>after you use <code class="shell">w</code>, use <code class="shell">u</code> and <code class="shell">d</code> and lots more <code class="shell">p self</code> on the
50 different stack-levels.</li>
51 <li>If you've got a big code-path that you need to grok, keep another
52 buffer open and list the code-path there (e.g., I had a
53 nasty-evil Deferred recursion, and this helped me tons)</li>
59 <h2>Footnotes</h2><ol><li><a name="footnote-1"><span class="footnote">POKEY THE PENGUIN IS COPYRIGHT © 1998-2002
60 THE AUTHORS</span></a></li></ol></div>
62 <p><a href="index.html">Index</a></p>
63 <span class="version">Version: 12.1.0</span>