Skip to content

Commit

Permalink
Fix #146: Custom launcher port for adapter
Browse files Browse the repository at this point in the history
Add "debugLauncherHost" debug configuration property specifying the interface on which the debug adapter is waiting for incoming connections from the launcher.
  • Loading branch information
int19h committed Apr 28, 2020
1 parent 257d00e commit 3f137db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/debugpy/adapter/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 18 additions & 5 deletions src/debugpy/adapter/launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
Expand All @@ -86,16 +94,21 @@ 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(
"{0} couldn't create listener socket for launcher: {1}", session, exc
)

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:
Expand Down

0 comments on commit 3f137db

Please sign in to comment.