Repository: go-delve/delve
Pull request #2789 (2021-11-14 07:13:12)

version: fix build version using buildInfo
In go1.18 buildInfo will include the git revision hash, use that to fix
the Build field of Version so that it is correct even if Delve wasn't
built using make.go.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4e591889..b3b3c6e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,48 @@
 All notable changes to this project will be documented in this file.
 This project adheres to Semantic Versioning.
 
+## [1.7.3] 2021-11-16
+
+### Added
+
+* Misc changes to prepare for Go 1.18 and generics (#2703, @2745, @aarzilli)
+* Watchpoint support (disabled on Windows) (#2651, #2659, #2667, #2769, @aarzilli)
+* Warn about listening to remote connections (#2721, @aarzilli)
+* Support call injection with rr backend (#2740, @aarzilli)
+* Support JSON-RPC and DAP on the same port from 'dlv debug/exec/test/attach' (#2755, @polinasok)
+* DAP: Remote attach support (#2709, @polinasok)
+* DAP: Multi-client support (#2731, #2737, #2781, @polinasok)
+* DAP: Logpoints support (#2634, #2730, #2747, #2748, @suzmue)
+* DAP: Dissasembly view support (#2713, #2716, #2728, #2742, @suzmue)
+* DAP: Support dlvCwd and use a temp file as default debug binary (#2660, #2734, @hyangah, @polinasok)
+* DAP: Auto-resume execution when setting breakpoints while running (#2726, @suzmue)
+* DAP: Add --client-addr flag to run dap with a predefined client (#2568, @hyangah)
+* DAP: Log parsed and applied launch configs (#2732, @polinasok)
+* DAP: Add option to hide system goroutines (#2743, @suzmue)
+* DAP: Add support for special 'config' expressions (#2750, @suzmue)
+
+### Fixed
+
+* Return correct exit status from Halt command (#2674, @suzmue)
+* Merge register data before writing to register (#2699, @mknyszek)
+* Do not assign temp breakpoint IDs to avoid conflicts with user breakpoints (#2650, @aarzilli)
+* Miscellaneous fixes for Windows native backend (#2736, @aarzilli)
+* Return error when assigning between function variables (#2692, @aarzilli)
+* Obey logflags config for LoadConfig warnings (#2701, @aarzilli, @suzmue)
+* Workaround for debugserver register set bug (#2770, @aarzilli)
+* DAP: Fix nil dereference when byte array cannot be converted to string (#2733, @polinasok)
+* DAP: Fix data race for noDebugProcess.ProcessState (#2735, @polinasok)
+
+### Changed
+
+* Refine handling of version-too-old errors (#2684, #2712, @polinasok, @yang-wei)
+* eBPF tracing backend return value parsing (#2704, @derekparker)
+* Replace libbpfgo with cilium/ebpf (##2771, @derekparker)
+* DAP: Merge Arguments and Locals scopes (#2717, @suzmue)
+* DAP: Refine launch/attach error visibility (#2671, @polinasok)
+* DAP: Server refactoring to separate listener and client session layers (#2729, @polinasok)
+* DAP: Improve shutdown logic and test coverage (#2749, @polinasok)
+
 ## [1.7.2] 2021-09-21
 
 ### Added
diff --git a/pkg/version/fixbuild.go b/pkg/version/fixbuild.go
new file mode 100644
index 00000000..e2dad6e0
--- /dev/null
+++ b/pkg/version/fixbuild.go
@@ -0,0 +1,23 @@
+//go:build go1.18
+// +build go1.18
+
+package version
+
+import "runtime/debug"
+
+func init() {
+	fixBuild = buildInfoFixBuild
+}
+
+func buildInfoFixBuild(v *Version) {
+	info, ok := debug.ReadBuildInfo()
+	if !ok {
+		return
+	}
+	for i := range info.Settings {
+		if info.Settings[i].Key == "gitrevision" {
+			v.Build = info.Settings[i].Value
+			break
+		}
+	}
+}
diff --git a/pkg/version/version.go b/pkg/version/version.go
index a06f0b8c..c532746b 100644
--- a/pkg/version/version.go
+++ b/pkg/version/version.go
@@ -17,13 +17,14 @@ type Version struct {
 var (
 	// DelveVersion is the current version of Delve.
 	DelveVersion = Version{
-		Major: "1", Minor: "7", Patch: "2", Metadata: "",
+		Major: "1", Minor: "7", Patch: "3", Metadata: "",
 		//TODO(aarzilli): before updating this to 1.8.0 re-enable staticcheck test
 		Build: "$Id$",
 	}
 )
 
 func (v Version) String() string {
+	fixBuild(&v)
 	ver := fmt.Sprintf("Version: %s.%s.%s", v.Major, v.Minor, v.Patch)
 	if v.Metadata != "" {
 		ver += "-" + v.Metadata
@@ -38,3 +39,7 @@ var buildInfo = func() string {
 func BuildInfo() string {
 	return fmt.Sprintf("%s\n%s", runtime.Version(), buildInfo())
 }
+
+var fixBuild = func(v *Version) {
+	// does nothing
+}
diff --git a/service/dap/command.go b/service/dap/command.go
index 0b08c569..a9690d2f 100644
--- a/service/dap/command.go
+++ b/service/dap/command.go
@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"errors"
 	"fmt"
+	"sort"
 	"strings"
 
 	"github.com/go-delve/delve/pkg/config"
@@ -37,24 +38,29 @@ type command struct {
 const (
 	msgHelp = `Prints the help message.
 	
-help [command]
+dlv help [command]
 
 Type "help" followed by the name of a command for more information about it.`
 
 	msgConfig = `Changes configuration parameters.
 	
-	config -list
+	dlv config -list
 	
 	Show all configuration parameters.
 	
-	config <parameter> <value>
+	dlv config <parameter> <value>
 	
 	Changes the value of a configuration parameter.
 	
-	config substitutePath <from> <to>
-	config substitutePath <from>
+	dlv config substitutePath <from> <to>
+	dlv config substitutePath <from>
 	
 	Adds or removes a path substitution rule.`
+	msgSources = `Print list of source files.
+
+	dlv sources [<regex>]
+
+If regex is specified only the source files matching it will be returned.`
 )
 
 // debugCommands returns a list of commands with default commands defined.
@@ -62,6 +68,7 @@ func debugCommands(s *Session) []command {
 	return []command{
 		{aliases: []string{"help", "h"}, cmdFn: s.helpMessage, helpMsg: msgHelp},
 		{aliases: []string{"config"}, cmdFn: s.evaluateConfig, helpMsg: msgConfig},
+		{aliases: []string{"sources", "s"}, cmdFn: s.sources, helpMsg: msgSources},
 	}
 }
 
@@ -88,14 +95,14 @@ func (s *Session) helpMessage(_, _ int, args string) (string, error) {
 			h = h[:idx]
 		}
 		if len(cmd.aliases) > 1 {
-			fmt.Fprintf(&buf, "    %s (alias: %s) \t %s\n", cmd.aliases[0], strings.Join(cmd.aliases[1:], " | "), h)
+			fmt.Fprintf(&buf, "    dlv %s (alias: %s) \t %s\n", cmd.aliases[0], strings.Join(cmd.aliases[1:], " | "), h)
 		} else {
-			fmt.Fprintf(&buf, "    %s \t %s\n", cmd.aliases[0], h)
+			fmt.Fprintf(&buf, "    dlv %s \t %s\n", cmd.aliases[0], h)
 		}
 	}
 
 	fmt.Fprintln(&buf)
-	fmt.Fprintln(&buf, "Type help followed by a command for full documentation.")
+	fmt.Fprintln(&buf, "Type 'dlv help' followed by a command for full documentation.")
 	return buf.String(), nil
 }
 
@@ -113,3 +120,12 @@ func (s *Session) evaluateConfig(_, _ int, expr string) (string, error) {
 		return res, nil
 	}
 }
+
+func (s *Session) sources(_, _ int, filter string) (string, error) {
+	sources, err := s.debugger.Sources(filter)
+	if err != nil {
+		return "", err
+	}
+	sort.Strings(sources)
+	return strings.Join(sources, "\n"), nil
+}


Test patch:
diff --git a/_scripts/latestver.py b/_scripts/latestver.py
index 886d476e..b8483009 100644
--- a/_scripts/latestver.py
+++ b/_scripts/latestver.py
@@ -19,7 +19,7 @@ def splitver(x):
 	return v
 
 ver = sys.argv[1]
-d = json.loads(urllib.urlopen('https://golang.org/dl/?mode=json&include=all').read())
+d = json.loads(urllib.urlopen('https://go.dev/dl/?mode=json&include=all').read())
 ds = sorted(d, reverse=True, key=lambda it: splitver(it['version'][2:]))
 for x in ds:
 	if x['version'][:len(ver)] == ver:
diff --git a/_scripts/test_linux.sh b/_scripts/test_linux.sh
index 5bd251f8..846f733e 100755
--- a/_scripts/test_linux.sh
+++ b/_scripts/test_linux.sh
@@ -26,7 +26,7 @@ if [ "$version" = "gotip" ]; then
 		exit 0
 	fi
 	echo Building Go from tip
-	getgo $(curl https://golang.org/VERSION?m=text)
+	getgo $(curl https://go.dev/VERSION?m=text)
 	export GOROOT_BOOTSTRAP=$GOROOT
 	export GOROOT=/usr/local/go/go-tip
 	git clone https://go.googlesource.com/go /usr/local/go/go-tip
@@ -35,7 +35,7 @@ if [ "$version" = "gotip" ]; then
 	cd -
 else
 	echo Finding latest patch version for $version
-	version=$(curl 'https://golang.org/dl/?mode=json&include=all' | jq '.[].version' --raw-output | egrep ^$version'($|\.|beta|rc)' | sort -rV | head -1)
+	version=$(curl 'https://go.dev/dl/?mode=json&include=all' | jq '.[].version' --raw-output | egrep ^$version'($|\.|beta|rc)' | sort -rV | head -1)
 	echo "Go $version on $arch"
 	getgo $version
 fi
@@ -57,7 +57,7 @@ cd delve
 # with the current VCS revision, which does not work with TeamCity
 if [ "$version" = "gotip" ]; then
 	export GOFLAGS=-buildvcs=false
-elif [ ${version:4} -gt 17 ]; then
+elif [ ${version:4:2} -gt 17 ]; then
 	export GOFLAGS=-buildvcs=false
 fi
 
diff --git a/_scripts/test_mac.sh b/_scripts/test_mac.sh
index f4395a84..e48cbf0e 100644
--- a/_scripts/test_mac.sh
+++ b/_scripts/test_mac.sh
@@ -12,7 +12,7 @@ if [ "$GOVERSION" = "gotip" ]; then
     if [ "$arch" != "amd64" ]; then
         exit 0
     fi
-    bootstrapver=$(curl https://golang.org/VERSION?m=text)
+    bootstrapver=$(curl https://go.dev/VERSION?m=text)
     cd $TMPDIR
     curl -sSL "https://storage.googleapis.com/golang/$bootstrapver.darwin-$ARCH.tar.gz" | tar -xz
     cd -
diff --git a/service/dap/server_test.go b/service/dap/server_test.go
index cbd75b3a..24e1591c 100644
--- a/service/dap/server_test.go
+++ b/service/dap/server_test.go
@@ -3846,10 +3846,11 @@ func TestEvaluateCommandRequest(t *testing.T) {
 
 					// Request help.
 					const dlvHelp = `The following commands are available:
-    help (alias: h) 	 Prints the help message.
-    config 	 Changes configuration parameters.
+    dlv help (alias: h) 	 Prints the help message.
+    dlv config 	 Changes configuration parameters.
+    dlv sources (alias: s) 	 Print list of source files.
 
-Type help followed by a command for full documentation.
+Type 'dlv help' followed by a command for full documentation.
 `
 					client.EvaluateRequest("dlv help", 1000, "repl")
 					got := client.ExpectEvaluateResponse(t)
@@ -3909,6 +3910,25 @@ Type help followed by a command for full documentation.
 					got = client.ExpectEvaluateResponse(t)
 					checkEval(t, got, "substitutePath\t[]\n\nUpdated", noChildren)
 
+					// Test sources.
+					client.EvaluateRequest("dlv sources", 1000, "repl")
+					got = client.ExpectEvaluateResponse(t)
+					if !strings.Contains(got.Body.Result, fixture.Source) {
+						t.Errorf("\ngot: %#v, want sources contains %s", got, fixture.Source)
+					}
+
+					client.EvaluateRequest(fmt.Sprintf("dlv sources .*%s", strings.ReplaceAll(filepath.Base(fixture.Source), ".", "\\.")), 1000, "repl")
+					got = client.ExpectEvaluateResponse(t)
+					if got.Body.Result != fixture.Source {
+						t.Errorf("\ngot: %#v, want sources=%q", got, fixture.Source)
+					}
+
+					client.EvaluateRequest("dlv sources nonexistentsource", 1000, "repl")
+					got = client.ExpectEvaluateResponse(t)
+					if got.Body.Result != "" {
+						t.Errorf("\ngot: %#v, want sources=\"\"", got)
+					}
+
 					// Test bad inputs.
 					client.EvaluateRequest("dlv help bad", 1000, "repl")
 					client.ExpectErrorResponse(t)