diff --git a/Documentation/usage/dlv.md b/Documentation/usage/dlv.md index 7feb273fc405686a611332084333fde5388240b0..7ec447aa1e97ef22690156bec64284ef756fa612 100644 --- a/Documentation/usage/dlv.md +++ b/Documentation/usage/dlv.md @@ -23,7 +23,7 @@ Pass flags to the program you are debugging using `--`, for example: --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. -h, --help help for dlv diff --git a/Documentation/usage/dlv_attach.md b/Documentation/usage/dlv_attach.md index 623fa78723205b3d455580ec765f4290e26e4a12..b98d0fd84a4c549869e69c6a733029180663084b 100644 --- a/Documentation/usage/dlv_attach.md +++ b/Documentation/usage/dlv_attach.md @@ -30,7 +30,7 @@ dlv attach pid [executable] [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_backend.md b/Documentation/usage/dlv_backend.md index 6262097aa3b1e41ab0b857bef25c22d0f99cb5ef..009f4094b824565347c29b758eec9b716ce08315 100644 --- a/Documentation/usage/dlv_backend.md +++ b/Documentation/usage/dlv_backend.md @@ -28,7 +28,7 @@ are: --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_connect.md b/Documentation/usage/dlv_connect.md index 80c921ede20d15ffa2e9dcee01c59d5122fa6c58..096e57e4e6e5e5d4ebecf552951d9964ac8f004e 100644 --- a/Documentation/usage/dlv_connect.md +++ b/Documentation/usage/dlv_connect.md @@ -24,7 +24,7 @@ dlv connect addr [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_core.md b/Documentation/usage/dlv_core.md index 37a34a16e759339b61d090a8db1aa57d8773c61b..cb69b87e8643bf56e25d183ef023c08d5c1ced0d 100644 --- a/Documentation/usage/dlv_core.md +++ b/Documentation/usage/dlv_core.md @@ -30,7 +30,7 @@ dlv core [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_dap.md b/Documentation/usage/dlv_dap.md index 63d89847aac8cb669935eb569dd2dfcf68b489f0..9ec39247d64e6a7c0fa7f6efc2cfc039b7042820 100644 --- a/Documentation/usage/dlv_dap.md +++ b/Documentation/usage/dlv_dap.md @@ -38,7 +38,7 @@ dlv dap [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_debug.md b/Documentation/usage/dlv_debug.md index 4611e3bf15d4732f6ca8da1331e74aefc6b932d2..b50413c205fd341143c1641fcf84d3c2e7624ed2 100644 --- a/Documentation/usage/dlv_debug.md +++ b/Documentation/usage/dlv_debug.md @@ -32,7 +32,7 @@ dlv debug [package] [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_exec.md b/Documentation/usage/dlv_exec.md index 498fe837f434ae73566e7463275d1826ff5e9ff3..06f007e3f2397f0809bd0af9283e77ee7e79979b 100644 --- a/Documentation/usage/dlv_exec.md +++ b/Documentation/usage/dlv_exec.md @@ -32,7 +32,7 @@ dlv exec [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_log.md b/Documentation/usage/dlv_log.md index b41f1918de38847ffbd28afa7bf091a09ac72863..d925a7ea2904edfb274be7645c37c0a5661976fd 100644 --- a/Documentation/usage/dlv_log.md +++ b/Documentation/usage/dlv_log.md @@ -43,7 +43,7 @@ and dap modes. --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_redirect.md b/Documentation/usage/dlv_redirect.md index e6272128cf81b0ee107ffa79a7eae11cd6482d1c..ca50e5050fb88590d3e80e820f6422500aa26866 100644 --- a/Documentation/usage/dlv_redirect.md +++ b/Documentation/usage/dlv_redirect.md @@ -31,7 +31,7 @@ File redirects can also be changed using the 'restart' command. --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_replay.md b/Documentation/usage/dlv_replay.md index c92f2d61d9d39bdbe33923afb19d72bcd40b25b7..89832fd0d0397449a89405cf4e82cdc00869e11e 100644 --- a/Documentation/usage/dlv_replay.md +++ b/Documentation/usage/dlv_replay.md @@ -28,7 +28,7 @@ dlv replay [trace directory] [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_run.md b/Documentation/usage/dlv_run.md index 0032e1939ca32437e3471311a2c681eec00f2901..c2db3e457d2f598f8c4ef9ae3c061004e30bdf6d 100644 --- a/Documentation/usage/dlv_run.md +++ b/Documentation/usage/dlv_run.md @@ -20,7 +20,7 @@ dlv run [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_test.md b/Documentation/usage/dlv_test.md index d291a844abbba87332b531a0138c51f5137c9b4e..2d8526f0628d24c2b2ce2371357afd7a6af78ad8 100644 --- a/Documentation/usage/dlv_test.md +++ b/Documentation/usage/dlv_test.md @@ -34,7 +34,7 @@ dlv test [package] [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_trace.md b/Documentation/usage/dlv_trace.md index 5d7548ae68f9f820cc4d870ac2da4985f2975942..fa50aa7841129b5c03e46e09ec129abfaabaaa25 100644 --- a/Documentation/usage/dlv_trace.md +++ b/Documentation/usage/dlv_trace.md @@ -38,7 +38,7 @@ dlv trace [package] regexp [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/Documentation/usage/dlv_version.md b/Documentation/usage/dlv_version.md index 6fec61119c9fac4c4297cb7b38691b3cde68c728..1a21d1942cccb3f1a082543a76d601aa0cfe14df 100644 --- a/Documentation/usage/dlv_version.md +++ b/Documentation/usage/dlv_version.md @@ -21,7 +21,7 @@ dlv version [flags] --api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1) --backend string Backend selection (see 'dlv help backend'). (default "default") --build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v" - --check-go-version Checks that the version of Go in use is compatible with Delve. (default true) + --check-go-version Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve. (default true) --disable-aslr Disables address space randomization --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index d7bf87e02bf8a3577166dc684f85436b73c88d37..51948e49f151b6914f64f7919f4b6aff545d3e87 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -130,7 +130,7 @@ func New(docCall bool) *cobra.Command { rootCommand.PersistentFlags().StringVar(&initFile, "init", "", "Init file, executed by the terminal client.") rootCommand.PersistentFlags().StringVar(&buildFlags, "build-flags", buildFlagsDefault, "Build flags, to be passed to the compiler. For example: --build-flags=\"-tags=integration -mod=vendor -cover -v\"") rootCommand.PersistentFlags().StringVar(&workingDir, "wd", "", "Working directory for running the program.") - rootCommand.PersistentFlags().BoolVarP(&checkGoVersion, "check-go-version", "", true, "Checks that the version of Go in use is compatible with Delve.") + rootCommand.PersistentFlags().BoolVarP(&checkGoVersion, "check-go-version", "", true, "Exits if the version of Go in use is not compatible (too old or too new) with the version of Delve.") rootCommand.PersistentFlags().BoolVarP(&checkLocalConnUser, "only-same-user", "", true, "Only connections from the same user that started this instance of Delve are allowed to connect.") rootCommand.PersistentFlags().StringVar(&backend, "backend", "default", `Backend selection (see 'dlv help backend').`) rootCommand.PersistentFlags().StringArrayVarP(&redirects, "redirect", "r", []string{}, "Specifies redirect rules for target process (see 'dlv help redirect')") diff --git a/pkg/goversion/compat.go b/pkg/goversion/compat.go index b19528eb43ac68ac8d6d3ed49b6f39d807270ba7..053ae138f68e8dee3e1c8757c00373c616ef6c2d 100644 --- a/pkg/goversion/compat.go +++ b/pkg/goversion/compat.go @@ -2,6 +2,8 @@ package goversion import ( "fmt" + + "github.com/go-delve/delve/pkg/logflags" ) var ( @@ -9,22 +11,33 @@ var ( MinSupportedVersionOfGoMinor = 15 MaxSupportedVersionOfGoMajor = 1 MaxSupportedVersionOfGoMinor = 17 - goTooOldErr = fmt.Errorf("Version of Go is too old for this version of Delve (minimum supported version %d.%d, suppress this error with --check-go-version=false)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor) - dlvTooOldErr = fmt.Errorf("Version of Delve is too old for this version of Go (maximum supported version %d.%d, suppress this error with --check-go-version=false)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor) + goTooOldErr = fmt.Sprintf("Go version %%s is too old for this version of Delve (minimum supported version %d.%d, suppress this error with --check-go-version=false)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor) + goTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - Go version %%s is too old for this version of Delve (minimum supported version %d.%d)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor) + dlvTooOldErr = fmt.Sprintf("Version of Delve is too old for Go version %%s (maximum supported version %d.%d, suppress this error with --check-go-version=false)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor) + dlvTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - version of Delve is too old for Go version %%s (maximum supported version %d.%d)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor) ) // Compatible checks that the version specified in the producer string is compatible with // this version of delve. -func Compatible(producer string) error { +func Compatible(producer string, warnonly bool) error { ver := ParseProducer(producer) if ver.IsDevel() { return nil } + verstr := fmt.Sprintf("%d.%d.%d", ver.Major, ver.Minor, ver.Rev) if !ver.AfterOrEqual(GoVersion{MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor, -1, 0, 0, ""}) { - return goTooOldErr + if warnonly { + logflags.WriteError(fmt.Sprintf(goTooOldWarn, verstr)) + return nil + } + return fmt.Errorf(goTooOldErr, verstr) } if ver.AfterOrEqual(GoVersion{MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor + 1, -1, 0, 0, ""}) { - return dlvTooOldErr + if warnonly { + logflags.WriteError(fmt.Sprintf(dlvTooOldWarn, verstr)) + return nil + } + return fmt.Errorf(dlvTooOldErr, verstr) } return nil } diff --git a/pkg/logflags/logflags.go b/pkg/logflags/logflags.go index 756e7ae6ba007dc5580b20a25710f3721a4472b4..db34e502f3ab612f25162baf8de7062f9f73d2da 100644 --- a/pkg/logflags/logflags.go +++ b/pkg/logflags/logflags.go @@ -136,6 +136,14 @@ func writeListeningMessage(server, addr string) { } } +func WriteError(msg string) { + if logOut != nil { + fmt.Fprintln(logOut, msg) + } else { + fmt.Fprintln(os.Stderr, msg) + } +} + var errLogstrWithoutLog = errors.New("--log-output specified without --log") // Setup sets debugger flags based on the contents of logstr. diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index bb74c9ac48e32cb5b354f56d59fd1722f7286cd9..400fdcddd6d72d7d6f807273fd4b16f9f661c914 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -223,9 +223,6 @@ func (d *Debugger) canRestart() bool { } func (d *Debugger) checkGoVersion() error { - if !d.config.CheckGoVersion { - return nil - } if d.isRecording() { // do not do anything if we are still recording return nil @@ -234,7 +231,7 @@ func (d *Debugger) checkGoVersion() error { if producer == "" { return nil } - return goversion.Compatible(producer) + return goversion.Compatible(producer, !d.config.CheckGoVersion) } func (d *Debugger) TargetGoVersion() string {