forked from go-delve/delve
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: misc improvements to config command and substitute-path rules
A series of interconnected changes to both the terminal command 'config', DAP command 'dlv config', quality of life improvements to how substitute-path works, and better documentation. - Let 'config substitute-path' show the current substitute path rules - Add a -clear command to 'config substitute-path' - Support 'config-debug-info-directories' - rewrite SubstitutePath to be platform independent (see below) - document path substitution more Regarding the rewrite of SubstitutePath: the previous version used runtime.GOOS and filepath.IsAbs to determine which filepath separator to use and if matching should be case insensitive. This is wrong in all situations where the client and server run on different OSes, when examining core files and when cross-compilation is involved. The new version of SubstitutePath checks the rules and the input path to determine if Windows is involved in the process, if it looks like it is it switches to case-insensitive matching. It uses a lax version of filepath.IsAbs to determine if a path is absolute and tries to avoid having to select a path separator as much as possible Fixes go-delve#2891, go-delve#2890, go-delve#2889, go-delve#3179, go-delve#3332, go-delve#3343
- Loading branch information
Showing
23 changed files
with
460 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
## Path substitution configuration | ||
|
||
Normally Delve finds the path to the source code that was used to produce an executable by looking at the debug symbols of the executable. | ||
However, under [some circumstances](../faq.md#substpath), the paths that end up inside the executable will be different from the paths to the source code on the machine that is running the debugger. If that is the case Delve will need extra configuration to convert the paths stored inside the executable to paths in your local filesystem. | ||
|
||
This configuration is done by specifying a list of path substitution rules. | ||
|
||
|
||
### Where are path substitution rules specified | ||
|
||
#### Delve command line client | ||
|
||
The command line client reads the path substitution rules from Delve's YAML configuration file located at `$XDG_CONFIG_HOME/dlv/config.yml` or `.dlv/config.yml` inside the home directory on Windows. | ||
|
||
The `substitute-path` entry should look like this: | ||
|
||
``` | ||
substitute-path: | ||
- {from: "/compiler/machine/directory", to: "/debugger/machine/directory"} | ||
- {from: "", to: "/mapping/for/relative/paths"} | ||
``` | ||
|
||
If you are starting a headless instance of Delve and connecting to it through `dlv connect` the configuration file that is used is the one that runs `dlv connect`. | ||
|
||
The rules can also be modified while Delve is running by using the [config substitute-path command](./README.md#config): | ||
|
||
``` | ||
(dlv) config substitute-path /from/path /to/path | ||
``` | ||
|
||
Double quotes can be used to specify paths that contain spaces, or to specify empty paths: | ||
|
||
``` | ||
(dlv) config substitute-path "/path containing spaces/" /path-without-spaces/ | ||
(dlv) config substitute-path /make/this/path/relative "" | ||
``` | ||
|
||
#### DAP server | ||
|
||
If you connect to Delve using the DAP protocol then the substitute path rules are specified using the substitutePath option in [launch.json](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#launchjson-attributes). | ||
|
||
``` | ||
"substitutePath": [ | ||
{ "from": "/from/path", "to": "/to/path" } | ||
] | ||
``` | ||
|
||
The [debug console](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#dlv-command-from-debug-console) can also be used to modify the path substitution list: | ||
|
||
``` | ||
dlv config substitutePath /from/path /to/path | ||
``` | ||
|
||
This command works similarly to the `config substitute-path` command described above. | ||
|
||
### How are path substitution rules applied | ||
|
||
Regardless of how they are specified the path substitution rules are an ordered list of `(from-path, to-path)` pairs. When Delve needs to convert a path P found inside the executable file into a path in the local filesystem it will scan through the list of rules looking for the first one where P starts with from-path and replace from-path with to-path. | ||
|
||
Empty paths in both from-path and to-path are special, they represent relative paths: | ||
|
||
- `(from="" to="/home/user/project/src")` converts all relative paths in the executable to absolute paths in `/home/user/project/src` | ||
- `(from="/build/dir" to="")` converts all paths in the executable that start with `/build/dir` into relative paths. | ||
|
||
The path substitution code is SubstitutePath in pkg/locspec/locations.go. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.