예제 #1
0
def attach_by_pid(session, target, cwd=None, wait=True):
    if platform.system() != "Windows":
        pytest.skip("https://github.com/microsoft/ptvsd/issues/1810")
    if sys.version_info < (3, ):
        pytest.skip("https://github.com/microsoft/ptvsd/issues/1811")

    log.info("Attaching {0} to {1} by PID.", session, target)

    config = session.config
    try:
        config["processId"] = int(target)
    except TypeError:
        pass

    if "processId" not in config:
        _attach_common_config(session, target, cwd)
        args = target.cli(session.spawn_debuggee.env)

        if wait:
            debug_me = """
import sys
while not "ptvsd" in sys.modules: pass
import ptvsd
while not ptvsd.is_attached(): pass
    """
        else:
            debug_me = None

        session.spawn_debuggee(args, cwd=cwd, debug_me=debug_me)
        config["processId"] = session.debuggee.pid

    session.spawn_adapter()
    return session.request_attach()
예제 #2
0
def launch(session, target, console=None, cwd=None):
    assert console in (None, "internalConsole", "integratedTerminal",
                       "externalTerminal")

    log.info("Launching {0} in {1} using {2!j}.", target, session, console)

    target.configure(session)
    config = session.config
    config.setdefaults({
        "console": "externalTerminal",
        "internalConsoleOptions": "neverOpen"
    })
    if console is not None:
        config["console"] = console
    if cwd is not None:
        config["cwd"] = cwd
    if "python" not in config and "pythonPath" not in config:
        config["python"] = sys.executable

    env = (session.spawn_adapter.env
           if config["console"] == "internalConsole" else config.env)
    target.cli(env)

    session.spawn_adapter()
    return session.request_launch()
예제 #3
0
def attach_listen(session, target, method, cwd=None, log_dir=None):
    log.info("Attaching {0} to {1} by socket using {2}.", session, target,
             method.upper())

    assert method in ("api", "cli")

    config = _attach_common_config(session, target, cwd)
    config["listen"] = {}
    config["listen"]["host"] = host = attach_listen.host
    config["listen"]["port"] = port = attach_listen.port

    if method == "cli":
        args = [
            os.path.dirname(debugpy.__file__),
            "--connect",
            compat.filename_str(host) + ":" + str(port),
        ]
        if log_dir is not None:
            args += ["--log-to", log_dir]
        if "subProcess" in config:
            args += ["--configure-subProcess", str(config["subProcess"])]
        debuggee_setup = None
    elif method == "api":
        args = []
        api_config = {k: v for k, v in config.items() if k in {"subProcess"}}
        debuggee_setup = """
import debugpy
if {log_dir!r}:
    debugpy.log_to({log_dir!r})
debugpy.configure({api_config!r})
debugpy.connect({address!r})
"""
        debuggee_setup = fmt(debuggee_setup,
                             address=(host, port),
                             log_dir=log_dir,
                             api_config=api_config)
    else:
        raise ValueError
    args += target.cli(session.spawn_debuggee.env)

    try:
        del config["subProcess"]
    except KeyError:
        pass

    def spawn_debuggee(occ):
        assert occ.body == some.dict.containing({"host": host, "port": port})
        session.spawn_debuggee(args, cwd=cwd, setup=debuggee_setup)

    session.timeline.when(timeline.Event("debugpyWaitingForServer"),
                          spawn_debuggee)
    session.spawn_adapter(
        args=[] if log_dir is None else ["--log-dir", log_dir])
    return session.request_attach()
예제 #4
0
파일: runners.py 프로젝트: yazici/ptvsd
def attach_by_pid(session, target, cwd=None, wait=True):
    if sys.version_info < (3,) and sys.platform == "win32":
        pytest.skip("https://github.com/microsoft/ptvsd/issues/1811")
    if sys.version_info < (3,) and sys.platform == "darwin":
        pytest.skip("https://github.com/microsoft/ptvsd/issues/1916")
    if wait and not sys.platform.startswith("linux"):
        pytest.skip("https://github.com/microsoft/ptvsd/issues/1926")

    log.info("Attaching {0} to {1} by PID.", session, target)

    config = session.config
    try:
        config["processId"] = int(target)
    except TypeError:
        pass

    if "processId" not in config:
        _attach_common_config(session, target, cwd)
        args = target.cli(session.spawn_debuggee.env)

        if wait:
            debug_me = """
import sys
import threading
import time

while "ptvsd" not in sys.modules:
    time.sleep(0.1)

from debug_me import scratchpad

while "_attach_by_pid" not in scratchpad:
    time.sleep(0.1)
    """
        else:
            debug_me = None

        session.spawn_debuggee(args, cwd=cwd, debug_me=debug_me)
        config["processId"] = session.debuggee.pid

    session.spawn_adapter()
    with session.request_attach():
        yield

    if wait:
        session.scratchpad["_attach_by_pid"] = True