You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
src/debugAdapter: add substitutePath config for debugging
This change adds a new configuration option to both launch and
attach requests. substituePath takes an array that maps from string to string
that is used to translate paths passed to the debugger and then
back to the client.
This allows users to translate their symlinked directories to the
files that were actually used to build the binary. In addition this
can also be used for remote debugging, and when the location of the
files has moved since the program was built.
Update #622
Change-Id: I71b081d17a29655c14cd20093dc9f88867fbcc69
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/270017
Trust: Suzy Mueller <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Run-TryBot: Suzy Mueller <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Polina Sokolova <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Copy file name to clipboardExpand all lines: docs/debugging.md
+41-4
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,8 @@ args | Array of command-line arguments to pass to the program being debugg
110
110
showLog | If `true`, Delve logs will be printed in the Debug Console panel.
111
111
logOutput | Comma-separated list of Delve components (`debugger`, `gdbwire`, `lldbout`, `debuglineerr`, `rpc`) that should produce debug output when `showLog` is `true`.
112
112
buildFlags | Build flags to pass to the Go compiler.
113
-
remotePath | If remote debugging (`mode`: `remote`), this should be the absolute path to the package being debugged on the remote machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
113
+
remotePath | If remote debugging (`mode`: `remote`), this should be the absolute path to the package being debugged on the remote machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant. Becomes the first mapping in substitutePath.
114
+
substitutePath | An array of mappings from an absolute local path to an absolute remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls. The mappings are applied in order, and the first matching mapping is used. This can be used to map files that have moved since the program was built, different remote paths, and symlinked files or directories. This is intended to be equivalent to the [substitute-path]((https://github.com/go-delve/delve/tree/master/Documentation/cli#config)(https://github.com/go-delve/delve/tree/master/Documentation/cli#config)) configuration, and will eventually configure substitute-path in Delve directly.
114
115
cwd | The working directory to be used in running the program. If remote debugging (`mode`: `remote`), this should be the absolute path to the working directory being debugged on the local machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
115
116
processId | This is the process ID of the executable you want to debug. Applicable only when using the `attach` request in `local` mode.
116
117
@@ -308,7 +309,27 @@ Then, create a remote debug configuration in your `launch.json`.
308
309
309
310
In the example, the VS Code debugger will run on the same machine as the headless `dlv` server. Make sure to update the `port` and `host` settings to point to your remote machine.
310
311
311
-
`remotePath` should point to the absolute path of the program being debugged in the remote machine. `cwd` should point to the absolute path of the working directory of the program being debugged on your local machine. This should be the counterpart of the folder in `remotePath`. See [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) for updates regarding `remotePath` and `cwd`.
312
+
`remotePath` should point to the absolute path of the program being debugged in the remote machine. `cwd` should point to the absolute path of the working directory of the program being debugged on your local machine. This should be the counterpart of the folder in `remotePath`. See [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) for updates regarding `remotePath` and `cwd`. You can also use the equivalent `substitutePath` configuration.
313
+
314
+
```json5
315
+
{
316
+
"name":"Launch remote",
317
+
"type":"go",
318
+
"request":"attach",
319
+
"mode":"remote",
320
+
"substitutePath": [
321
+
{
322
+
"from":"/absolute/path/dir/on/local/machine",
323
+
"to":"/absolute/path/dir/on/remote/machine",
324
+
},
325
+
],
326
+
"port":2345,
327
+
"host":"127.0.0.1",
328
+
"cwd":"/absolute/path/dir/on/local/machine",
329
+
}
330
+
```
331
+
332
+
If you do not set, `remotePath` or `substitutePath`, then the debug adapter will attempt to infer the path mappings. See [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) for more information.
312
333
313
334
When you run the `Launch remote` target, VS Code will send debugging commands to the `dlv` server you started, instead of launching it's own `dlv` instance against your program.
314
335
@@ -405,9 +426,25 @@ This error can show up for Mac users using Delve versions 0.12.2 and above. `xco
405
426
406
427
### Debugging symlink directories
407
428
408
-
This extension does not provide support for debugging projects containing symlinks. Make sure that you are setting breakpoints in the files that Go will use to compile your program.
429
+
Since the debugger and go compiler use the actual filenames, extra configuration is required to debug symlinked directories. Use the `substitutePath` property to tell the debugAdapter how to properly translate the paths. For example, if your project lives in `/path/to/actual/helloWorld`, but the project is open in vscode under the linked folder `/path/to/hello`, you can add the following to your config to set breakpoints in the files in `/path/to/hello`:
430
+
431
+
```json5
432
+
{
433
+
"name":"Launch remote",
434
+
"type":"go",
435
+
"request":"launch",
436
+
"mode":"auto",
437
+
"program":"/path/to/hello",
438
+
"substitutePath": [
439
+
{
440
+
"from":"/path/to/hello",
441
+
"to":"/path/to/actual/helloWorld",
442
+
},
443
+
],
444
+
}
445
+
```
409
446
410
-
For updates to symlink support reference [golang/vscode-go#622](https://github.com/golang/vscode-go/issues/622).
447
+
This extension does not provide general support for debugging projects containing symlinks. If `substitutePath` does not meet your needs, please consider commenting on this issue that contains updates to symlink support reference [golang/vscode-go#622](https://github.com/golang/vscode-go/issues/622).
Copy file name to clipboardExpand all lines: package.json
+43-3
Original file line number
Diff line number
Diff line change
@@ -522,6 +522,26 @@
522
522
"description": "Environment variables passed to the program.",
523
523
"default": {}
524
524
},
525
+
"substitutePath": {
526
+
"type": "array",
527
+
"items": {
528
+
"type": "object",
529
+
"properties": {
530
+
"from": {
531
+
"type": "string",
532
+
"description": "The absolute local path to be replaced when passing paths to the debugger",
533
+
"default": ""
534
+
},
535
+
"to": {
536
+
"type": "string",
537
+
"description": "The absolute remote path to be replaced when passing paths back to the client",
538
+
"default": ""
539
+
}
540
+
}
541
+
},
542
+
"description": "An array of mappings from a local path to the remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls. Overriden by remotePath.",
543
+
"default": []
544
+
},
525
545
"buildFlags": {
526
546
"type": "string",
527
547
"description": "Build flags, to be passed to the Go compiler.",
@@ -534,7 +554,7 @@
534
554
},
535
555
"remotePath": {
536
556
"type": "string",
537
-
"description": "Absolute path to the file being debugged on the remote machine in case of remote debugging.",
557
+
"description": "Absolute path to the file being debugged on the remote machine in case of remote debugging. If specified, becomes the first entry in substitutePath.",
538
558
"default": ""
539
559
},
540
560
"port": {
@@ -680,7 +700,7 @@
680
700
},
681
701
"remotePath": {
682
702
"type": "string",
683
-
"description": "If remote debugging, the path to the source code on the remote machine, if different from the local machine.",
703
+
"description": "If remote debugging, the path to the source code on the remote machine, if different from the local machine. If specified, becomes the first entry in substitutePath.",
684
704
"default": ""
685
705
},
686
706
"port": {
@@ -693,6 +713,26 @@
693
713
"description": "The host name of the machine the delve debugger will be listening on.",
694
714
"default": "127.0.0.1"
695
715
},
716
+
"substitutePath": {
717
+
"type": "array",
718
+
"items": {
719
+
"type": "object",
720
+
"properties": {
721
+
"from": {
722
+
"type": "string",
723
+
"description": "The absolute local path to be replaced when passing paths to the debugger",
724
+
"default": ""
725
+
},
726
+
"to": {
727
+
"type": "string",
728
+
"description": "The absolute remote path to be replaced when passing paths back to the client",
729
+
"default": ""
730
+
}
731
+
}
732
+
},
733
+
"description": "An array of mappings from a local path to the remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls.",
734
+
"default": []
735
+
},
696
736
"trace": {
697
737
"type": "string",
698
738
"enum": [
@@ -1063,7 +1103,7 @@
1063
1103
},
1064
1104
"remotePath": {
1065
1105
"type": "string",
1066
-
"description": "If remote debugging, the path to the source code on the remote machine, if different from the local machine.",
1106
+
"description": "If remote debugging, the path to the source code on the remote machine, if different from the local machine. If specified, becomes the first entry in substitutePath.",
// So, update it to use the same separator for ease in path replacement.
1065
+
filePath=normalizeSeparators(filePath);
1066
+
letsubstitutedPath=filePath;
1067
+
letsubstituteRule: {from: string,to: string};
1068
+
this.substitutePath.forEach((value)=>{
1069
+
if(filePath.startsWith(value.from)){
1070
+
if(!!substituteRule){
1071
+
log(`Substitutition rule ${value.from}:${value.to} applies to local path ${filePath} but it was already mapped to debugger path using rule ${substituteRule.from}:${substituteRule.to}`);
// If there is a substitutePath mapping, then we replace the path.
1242
+
pathToConvert=normalizeSeparators(pathToConvert);
1243
+
letsubstitutedPath=pathToConvert;
1244
+
letsubstituteRule: {from: string,to: string};
1245
+
this.substitutePath.forEach((value)=>{
1246
+
if(pathToConvert.startsWith(value.to)){
1247
+
if(!!substituteRule){
1248
+
log(`Substitutition rule ${value.from}:${value.to} applies to debugger path ${pathToConvert} but it was already mapped to local path using rule ${substituteRule.from}:${substituteRule.to}`);
0 commit comments