|
| 1 | +This patch corresponds to PR 2684 that causes Delve to warn when |
| 2 | +debugging programs built with an unsupported Go version. This patch |
| 3 | +drops the documentation changes as they did not apply cleanly to 1.7.2. |
| 4 | + |
| 5 | +https://github.com/go-delve/delve/pull/2684 |
| 6 | +https://github.com/go-delve/delve/commit/efc44831754e5e66b66ec7375a3ca424426310ad |
| 7 | + |
| 8 | + |
| 9 | +commit efc44831754e5e66b66ec7375a3ca424426310ad |
| 10 | +Author: polinasok < [email protected]> |
| 11 | +Date: Sat Sep 25 08:41:00 2021 -0700 |
| 12 | + |
| 13 | + pkg/goversion: visibly warn the user with --check-go-version=false (#2684) |
| 14 | + |
| 15 | + |
| 16 | + Co-authored-by: Polina Sokolova < [email protected]> |
| 17 | + |
| 18 | +diff --git pkg/goversion/compat.go pkg/goversion/compat.go |
| 19 | +index b19528eb..053ae138 100644 |
| 20 | +--- pkg/goversion/compat.go |
| 21 | ++++ pkg/goversion/compat.go |
| 22 | +@@ -2,6 +2,8 @@ package goversion |
| 23 | + |
| 24 | + import ( |
| 25 | + "fmt" |
| 26 | ++ |
| 27 | ++ "github.com/go-delve/delve/pkg/logflags" |
| 28 | + ) |
| 29 | + |
| 30 | + var ( |
| 31 | +@@ -9,22 +11,33 @@ var ( |
| 32 | + MinSupportedVersionOfGoMinor = 15 |
| 33 | + MaxSupportedVersionOfGoMajor = 1 |
| 34 | + MaxSupportedVersionOfGoMinor = 17 |
| 35 | +- 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) |
| 36 | +- 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) |
| 37 | ++ 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) |
| 38 | ++ goTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - Go version %%s is too old for this version of Delve (minimum supported version %d.%d)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor) |
| 39 | ++ 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) |
| 40 | ++ dlvTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - version of Delve is too old for Go version %%s (maximum supported version %d.%d)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor) |
| 41 | + ) |
| 42 | + |
| 43 | + // Compatible checks that the version specified in the producer string is compatible with |
| 44 | + // this version of delve. |
| 45 | +-func Compatible(producer string) error { |
| 46 | ++func Compatible(producer string, warnonly bool) error { |
| 47 | + ver := ParseProducer(producer) |
| 48 | + if ver.IsDevel() { |
| 49 | + return nil |
| 50 | + } |
| 51 | ++ verstr := fmt.Sprintf("%d.%d.%d", ver.Major, ver.Minor, ver.Rev) |
| 52 | + if !ver.AfterOrEqual(GoVersion{MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor, -1, 0, 0, ""}) { |
| 53 | +- return goTooOldErr |
| 54 | ++ if warnonly { |
| 55 | ++ logflags.WriteError(fmt.Sprintf(goTooOldWarn, verstr)) |
| 56 | ++ return nil |
| 57 | ++ } |
| 58 | ++ return fmt.Errorf(goTooOldErr, verstr) |
| 59 | + } |
| 60 | + if ver.AfterOrEqual(GoVersion{MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor + 1, -1, 0, 0, ""}) { |
| 61 | +- return dlvTooOldErr |
| 62 | ++ if warnonly { |
| 63 | ++ logflags.WriteError(fmt.Sprintf(dlvTooOldWarn, verstr)) |
| 64 | ++ return nil |
| 65 | ++ } |
| 66 | ++ return fmt.Errorf(dlvTooOldErr, verstr) |
| 67 | + } |
| 68 | + return nil |
| 69 | + } |
| 70 | +diff --git pkg/logflags/logflags.go pkg/logflags/logflags.go |
| 71 | +index 756e7ae6..db34e502 100644 |
| 72 | +--- pkg/logflags/logflags.go |
| 73 | ++++ pkg/logflags/logflags.go |
| 74 | +@@ -136,6 +136,14 @@ func writeListeningMessage(server, addr string) { |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | ++func WriteError(msg string) { |
| 79 | ++ if logOut != nil { |
| 80 | ++ fmt.Fprintln(logOut, msg) |
| 81 | ++ } else { |
| 82 | ++ fmt.Fprintln(os.Stderr, msg) |
| 83 | ++ } |
| 84 | ++} |
| 85 | ++ |
| 86 | + var errLogstrWithoutLog = errors.New("--log-output specified without --log") |
| 87 | + |
| 88 | + // Setup sets debugger flags based on the contents of logstr. |
| 89 | +diff --git service/debugger/debugger.go service/debugger/debugger.go |
| 90 | +index bb74c9ac..400fdcdd 100644 |
| 91 | +--- service/debugger/debugger.go |
| 92 | ++++ service/debugger/debugger.go |
| 93 | +@@ -223,9 +223,6 @@ func (d *Debugger) canRestart() bool { |
| 94 | + } |
| 95 | + |
| 96 | + func (d *Debugger) checkGoVersion() error { |
| 97 | +- if !d.config.CheckGoVersion { |
| 98 | +- return nil |
| 99 | +- } |
| 100 | + if d.isRecording() { |
| 101 | + // do not do anything if we are still recording |
| 102 | + return nil |
| 103 | +@@ -234,7 +231,7 @@ func (d *Debugger) checkGoVersion() error { |
| 104 | + if producer == "" { |
| 105 | + return nil |
| 106 | + } |
| 107 | +- return goversion.Compatible(producer) |
| 108 | ++ return goversion.Compatible(producer, !d.config.CheckGoVersion) |
| 109 | + } |
| 110 | + |
| 111 | + func (d *Debugger) TargetGoVersion() string { |
0 commit comments