Beispiel #1
0
# 'ATCH'
#   Attach debugger to the process. If successful, the server responds with 'ACPT', followed by process ID
#   (int64), and then the Python language version that the server is running represented by three int64s -
#   major, minor, micro; From there on the socket is assumed to be using the normal PTVS debugging protocol.
#   If attaching was not successful (which can happen if some other debugger is already attached), the server
#   responds with 'RJCT' and closes the connection. 
#
# 'REPL'
#   Attach REPL to the process. If successful, the server responds with 'ACPT', and from there on the socket
#   is assumed to be using the normal PTVS REPL protocol. If not successful (which can happen if there is
#   no debugger attached), the server responds with 'RJCT' and closes the connection. 

PTVS_VER = '2.1'
DEFAULT_PORT = 5678
PTVSDBG_VER = 3 # must be kept in sync with DebuggerProtocolVersion in PythonRemoteProcess.cs
PTVSDBG = to_bytes('PTVSDBG')
ACPT = to_bytes('ACPT')
RJCT = to_bytes('RJCT')
INFO = to_bytes('INFO')
ATCH = to_bytes('ATCH')
REPL = to_bytes('REPL')

_attach_enabled = False
_attached = threading.Event()
vspd.DONT_DEBUG.append(__file__)


class AttachAlreadyEnabledError(Exception):
    """`ptvsd.enable_attach` has already been called in this process."""

    import thread
except ImportError:
    import _thread as thread
try:
    import ssl
except ImportError:
    ssl = None

import ptvsd.visualstudio_py_debugger as vspd
import ptvsd.visualstudio_py_repl as vspr
from ptvsd.visualstudio_py_util import to_bytes, read_bytes, read_int, read_string, write_bytes, write_int, write_string

PTVS_VER = '2.2'
DEFAULT_PORT = 5678
PTVSDBG_VER = 6
PTVSDBG = to_bytes('PTVSDBG')
ACPT = to_bytes('ACPT')
RJCT = to_bytes('RJCT')
INFO = to_bytes('INFO')
ATCH = to_bytes('ATCH')
REPL = to_bytes('REPL')

PY_ROOT = os.path.normcase(__file__)
while os.path.basename(PY_ROOT) != 'pythonFiles':
    PY_ROOT = os.path.dirname(PY_ROOT)

_attach_enabled = False
_attached = threading.Event()


class AttachAlreadyEnabledError(Exception):
import sys
import os.path
import traceback
import time
import socket
try:
    import ptvsd.visualstudio_py_util as _vspu
except:
    traceback.print_exc()
    print(
        """Internal error detected. Please copy the above traceback and report at
https://github.com/Microsoft/vscode-python/issues""")
    sys.exit(1)

LAST = _vspu.to_bytes('LAST')
OUTP = _vspu.to_bytes('OUTP')
LOAD = _vspu.to_bytes('LOAD')


def parse_argv():
    """Parses arguments for use with the launcher.
    Arguments are:
    1. Working directory.
    2. VS debugger port to connect to.
    3. GUID for the debug session.
    4. Debug options (not used).
    5. '-m' or '-c' to override the default run-as mode. [optional].
    6. Startup script name.
    7. Script arguments.
    """