[an error occurred while processing this directive]
Brown CS // CS190 Home // Assignments // Debugging

Debugging Lab

This assignment is intended to give you a chance to demonstrate that you know how to step through code and verfiy code execution. Use the method described in Chapter 4 from Writing Solid Code.

  1. Download the Minesweeper source and decompress it (tar -xvf pymine.tar).
  2. Re-read Maguire's description of how to step through code.
  3. Set up to record your debugging session, probably using cut-and-paste.
  4. Take a look at the documentation for the pdb Python module. It's very similar to gdb for C and C++ programs, so if you're familiar with that you should feel right at home in pdb.
  5. Step through the method MineField.populate in the debugger (this method is called every time you start a new game, after selecting the field size). Follow the guidelines from Writing Solid Code chapter 4 on how to do this. Check variable values and other state information before and after execution of each line and verify that the line did what it should. Be sure to step through all the lines of code, even if that means fixing some of the errors as you go along. (It is only necessary to step through the populate function and not the subfunctions called by it.)
  6. Add concise comments to your transcript explaining what bugs you found and how you fixed them.
  7. Hand in your debugger transcript.

The rubric for this assignment is available here.

How does this help me with the chosen project framework, TurboGears?

You can use pdb within TurboGears. To do so, open up the start-....py file used to run the project and add the following lines of code right before the last line which starts the server:

import pdb
cherrypy.config.update({'autoreload.on': False})
pdb.set_trace()

This does a couple things. First, it loads pdb. Second, it disables auto-detection of changes to files while the server is running - without this, if you change a file, the server will restart but the debugger won't quite work... Finally the set_trace() gives you an initial pdb prompt from which you can set breakpoints in your code. For example, setting a breakpoint in the TurboGears wiki tutorial code:

[colin@sliver:~/Desktop/wiki20]$ python start-wiki20.py 
> /home/colin/Desktop/wiki20/start-wiki20.py(32)()
-> turbogears.start_server(Root())
(Pdb) b wiki20/controllers.py:25
Breakpoint 1 at /home/colin/Desktop/wiki20/wiki20/controllers.py:25
(Pdb) 

Try it out now if you have time!

[an error occurred while processing this directive]