Example #1
0
def print_exc(limit=None, file=None):
    if file is None:
        file = sys.stderr
    try:
        etype, value, tb = sys.exc_info()
        tbtools.defaultTB(etype, value, tb, out=file)
    finally:
        etype = value = tb = None
Example #2
0
def main():
    if not sys.argv[1:]:
        print "usage: ipdb.py scriptfile [arg] ..."
        sys.exit(2)

    mainpyfile =  sys.argv[1]     # Get script filename
    if not os.path.exists(mainpyfile):
        print 'Error:', mainpyfile, 'does not exist'
        sys.exit(1)

    del sys.argv[0]         # Hide "pdb.py" from argument list

    # Replace pdb's dir with script's dir in front of module search path.
    sys.path[0] = os.path.dirname(mainpyfile)

    # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
    # modified by the script being debugged. It's a bad idea when it was
    # changed by the user from the command line. The best approach would be to
    # have a "restart" command which would allow explicit specification of
    # command line arguments.
    pdb = tbtools.defaultPDB
    while 1:
        try:
            pdb._runscript(mainpyfile)
            if pdb._user_requested_quit:
                break
            print "The program finished and will be restarted"
        except Restart:
            # Restart is defined by pdb in Python 2.6
            print "Restarting", mainpyfile, "with arguments"
            print "\t" + " ".join(sys.argv[1:])
        except SystemExit:
            # In most cases SystemExit does not warrant a post-mortem session.
            print "The program exited via sys.exit(). Exit status: ",
            tbtools.ultraTB.print_exc()
            # print sys.exc_info()[1]
        except bdb.BdbQuit:
            # requested quit
            break
        except:
            etype, value, tb = sys.exc_info()
            tbtools.defaultTB(etype, value, tb)
            print "Uncaught exception. Entering post mortem debugging"
            print "Running 'cont' or 'step' will restart the program"
            post_mortem(tb)
            print "Post mortem debugger finished. The "+mainpyfile+" will be restarted"