Minimal debug/rep functionality

Mark Hobbes2176 at
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):
    def user_exception(self, frame, exc_stuff):

This is copied out of 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()'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.


More information about the Python-list mailing list