Fix #146: Custom launcher port for adapter

Add "debugLauncherHost" debug configuration property specifying the interface on which the debug adapter is waiting for incoming connections from the launcher.
This commit is contained in:
Pavel Minaev 2020-04-27 15:13:23 -07:00 committed by Pavel Minaev
parent 257d00e9dd
commit 3f137dbf67
2 changed files with 20 additions and 5 deletions

View file

@ -323,12 +323,14 @@ class Client(components.Component):
raise request.cant_handle('"sudo":true is not supported on Windows.')
launcher_path = request("debugLauncherPath", os.path.dirname(launcher.__file__))
launcher_host = request("debugLauncherHost", "127.0.0.1")
servers.serve()
launchers.spawn_debuggee(
self.session,
request,
launcher_path,
launcher_host,
args,
cwd,
console,

View file

@ -9,7 +9,7 @@ import subprocess
import sys
from debugpy import adapter
from debugpy.common import compat, log, messaging, sockets
from debugpy.common import compat, fmt, log, messaging, sockets
from debugpy.adapter import components, servers
@ -66,7 +66,15 @@ class Launcher(components.Component):
def spawn_debuggee(
session, start_request, launcher_path, args, cwd, console, console_title, sudo
session,
start_request,
launcher_path,
launcher_host,
args,
cwd,
console,
console_title,
sudo,
):
# -E tells sudo to propagate environment variables to the target process - this
# is necessary for launcher to get DEBUGPY_LAUNCHER_PORT and DEBUGPY_LOG_DIR.
@ -86,7 +94,7 @@ def spawn_debuggee(
try:
listener = sockets.serve(
"Launcher", on_launcher_connected, "127.0.0.1", backlog=1
"Launcher", on_launcher_connected, launcher_host, backlog=1
)
except Exception as exc:
raise start_request.cant_handle(
@ -94,8 +102,13 @@ def spawn_debuggee(
)
try:
_, launcher_port = listener.getsockname()
cmdline += [str(launcher_port), "--"]
launcher_host, launcher_port = listener.getsockname()
launcher_addr = (
launcher_port
if launcher_host == "127.0.0.1"
else fmt("{0}:{1}", launcher_host, launcher_port)
)
cmdline += [str(launcher_addr), "--"]
cmdline += args
if log.log_dir is not None: