Minimal debug/rep functionality

Mark Hobbes2176 at yahoo.com
Thu Sep 19 00:16:33 EDT 2002


Okay, here's my first stab:

from bdb import *

class Mdb(Bdb):
    def user_call(self, frame, args):
        name = frame.f_code.co_name
        if not name: name = '???'
    def user_line(self, frame):
        import linecache
        name = frame.f_code.co_name
        if not name: name = '???'
        fn = self.canonic(frame.f_code.co_filename)
        line = linecache.getline(fn, frame.f_lineno)
        print '+++', frame.f_lineno, name, ':', line.strip()
    def user_return(self, frame, retval):
        None
    def user_exception(self, frame, exc_stuff):
        self.set_continue()

This is copied out of bdb.py and modified from the Tdb class.

To use it, you simply:

import mdb # contains definition of Mdb
import foo # contains function to trace
m = mdb.Mdb()
m.run('foo.main()') # main() is the method I'd like to trace

and out pops a list like (things are a hair cleaner if the input is done 
from a file instead of interactively):

+++ <line number> <code on that line>

My next wish is to NOT have it step into functions .... this isn't a real 
biggie but it would help eliminate some (soon to be) volumious output.

Regards,
Mark



More information about the Python-list mailing list