dwtest: fixes for DWARF5 support

Fix the var location test harness to allow for subprogram DIE high_pc
attrs that are offsets from low_pc as opposed to addresses themselves
(this is what the Go compiler will be doing when it generates
DWARF5). Also add "-trimpath" to a number of the builds to make it
easier to diff good/bad DWARF.

Updates golang/go#26379.

Change-Id: I708e14e5bb60ba4ebd668e616c4ca37f8d998efc
Reviewed-on: https://go-review.googlesource.com/c/debug/+/636518
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/dwtest/dwloc_test.go b/dwtest/dwloc_test.go
index a0b7dca..1c046cb 100644
--- a/dwtest/dwloc_test.go
+++ b/dwtest/dwloc_test.go
@@ -86,14 +86,14 @@
 
 	// Run builds.
 	harnessPath := filepath.Join(dir, "dumpdwloc.exe")
-	cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", harnessPath)
+	cmd := exec.Command(testenv.GoToolPath(t), "build", "-trimpath", "-o", harnessPath)
 	cmd.Dir = bd
 	if b, err := cmd.CombinedOutput(); err != nil {
 		t.Fatalf("build failed (%v): %s", err, b)
 	}
 
 	nooptHarnessPath := filepath.Join(dir, "dumpdwloc.exe")
-	cmd = exec.Command(testenv.GoToolPath(t), "build", "-gcflags=all=-l -N", "-o", nooptHarnessPath)
+	cmd = exec.Command(testenv.GoToolPath(t), "build", "-trimpath", "-gcflags=all=-l -N", "-o", nooptHarnessPath)
 	cmd.Dir = bd
 	if b, err := cmd.CombinedOutput(); err != nil {
 		t.Fatalf("build failed (%v): %s", err, b)
@@ -129,7 +129,7 @@
 	// A note on this build: Delve currently has problems digesting
 	// PIE binaries on Windows; until this can be straightened out,
 	// default to "exe" buildmode.
-	cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=exe", "-o", epath, spath)
+	cmd := exec.Command(testenv.GoToolPath(t), "build", "-trimpath", "-buildmode=exe", "-o", epath, spath)
 	if b, err := cmd.CombinedOutput(); err != nil {
 		t.Logf("%% build output: %s\n", b)
 		t.Fatalf("build failed: %s", err)
diff --git a/dwtest/testdata/dwdumploc.go b/dwtest/testdata/dwdumploc.go
index 60bca95..287a25d 100644
--- a/dwtest/testdata/dwdumploc.go
+++ b/dwtest/testdata/dwdumploc.go
@@ -241,16 +241,17 @@
 
 		verb(1, "found function %s at offset %x", fcn, off)
 		rrv.dwOffset = off
-		if lopc, ok := die.Val(dwarf.AttrLowpc).(uint64); ok {
-			rrv.dwLoPC = lopc
-		} else {
-			return finfo{}, fmt.Errorf("target function seems to be missing LowPC attribute")
+
+		// Collect the start/end PC for the func. The format/class of
+		// the high PC attr may vary depending on which DWARF version
+		// we're generating; invoke a helper to handle the various
+		// possibilities.
+		lowpc, highpc, perr := dwtest.SubprogLoAndHighPc(die)
+		if perr != nil {
+			return finfo{}, fmt.Errorf("sibprog die malformed: %v", perr)
 		}
-		if hipc, ok := die.Val(dwarf.AttrHighpc).(uint64); ok {
-			rrv.dwHiPC = hipc
-		} else {
-			return finfo{}, fmt.Errorf("target function seems to be missing HighPC attribute")
-		}
+		rrv.dwLoPC = lowpc
+		rrv.dwHiPC = highpc
 		rrv.dwx = &dwx
 		rrv.name = fcn
 		rrv.valid = true