From fb3a926b7fb85c535b03534a0d6ba99a15a65322 Mon Sep 17 00:00:00 2001 From: Pranay Agarwal Date: Wed, 15 May 2019 13:05:58 -0700 Subject: [PATCH] Add support for unix sockets for debugger "attach" target (#57) --- docs/debugging.md | 6 +++++- package.json | 4 ++++ src/debugger.ts | 11 +++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/debugging.md b/docs/debugging.md index b70b8a7..86e7e06 100644 --- a/docs/debugging.md +++ b/docs/debugging.md @@ -20,14 +20,18 @@ You will need to set breakpoints before script execution to be able to hit them. Start your HHVM server with the following additional configuration strings in server.ini or CLI args: `hhvm.debugger.vs_debug_enable=1` to enable the debugging extension -`hhvm.debugger.vs_debug_listen_port=` to optionally change the port the debugger listens on (default: `8999`) +`hhvm.debugger.vs_debug_listen_port=` to optionally change the port the debugger listens on (default: `8999`) +`hhvm.debugger.vs_debug_domain_socket_path=` to optionally expose the debugger interface over a unix socket rather than a TCP port E.g. `hhvm -m server -p 8080 -d hhvm.debugger.vs_debug_enable=1 -d hhvm.debugger.vs_debug_listen_port=1234` +You can also use the `--mode vsdebug`, `--vsDebugPort` and `--vsDebugDomainSocketPath` command line arguments for the same purpose. + Add a new HHVM `attach` config to `.vscode/launch.json` and configure as needed: `host`: [Optional] The remote HHVM host (default: `localhost`) `port`: [Optional] The server debugging port, if changed in HHVM config (default: `8999`) +`socket`: [Optional] Path to a Unix domain socket path. If specified, the debugger will attach to this socket rather than a TCP port. If the site root on the server is different from your local workspace, set the following to automatically map them: diff --git a/package.json b/package.json index cae7c71..9f3cb7f 100755 --- a/package.json +++ b/package.json @@ -106,6 +106,10 @@ "description": "Debug port to attach to (default: 8999)", "default": 8999 }, + "socket": { + "type": "string", + "description": "Path to the Unix domain socket to attach to" + }, "remoteSiteRoot": { "type": "string", "description": "Absolute path to workspace root on the remote server, to map to local workspace", diff --git a/src/debugger.ts b/src/debugger.ts index e491169..09482a2 100644 --- a/src/debugger.ts +++ b/src/debugger.ts @@ -7,9 +7,6 @@ * exposes the debugger over a TCP port. This adapter is a thin Node executable that connects * the two. * - * The current implementation is based on Nuclide's HHVM debug adapter located at - * https://github.com/facebook/nuclide/blob/master/pkg/nuclide-debugger-hhvm-rpc/lib/hhvmDebugger.js - * */ import * as child_process from 'child_process'; @@ -29,6 +26,7 @@ type DebuggerWriteCallback = (data: string) => void; interface HhvmAttachRequestArguments extends DebugProtocol.AttachRequestArguments { host?: string; port?: string; + socket?: string; remoteSiteRoot?: string; localWorkspaceRoot?: string; sandboxUser?: string; @@ -92,15 +90,16 @@ class HHVMDebuggerWrapper { this.localWorkspaceRoot = args.localWorkspaceRoot; this.localWorkspaceRootPattern = args.localWorkspaceRoot ? new RegExp(this.escapeRegExp(args.localWorkspaceRoot), 'g') : undefined; - if (Number.isNaN(attachPort)) { - throw new Error('Invalid HHVM debug port specified.'); + if (!args.socket && Number.isNaN(attachPort)) { + throw new Error('Invalid HHVM debug port or socket path.'); } if (!args.sandboxUser || args.sandboxUser.trim() === '') { args.sandboxUser = os.userInfo().username; } - const socket = net.createConnection({ port: attachPort }); + const socketArgs = args.socket ? { path: args.socket } : { port: attachPort}; + const socket = net.createConnection(socketArgs); socket.on('data', chunk => { this.processDebuggerMessage(chunk);