Skip to content

Commit fa820d4

Browse files
committed
docs/debugging.md: add tips for debugging with -trimpath
Updates #2609 Change-Id: I6fae938b428f834f8e55e2e8afd4d309db33d0a9 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/469916 Reviewed-by: Ethan Reesor <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 6aaa26a commit fa820d4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/debugging.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,49 @@ culprits are remote debugging where the program is built in the remote location,
10131013
use of symbolic links, or use of `-trimpath` build flags. In this case,
10141014
configure the `substitutePath` attribute in your launch configuration.
10151015

1016+
#### Trimpath tips
1017+
1018+
If you are using `-trimpath` to build your program, you need to add entries to substitute
1019+
path to let the debugger know how to map the package paths that are compiled in the
1020+
binary to the files that you are looking at in the editor.
1021+
1022+
Here are some tips for configuring substitutePath. This assumes that your program is using module mode, which is the default.
1023+
1024+
One rule that you will need will map your main module. The mapping will map `"from"` the file path to the directory containing the module, `"to"` the module path.
1025+
1026+
You will also need to create a similar mapping for all dependencies. These include modules
1027+
in the module cache, vendored modules, and the standard library.
1028+
1029+
```json
1030+
"substitutePath": [
1031+
// Main module.
1032+
{
1033+
"from": "${workspaceFolder}",
1034+
"to": "moduleName",
1035+
},
1036+
// Module cache paths.
1037+
{
1038+
"from": "${env:HOME}/go/pkg/mod/github.com",
1039+
"to": "github.com",
1040+
},
1041+
{
1042+
"from": "${env:HOME}/go/pkg/mod/golang.org",
1043+
"to": "golang.org",
1044+
},
1045+
...
1046+
// Standard library paths.
1047+
// This rule should come last since the empty "to" will match every path.
1048+
{ "from": "/path/to/local/goroot/pkg" , "to": ""}
1049+
],
1050+
```
1051+
1052+
Since rules are applied both from client to server and server to client,
1053+
rules with an empty string will be applied to *all* paths that it sees, so even
1054+
dependencies will be mapped to `"/path/to/module"`.
1055+
1056+
We plan to make this easier in the future. Progress can be tracked
1057+
in the issue tracker [golang/vscode-go#1985](https://github.com/golang/vscode-go/issues/1985).
1058+
10161059
### Debug sessions started with the "debug test" CodeLens or the test UI does not use my `launch.json` configuration
10171060

10181061
The "debug test" CodeLens and the [test UI](features.md#test-and-benchmark) do

0 commit comments

Comments
 (0)