2021-10-30 02:35:13 +00:00
|
|
|
package dap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
*: misc improvements to config command and substitute-path rules (#3335)
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 #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
"strings"
|
2021-10-30 02:35:13 +00:00
|
|
|
|
|
|
|
"github.com/go-delve/delve/pkg/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func listConfig(args *launchAttachArgs) string {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
config.ConfigureList(&buf, args, "cfgName")
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2021-12-07 17:23:55 +00:00
|
|
|
func configureSet(sargs *launchAttachArgs, args string) (bool, string, error) {
|
2021-10-30 02:35:13 +00:00
|
|
|
v := config.Split2PartsBySpace(args)
|
|
|
|
|
|
|
|
cfgname := v[0]
|
|
|
|
var rest string
|
|
|
|
if len(v) == 2 {
|
|
|
|
rest = v[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
field := config.ConfigureFindFieldByName(sargs, cfgname, "cfgName")
|
|
|
|
if !field.CanAddr() {
|
2021-12-07 17:23:55 +00:00
|
|
|
return false, "", fmt.Errorf("%q is not a configuration parameter", cfgname)
|
2021-10-30 02:35:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if cfgname == "substitutePath" {
|
|
|
|
err := configureSetSubstitutePath(sargs, rest)
|
|
|
|
if err != nil {
|
2021-12-07 17:23:55 +00:00
|
|
|
return false, "", err
|
2021-10-30 02:35:13 +00:00
|
|
|
}
|
|
|
|
// Print the updated client to server and server to client maps.
|
2021-12-07 17:23:55 +00:00
|
|
|
return true, config.ConfigureListByName(sargs, cfgname, "cfgName"), nil
|
2021-10-30 02:35:13 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 14:44:10 +00:00
|
|
|
if cfgname == "showPprofLabels" {
|
|
|
|
err := configureSetShowPprofLabels(sargs, rest)
|
|
|
|
if err != nil {
|
|
|
|
return false, "", err
|
|
|
|
}
|
|
|
|
// Print the updated labels
|
|
|
|
return true, config.ConfigureListByName(sargs, cfgname, "cfgName"), nil
|
|
|
|
}
|
|
|
|
|
2021-10-30 02:35:13 +00:00
|
|
|
err := config.ConfigureSetSimple(rest, cfgname, field)
|
|
|
|
if err != nil {
|
2021-12-07 17:23:55 +00:00
|
|
|
return false, "", err
|
2021-10-30 02:35:13 +00:00
|
|
|
}
|
2021-12-07 17:23:55 +00:00
|
|
|
return true, config.ConfigureListByName(sargs, cfgname, "cfgName"), nil
|
2021-10-30 02:35:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func configureSetSubstitutePath(args *launchAttachArgs, rest string) error {
|
*: misc improvements to config command and substitute-path rules (#3335)
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 #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
if strings.TrimSpace(rest) == "-clear" {
|
|
|
|
args.substitutePathClientToServer = args.substitutePathClientToServer[:0]
|
|
|
|
args.substitutePathServerToClient = args.substitutePathServerToClient[:0]
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-30 02:35:13 +00:00
|
|
|
argv := config.SplitQuotedFields(rest, '"')
|
*: misc improvements to config command and substitute-path rules (#3335)
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 #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
if len(argv) == 2 && argv[0] == "-clear" {
|
|
|
|
argv = argv[1:]
|
|
|
|
}
|
2021-10-30 02:35:13 +00:00
|
|
|
switch len(argv) {
|
*: misc improvements to config command and substitute-path rules (#3335)
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 #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
case 0:
|
|
|
|
// do nothing, let caller show the current list of substitute path rules
|
|
|
|
return nil
|
2021-10-30 02:35:13 +00:00
|
|
|
case 1: // delete substitute-path rule
|
|
|
|
for i := range args.substitutePathClientToServer {
|
|
|
|
if args.substitutePathClientToServer[i][0] == argv[0] {
|
|
|
|
copy(args.substitutePathClientToServer[i:], args.substitutePathClientToServer[i+1:])
|
|
|
|
args.substitutePathClientToServer = args.substitutePathClientToServer[:len(args.substitutePathClientToServer)-1]
|
|
|
|
copy(args.substitutePathServerToClient[i:], args.substitutePathServerToClient[i+1:])
|
|
|
|
args.substitutePathServerToClient = args.substitutePathServerToClient[:len(args.substitutePathServerToClient)-1]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Errorf("could not find rule for %q", argv[0])
|
|
|
|
case 2: // add substitute-path rule
|
|
|
|
for i := range args.substitutePathClientToServer {
|
|
|
|
if args.substitutePathClientToServer[i][0] == argv[0] {
|
|
|
|
args.substitutePathClientToServer[i][1] = argv[1]
|
|
|
|
args.substitutePathServerToClient[i][0] = argv[1]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
args.substitutePathClientToServer = append(args.substitutePathClientToServer, [2]string{argv[0], argv[1]})
|
|
|
|
args.substitutePathServerToClient = append(args.substitutePathServerToClient, [2]string{argv[1], argv[0]})
|
|
|
|
|
|
|
|
default:
|
*: misc improvements to config command and substitute-path rules (#3335)
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 #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
return fmt.Errorf("too many arguments to \"config substitutePath\"")
|
2021-10-30 02:35:13 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2023-12-04 14:44:10 +00:00
|
|
|
|
|
|
|
func configureSetShowPprofLabels(args *launchAttachArgs, rest string) error {
|
|
|
|
if strings.TrimSpace(rest) == "-clear" {
|
|
|
|
args.ShowPprofLabels = args.ShowPprofLabels[:0]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
delete := false
|
|
|
|
argv := config.SplitQuotedFields(rest, '"')
|
|
|
|
if len(argv) == 2 && argv[0] == "-clear" {
|
|
|
|
argv = argv[1:]
|
|
|
|
delete = true
|
|
|
|
}
|
|
|
|
switch len(argv) {
|
|
|
|
case 0:
|
|
|
|
// do nothing, let caller show the current list of labels
|
|
|
|
return nil
|
|
|
|
case 1:
|
|
|
|
if delete {
|
|
|
|
for i := range args.ShowPprofLabels {
|
|
|
|
if args.ShowPprofLabels[i] == argv[0] {
|
|
|
|
copy(args.ShowPprofLabels[i:], args.ShowPprofLabels[i+1:])
|
|
|
|
args.ShowPprofLabels = args.ShowPprofLabels[:len(args.ShowPprofLabels)-1]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Errorf("could not find label %q", argv[0])
|
|
|
|
} else {
|
|
|
|
args.ShowPprofLabels = append(args.ShowPprofLabels, argv[0])
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("too many arguments to \"config showPprofLabels\"")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|