Skip to content

Commit

Permalink
Add support for unix sockets for debugger "attach" target (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
PranayAgarwal authored May 15, 2019
1 parent e834500 commit fb3a926
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<port>` to optionally change the port the debugger listens on (default: `8999`)
`hhvm.debugger.vs_debug_listen_port=<port>` to optionally change the port the debugger listens on (default: `8999`)
`hhvm.debugger.vs_debug_domain_socket_path=<socket file 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:

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fb3a926

Please sign in to comment.