From 3f137dbf673c323a0d70fcf135df3a3397938753 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Mon, 27 Apr 2020 15:13:23 -0700 Subject: [PATCH] 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. --- src/debugpy/adapter/clients.py | 2 ++ src/debugpy/adapter/launchers.py | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/debugpy/adapter/clients.py b/src/debugpy/adapter/clients.py index a69a9161c..53680895c 100644 --- a/src/debugpy/adapter/clients.py +++ b/src/debugpy/adapter/clients.py @@ -323,12 +323,14 @@ def property_or_debug_option(prop_name, flag_name): 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, diff --git a/src/debugpy/adapter/launchers.py b/src/debugpy/adapter/launchers.py index ce502fb85..d0d3e8f4b 100644 --- a/src/debugpy/adapter/launchers.py +++ b/src/debugpy/adapter/launchers.py @@ -9,7 +9,7 @@ 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 @@ def terminate_debuggee(self): 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 on_launcher_connected(sock): 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 on_launcher_connected(sock): ) 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: