Exemplo n.º 1
0
Arquivo: qdb.py Projeto: llazzaro/gqdb
def set_trace(host='localhost', port=6000, authkey=b'secret password'):
    "Simplified interface to debug running programs"
    global qdb, listener, conn

    #from multiprocessing.connection import Listener
    from json_serializer import JsonListener
    # only create it if not currently instantiated
    if not qdb:
        address = (host, port)     # family is deduced to be 'AF_INET'
        listener = JsonListener(address, authkey=authkey)
        conn = listener.accept()

        # create the backend
        qdb = Qdb(conn)
    # start debugger backend:
    qdb.set_trace()
Exemplo n.º 2
0
Arquivo: qdb.py Projeto: llazzaro/gqdb
def main(host='localhost', port=6000, authkey=b'secret password'):
    "Debug a script and accept a remote frontend"

    if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):
        print("usage: pdb.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)

    #from multiprocessing.connection import Listener
    from json_serializer import JsonListener
    address = (host, port)     # family is deduced to be 'AF_INET'
    listener = JsonListener(address, authkey=authkey)
    print("qdb debugger backend: waiting for connection at", address)
    conn = listener.accept()
    print('qdb debugger backend: connected to', listener.last_accepted)

    # create the backend
    qdb = Qdb(conn, redirect_stdio=True, allow_interruptions=True)
    try:
        print("running", mainpyfile)
        qdb._runscript(mainpyfile)
        print("The program finished")
    except SystemExit:
        # In most cases SystemExit does not warrant a post-mortem session.
        print("The program exited via sys.exit(). Exit status: ")
        print(sys.exc_info()[1])
        raise
    except Exception:
        traceback.print_exc()
        print("Uncaught exception. Entering post mortem debugging")
        info = sys.exc_info()
        qdb.post_mortem(info)
        print("Program terminated!")
    finally:
        conn.close()
        listener.close()
        print("qdb debbuger backend: connection closed")