debug-with-emacs.xhtml   [plain text]


<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Debugging Python(Twisted) with Emacs</title>
</head>
<body>
<h1>Debugging Python(Twisted) with Emacs</h1>

<img src="http://yellow5.com/pokey/archive/pokey411_3.gif"/>
<span class="footnote">POKEY THE PENGUIN IS COPYRIGHT &copy; 1998-2002
THE AUTHORS</span>

<ul>
  <li>Open up your project files. sometimes emacs can't find them if you
   don't have them open before-hand.</li>

  <li> <code>M-x pdb</code>, Run pdb as: <code>twistd -b -f my.tap</code></li>

  <li>while pdb waits for your input, go to a place in your code and hit
   <code>C-x SPC</code> to insert a break-point. pdb should say something happy.
   Do this in as many points as you wish.</li>

   <li>Go to your pdb buffer and hit <code>c</code>; this runs as normal until a
   break-point is found.</li>

   <li>once you get to a breakpoint, use <code>s</code> to step, <code>n</code> to run the
   current line without stepping through the functions it calls, <code>w</code>
   to print out the current stack, <code>u</code> and <code>d</code> to go up and down a
   level in the stack, <code>p foo</code> to print result of expression <code>foo</code>.</li>

   <li>recommendations for effective debugging:
   <ul>
     <li>use <code>p self</code> a lot; just knowing the class where the current code
     is isn't enough most of the time.</li>
     <li>use <code>w</code> to get your bearings, it'll re-display the current-line/arrow</li>
     <li>after you use <code>w</code>, use <code>u</code> and <code>d</code> and lots more <code>p self</code> on the
     different stack-levels.</li>
     <li>If you've got a big code-path that you need to grok, keep another
      buffer open and list the code-path there (e.g., I had a
      nasty-evil Deferred recursion, and this helped me tons)</li>
    </ul>
  </li>
</ul>


</body>
</html>