Skip to content

Commit 41279a6

Browse files
committed
Revert "src/goDebugFactory.ts: direct users to use 'debugServer' for remote"
This reverts commit 45b06e0. Reason for revert: issue #1729 shows a use case for including this option. We will instead issue a warning that the host and port are being used. Updates #1729 Change-Id: Iea1b96f034caf3517221b3b6b267d7a829d0f652 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/346269 Trust: Suzy Mueller <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Polina Sokolova <[email protected]>
1 parent a4c2c4a commit 41279a6

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

docs/debugging.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ Here is the list of attributes specific to Go debugging.
246246
| `dlvFlags` | Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.<br/> | <center>_same as Launch_</center>|
247247
| `env` | Environment variables passed to the program.<br/> | <center>_n/a_</center> |
248248
| `envFile` | Absolute path to a file containing environment variable definitions. Multiple files can be specified by provided an array of absolute paths<br/>(Default: `${workspaceFolder}/.env`)<br/> | <center>_n/a_</center> |
249-
| `host` | The host name of the machine the delve debugger will be listening on.<br/>(Default: `"127.0.0.1"`)<br/> | <center>_same as Launch_</center>|
249+
| `host` | The host name of the machine the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.<br/>(Default: `"127.0.0.1"`)<br/> | <center>_same as Launch_</center>|
250250
| `logDest` | dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only in `dlv-dap` mode, and on Linux and Mac OS.<br/> | dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only in `dlv-dap` mode and on Linux and Mac OS.<br/> |
251251
| `logOutput` | Comma separated list of components that should produce debug output. Maps to dlv's `--log-output` flag. Check `dlv log` for details.<br/><p>Allowed Values: `"debugger"`, `"gdbwire"`, `"lldbout"`, `"debuglineerr"`, `"rpc"`, `"dap"`<br/>(Default: `"debugger"`)<br/> | <center>_same as Launch_</center>|
252252
| `mode` | One of `auto`, `debug`, `test`, `exec`, `replay`, `core`. In `auto` mode, the extension will choose either `debug` or `test` depending on active editor window.<br/><p>Allowed Values: `"auto"`, `"debug"`, `"test"`, `"exec"`, `"replay"`, `"core"`<br/>(Default: `auto`)<br/> | Indicates local or remote debugging. Local maps to the `dlv attach` command, remote maps to `connect`. `remote` is not supported in `dlv-dap` mode currently. Use `host` and `port` instead.<br/><p>Allowed Values: `"local"`, `"remote"`<br/>(Default: `local`)<br/> |
253253
| `output` | Output path for the binary of the debugee.<br/>(Default: `"debug"`)<br/> | <center>_n/a_</center> |
254-
| `port` | The port that the delve debugger will be listening on.<br/>(Default: `2345`)<br/> | <center>_same as Launch_</center>|
254+
| `port` | The port that the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.<br/>(Default: `2345`)<br/> | <center>_same as Launch_</center>|
255255
| `processId` | <center>_n/a_</center> | <br/><p><b>Option 1:</b> Use process picker to select a process to attach, or Process ID as integer.<br/><p>Allowed Values: `"${command:pickProcess}"`, `"${command:pickGoProcess}"`<br/><br/><p><b>Option 2:</b> Attach to a process by name. If more than one process matches the name, use the process picker to select a process.<br/><br/><p><b>Option 3:</b> The numeric ID of the process to be debugged. If 0, use the process picker to select a process.<br/><br/>(Default: `0`)<br/> |
256256
| `program` | Path to the program folder (or any go file within that folder) when in `debug` or `test` mode, and to the pre-built binary file to debug in `exec` mode. If it is not an absolute path, the extension interpretes it as a workspace relative path.<br/>(Default: `"${workspaceFolder}"`)<br/> | <center>_n/a_</center> |
257257
| `remotePath` | <center>_n/a_</center> | (Deprecated) *Use `substitutePath` instead.*<br/>The path to the source code on the remote machine, when the remote path is different from the local machine. If specified, becomes the first entry in substitutePath.<br/>(Default: `""`)<br/> |
@@ -351,14 +351,58 @@ If you want to explicitly specify the location of the delve binary, use the `go.
351351

352352
> If you are able to use the [Remote Development](https://aka.ms/vscode-remote/download/extension) extensions and VS Code’s universal [remote development capabilities](https://code.visualstudio.com/docs/remote/remote-overview), that is the recommended way to debug Go programs remotely. Check out [Getting started](https://code.visualstudio.com/docs/remote/remote-overview#_getting-started) section and [Remote tutorials](https://code.visualstudio.com/docs/remote/remote-overview#_remote-tutorials) to learn more.
353353

354-
🚧 Remote debugging is the debug mode intended to work with a debugger and target running on a different machine or a container. Support for remote debugging using Delve’s native DAP implementation is still a work-in-progress. Please fall back to the `legacy` debug adapter.
354+
Remote debugging is the debug mode intended to work with a debugger and target running on a different machine or a container. Support for remote debugging using Delve’s native DAP implementation is still a work-in-progress. This section describes a current temporary workaround and its limitations. If the following workaround is not working for your case, please file an issue and help us understand remote debugging use cases better.
355+
356+
<p align="center"><img src="images/remote-debugging.png" alt="Remote Debugging"> </p>
357+
358+
When using the dlv-dap mode, the delve instance running remotely needs to be able to process DAP requests, instead of the traditional JSON-RPC, used with an external `dlv --headless` server. The following command starts a Delve DAP server on port 12345 that is ready to accept a request from an editor such as VS Code for launching or attaching to a target.
359+
360+
```
361+
$ dlv-dap dap --listen=:12345
362+
```
363+
364+
Use the following `launch` configuration to tell `dlv-dap` to execute a binary precompiled with `-gcflags='all=-N -l'`:
365+
366+
```json5
367+
{
368+
"name": "Connect to server (DAP)",
369+
"type": "go",
370+
"debugAdapter": "dlv-dap",
371+
"request": "launch",
372+
"port": 12345,
373+
"host": "127.0.0.1",
374+
"mode": "exec",
375+
"program": "/absolute/path/to/remote/workspace/program/executable",
376+
"substitutePath": [
377+
{ "from": ${workspaceFolder}, "to": "/path/to/remote/workspace" },
378+
...
379+
]
380+
}
381+
```
382+
383+
Or have the binary compiled by dlv-dap by modifying the above configuration to use:
384+
385+
```json5
386+
"mode": "debug",
387+
"program": "/absolute/path/to/remote/workspace/package",
388+
```
389+
390+
When seeing the `"port"` attribute being used in the launch request, Go extension will assume a Delve DAP server is started externally and accessible through the specified `host:port` and tell VS Code to connect to it directly. The `program` attribute must point to the absolute path to the package or binary to debug in the remote host’s file system even when `substitutePath` is specified.
391+
392+
⚠️ Limitations
393+
* Unlike `dlv <debug|exec|attach> --headless` commands traditionally used for remote debugging scenarios, Delve’s new `dap` sub command does not launch or attach to the debuggee process until it receives a Launch/Attach request. We understand this limitation, and we are currently working on addressing this limitation.
394+
* Anyone who can connect to the Delve DAP server’s host:port can exploit it to run arbitrary programs.
395+
* When using `"attach"` requests, you will need to specify the `processId` since
396+
[the processId resolution feature](#attach) cannot gather process information running remotely.
397+
* Delve DAP does not support `--allow-multiclient` or `--continue` flags yet, which means after a debug session ends, the dlv-dap process will exit.
398+
* If you use `debug` or `test` mode `launch` requests, Delve builds the target binary. Delve tries to build the target from the directory where the `dlv` (or `dlv-dap`) process is running, so make sure to run the `dlv-dap` command from the directory you’d run the `go build` or `go test` command.
355399

356400
### Running Debugee Externally
357401

358402
Sometimes you’d like to launch the program for debugging outside VS Code (e.g., as a workaround of the missing `console` support), there are currently two options.
359403

360404
* Compile and run the program from the external terminal and use [the "attach" configuration](#attach).
361-
* Launch the server externally; run `dlv-dap dap --listen=:<port>` from the external terminal, and set the `"debugServer": <port>` attribute in your launch configuration.
405+
* Use ["Remote Debugging"](#remote-debugging); run `dlv-dap dap --listen=:<port>` from the external terminal, and set the `"port"` attribute in your launch configuration.
362406

363407
## Reporting Issues
364408

@@ -421,7 +465,7 @@ $ dlv-dap dap --listen=:12345 --log --log-output=dap
421465
"request": "launch",
422466
"debugAdapter": "dlv-dap",
423467
...
424-
"debugServer": 12345,
468+
"port": 12345
425469
}
426470
```
427471

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,12 @@
639639
},
640640
"port": {
641641
"type": "number",
642-
"description": "The port that the delve debugger will be listening on.",
642+
"description": "The port that the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.",
643643
"default": 2345
644644
},
645645
"host": {
646646
"type": "string",
647-
"description": "The host name of the machine the delve debugger will be listening on.",
647+
"description": "The host name of the machine the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.",
648648
"default": "127.0.0.1"
649649
},
650650
"trace": {
@@ -831,12 +831,12 @@
831831
},
832832
"port": {
833833
"type": "number",
834-
"description": "The port that the delve debugger will be listening on.",
834+
"description": "The port that the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.",
835835
"default": 2345
836836
},
837837
"host": {
838838
"type": "string",
839-
"description": "The host name of the machine the delve debugger will be listening on.",
839+
"description": "The host name of the machine the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.",
840840
"default": "127.0.0.1"
841841
},
842842
"substitutePath": {

src/goDebugConfiguration.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
158158
// for local mode, default to dlv-dap.
159159
debugConfiguration['debugAdapter'] = debugConfiguration['mode'] !== 'remote' ? 'dlv-dap' : 'legacy';
160160
}
161-
if (debugConfiguration['debugAdapter'] === 'dlv-dap' && debugConfiguration['port']) {
162-
this.showWarning(
163-
'ignorePortInDlvDapWarning',
164-
"`port` is ignored with the 'dlv-dap' debugAdapter, which does not yet support remote debugging. Please file an issue if you have a use case that requires port."
165-
);
166-
}
167161
if (debugConfiguration['debugAdapter'] === 'dlv-dap' && debugConfiguration['mode'] === 'remote') {
168162
this.showWarning(
169163
'ignoreDlvDAPInRemoteModeWarning',

src/goDebugFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescr
3737
private async createDebugAdapterDescriptorDlvDap(
3838
configuration: vscode.DebugConfiguration
3939
): Promise<vscode.ProviderResult<vscode.DebugAdapterDescriptor>> {
40+
if (configuration.port) {
41+
return new vscode.DebugAdapterServer(configuration.port, configuration.host ?? '127.0.0.1');
42+
}
4043
const logger = new TimestampedLogger(configuration.trace, this.outputChannel);
4144
logger.debug(`Config: ${JSON.stringify(configuration)}`);
4245
const d = new DelveDAPOutputAdapter(configuration, logger);

0 commit comments

Comments
 (0)