cmd/compile: enable scopes unconditionally

This revives Alessandro Arzilli's CL to enable scopes
whenever any dwarf is emitted (with optimization or not),
adds a test that detects this changes and shows that it
creates more truthful debugging output.

Reverted change to ssa/debug_test tests made when
scopes were disabled during dwarflocationlist development.

Also included are updates to the Delve test output (it
had fallen out of sync; creating test output for one
updates it for all) and minor naming changes in
ssa/debug_test.

Compile-time/space changes (relative to tip including dwarflocationlists):

benchstat -geomean after.log scopes.log
name        old time/op     new time/op     delta
Template        182ms ± 1%      182ms ± 1%    ~     (p=0.666 n=9+9)
Unicode        82.8ms ± 1%     86.6ms ±14%    ~     (p=0.211 n=9+10)
GoTypes         611ms ± 1%      616ms ± 2%  +0.97%  (p=0.001 n=10+9)
Compiler        2.95s ± 1%      2.95s ± 0%    ~     (p=0.573 n=10+8)
SSA             6.70s ± 1%      6.81s ± 1%  +1.68%  (p=0.000 n=9+10)
Flate           117ms ± 1%      118ms ± 1%  +0.60%  (p=0.036 n=9+8)
GoParser        145ms ± 1%      145ms ± 1%    ~     (p=1.000 n=9+9)
Reflect         398ms ± 1%      396ms ± 1%    ~     (p=0.053 n=9+10)
Tar             171ms ± 1%      171ms ± 1%    ~     (p=0.356 n=9+10)
XML             214ms ± 1%      214ms ± 1%    ~     (p=0.605 n=9+9)
StdCmd          12.4s ± 2%      12.4s ± 1%    ~     (p=1.000 n=9+9)
[Geo mean]      506ms           509ms       +0.71%

name        old user-ns/op  new user-ns/op  delta
Template         254M ± 4%       249M ± 6%    ~     (p=0.155 n=10+10)
Unicode          121M ±11%       124M ± 6%    ~     (p=0.516 n=10+10)
GoTypes          824M ± 2%       869M ± 5%  +5.49%  (p=0.001 n=8+10)
Compiler        4.01G ± 2%      4.02G ± 1%    ~     (p=0.561 n=9+9)
SSA             10.0G ± 2%      10.2G ± 2%  +2.29%  (p=0.000 n=9+10)
Flate            154M ± 7%       154M ± 7%    ~     (p=0.960 n=10+9)
GoParser         190M ± 7%       196M ± 6%    ~     (p=0.064 n=9+10)
Reflect          528M ± 2%       517M ± 3%  -1.97%  (p=0.025 n=10+10)
Tar              227M ± 5%       232M ± 3%    ~     (p=0.061 n=9+10)
XML              286M ± 4%       283M ± 4%    ~     (p=0.343 n=9+9)
[Geo mean]       502M            508M       +1.09%

name        old text-bytes  new text-bytes  delta
HelloSize        672k ± 0%       672k ± 0%  +0.01%  (p=0.000 n=10+10)
CmdGoSize       7.21M ± 0%      7.21M ± 0%  -0.00%  (p=0.000 n=10+10)
[Geo mean]      2.20M           2.20M       +0.00%

name        old data-bytes  new data-bytes  delta
HelloSize       9.88k ± 0%      9.88k ± 0%    ~     (all equal)
CmdGoSize        248k ± 0%       248k ± 0%    ~     (all equal)
[Geo mean]      49.5k           49.5k       +0.00%

name        old bss-bytes   new bss-bytes   delta
HelloSize        125k ± 0%       125k ± 0%    ~     (all equal)
CmdGoSize        144k ± 0%       144k ± 0%  -0.04%  (p=0.000 n=10+10)
[Geo mean]       135k            135k       -0.02%

name        old exe-bytes   new exe-bytes   delta
HelloSize       1.30M ± 0%      1.34M ± 0%  +3.15%  (p=0.000 n=10+10)
CmdGoSize       13.5M ± 0%      13.9M ± 0%  +2.70%  (p=0.000 n=10+10)
[Geo mean]      4.19M           4.31M       +2.92%

Change-Id: Id53b8d57bd00440142ccbd39b95710e14e083fb5
Reviewed-on: https://go-review.googlesource.com/101217
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index 2fa7ef8..d0e85c9 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -405,7 +405,7 @@
 		Debug['l'] = 1 - Debug['l']
 	}
 
-	trackScopes = flagDWARF && (Debug['l'] == 0 && Debug['N'] != 0)
+	trackScopes = flagDWARF
 
 	Widthptr = thearch.LinkArch.PtrSize
 	Widthreg = thearch.LinkArch.RegSize
diff --git a/src/cmd/compile/internal/ssa/debug_test.go b/src/cmd/compile/internal/ssa/debug_test.go
index b066816..ff9f175 100644
--- a/src/cmd/compile/internal/ssa/debug_test.go
+++ b/src/cmd/compile/internal/ssa/debug_test.go
@@ -136,22 +136,27 @@
 	}
 
 	optFlags := "" // Whatever flags are needed to test debugging of optimized code.
+	dbgFlags := "-N -l"
 	if !*useDelve && !*inlines {
 		// For gdb (default), disable inlining so that a compiler test does not depend on library code.
 		// TODO: Technically not necessary in 1.10, but it causes a largish regression that needs investigation.
 		optFlags += " -l"
 	}
 
-	subTest(t, debugger+"-dbg", "hist", "-N -l")
-	subTest(t, debugger+"-dbg-race", "i22600", "-N -l", "-race")
-	subTest(t, debugger+"-dbg-22558", "i22558", "-N -l")
+	subTest(t, debugger+"-dbg", "hist", dbgFlags)
+	subTest(t, debugger+"-dbg", "scopes", dbgFlags)
+	subTest(t, debugger+"-dbg", "i22558", dbgFlags)
+
+	subTest(t, debugger+"-dbg-race", "i22600", dbgFlags, "-race")
+
 	optSubTest(t, debugger+"-opt", "hist", optFlags)
+	optSubTest(t, debugger+"-opt", "scopes", optFlags)
 }
 
 // subTest creates a subtest that compiles basename.go with the specified gcflags and additional compiler arguments,
 // then runs the debugger on the resulting binary, with any comment-specified actions matching tag triggered.
 func subTest(t *testing.T, tag string, basename string, gcflags string, moreargs ...string) {
-	t.Run(tag, func(t *testing.T) {
+	t.Run(tag+"-"+basename, func(t *testing.T) {
 		testNexting(t, basename, tag, gcflags, moreargs...)
 	})
 }
@@ -161,7 +166,7 @@
 func optSubTest(t *testing.T, tag string, basename string, gcflags string, moreargs ...string) {
 	// If optimized test is run with unoptimized libraries (compiled with -N -l), it is very likely to fail.
 	// This occurs in the noopt builders (for example).
-	t.Run(tag, func(t *testing.T) {
+	t.Run(tag+"-"+basename, func(t *testing.T) {
 		if *force || optimizedLibs {
 			testNexting(t, basename, tag, gcflags, moreargs...)
 		} else {
diff --git a/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts
index b98e3c6..a7bcbb1 100644
--- a/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts
+++ b/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts
@@ -57,7 +57,25 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 86:		for i, a := range hist {
 87:			if a == 0 { //gdb-opt=(a,n,t)
-88:				continue
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+91:			n += a
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+90:			t += i * a
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+90:			t += i * a
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+86:		for i, a := range hist {
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+87:			if a == 0 { //gdb-opt=(a,n,t)
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+91:			n += a
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+90:			t += i * a
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+90:			t += i * a
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
+86:		for i, a := range hist {
+92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
 87:			if a == 0 { //gdb-opt=(a,n,t)
 92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
 91:			n += a
@@ -79,27 +97,4 @@
 86:		for i, a := range hist {
 92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
 87:			if a == 0 { //gdb-opt=(a,n,t)
-88:				continue
-87:			if a == 0 { //gdb-opt=(a,n,t)
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-91:			n += a
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-90:			t += i * a
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-90:			t += i * a
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-86:		for i, a := range hist {
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-87:			if a == 0 { //gdb-opt=(a,n,t)
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-91:			n += a
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-90:			t += i * a
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-90:			t += i * a
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-86:		for i, a := range hist {
-92:			fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t)
-87:			if a == 0 { //gdb-opt=(a,n,t)
-88:				continue
 98:	}
diff --git a/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts b/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts
index 91b4f2d..fe00014 100644
--- a/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts
+++ b/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts
@@ -14,64 +14,64 @@
 73:		scanner := bufio.NewScanner(reader)
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 1
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 1
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 1
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 2
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 2
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 2
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 4
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 4
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
 i = 5
 81:			hist = ensure(int(i), hist)
 82:			hist[int(i)]++
diff --git a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts
index d943eb1..79c65a9 100644
--- a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts
+++ b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts
@@ -22,9 +22,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 0, 0, 0, 0, 0, 0}
 i = 1
 81:			hist = ensure(int(i), hist)
@@ -32,9 +32,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 1, 0, 0, 0, 0, 0}
 i = 1
 81:			hist = ensure(int(i), hist)
@@ -42,9 +42,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 2, 0, 0, 0, 0, 0}
 i = 1
 81:			hist = ensure(int(i), hist)
@@ -52,9 +52,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 3, 0, 0, 0, 0, 0}
 i = 2
 81:			hist = ensure(int(i), hist)
@@ -62,9 +62,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 3, 1, 0, 0, 0, 0}
 i = 2
 81:			hist = ensure(int(i), hist)
@@ -72,9 +72,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 3, 2, 0, 0, 0, 0}
 i = 2
 81:			hist = ensure(int(i), hist)
@@ -82,9 +82,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 3, 3, 0, 0, 0, 0}
 i = 4
 81:			hist = ensure(int(i), hist)
@@ -92,9 +92,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 3, 3, 0, 1, 0, 0}
 i = 4
 81:			hist = ensure(int(i), hist)
@@ -102,9 +102,9 @@
 74:		for scanner.Scan() { //gdb-opt=(scanner/A)
 scanner = (struct bufio.Scanner *) <A>
 75:			s := scanner.Text()
-76:			i, err2 := strconv.ParseInt(s, 10, 64)
-77:			if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-err2 = {tab = 0x0, data = 0x0}
+76:			i, err := strconv.ParseInt(s, 10, 64)
+77:			if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+err = {tab = 0x0, data = 0x0}
 hist =  []int = {0, 3, 3, 0, 2, 0, 0}
 i = 5
 81:			hist = ensure(int(i), hist)
diff --git a/src/cmd/compile/internal/ssa/testdata/hist.go b/src/cmd/compile/internal/ssa/testdata/hist.go
index 1462ff6..8a0cc27 100644
--- a/src/cmd/compile/internal/ssa/testdata/hist.go
+++ b/src/cmd/compile/internal/ssa/testdata/hist.go
@@ -73,9 +73,9 @@
 	scanner := bufio.NewScanner(reader)
 	for scanner.Scan() { //gdb-opt=(scanner/A)
 		s := scanner.Text()
-		i, err2 := strconv.ParseInt(s, 10, 64)
-		if err2 != nil { //gdb-dbg=(i) //gdb-opt=(err2,hist,i)
-			fmt.Fprintf(os.Stderr, "There was an error: %v\n", err2)
+		i, err := strconv.ParseInt(s, 10, 64)
+		if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
+			fmt.Fprintf(os.Stderr, "There was an error: %v\n", err)
 			return
 		}
 		hist = ensure(int(i), hist)
diff --git a/src/cmd/compile/internal/ssa/testdata/i22558.dlv-dbg-22558.nexts b/src/cmd/compile/internal/ssa/testdata/i22558.dlv-dbg.nexts
similarity index 100%
rename from src/cmd/compile/internal/ssa/testdata/i22558.dlv-dbg-22558.nexts
rename to src/cmd/compile/internal/ssa/testdata/i22558.dlv-dbg.nexts
diff --git a/src/cmd/compile/internal/ssa/testdata/i22558.gdb-dbg-22558.nexts b/src/cmd/compile/internal/ssa/testdata/i22558.gdb-dbg.nexts
similarity index 100%
rename from src/cmd/compile/internal/ssa/testdata/i22558.gdb-dbg-22558.nexts
rename to src/cmd/compile/internal/ssa/testdata/i22558.gdb-dbg.nexts
diff --git a/src/cmd/compile/internal/ssa/testdata/scopes.dlv-dbg.nexts b/src/cmd/compile/internal/ssa/testdata/scopes.dlv-dbg.nexts
new file mode 100644
index 0000000..3a49afc
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/scopes.dlv-dbg.nexts
@@ -0,0 +1,19 @@
+  ./testdata/scopes.go
+18:	func test() {
+19:		x := id(0)
+20:		y := id(0)
+21:		fmt.Println(x)
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+26:		y = x + y //gdb-dbg=(x,y)//gdb-opt=(x,y)
+27:		fmt.Println(x, y)
+28:	}
+11:	}
diff --git a/src/cmd/compile/internal/ssa/testdata/scopes.dlv-opt.nexts b/src/cmd/compile/internal/ssa/testdata/scopes.dlv-opt.nexts
new file mode 100644
index 0000000..749f1d3
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/scopes.dlv-opt.nexts
@@ -0,0 +1,27 @@
+  ./testdata/scopes.go
+18:	func test() {
+19:		x := id(0)
+20:		y := id(0)
+21:		fmt.Println(x)
+18:	func test() {
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+22:		for i := x; i < 3; i++ {
+27:		fmt.Println(x, y)
+26:		y = x + y //gdb-dbg=(x,y)//gdb-opt=(x,y)
+27:		fmt.Println(x, y)
+28:	}
+11:	}
diff --git a/src/cmd/compile/internal/ssa/testdata/scopes.gdb-dbg.nexts b/src/cmd/compile/internal/ssa/testdata/scopes.gdb-dbg.nexts
new file mode 100644
index 0000000..0304128
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/scopes.gdb-dbg.nexts
@@ -0,0 +1,27 @@
+  src/cmd/compile/internal/ssa/testdata/scopes.go
+18:	func test() {
+19:		x := id(0)
+20:		y := id(0)
+21:		fmt.Println(x)
+0:
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 0
+y = 0
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 1
+y = 0
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 4
+y = 1
+22:		for i := x; i < 3; i++ {
+26:		y = x + y //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 0
+y = 5
+27:		fmt.Println(x, y)
+0: 5
+11:	}
diff --git a/src/cmd/compile/internal/ssa/testdata/scopes.gdb-opt.nexts b/src/cmd/compile/internal/ssa/testdata/scopes.gdb-opt.nexts
new file mode 100644
index 0000000..290f02f
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/scopes.gdb-opt.nexts
@@ -0,0 +1,41 @@
+  src/cmd/compile/internal/ssa/testdata/scopes.go
+18:	func test() {
+19:		x := id(0)
+20:		y := id(0)
+21:		fmt.Println(x)
+0:
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 0
+y = 0
+22:		for i := x; i < 3; i++ {
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = <optimized out>
+y = 0
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 1
+y = 0
+22:		for i := x; i < 3; i++ {
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = <optimized out>
+y = 0
+22:		for i := x; i < 3; i++ {
+23:			x := i * i
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 4
+y = 1
+22:		for i := x; i < 3; i++ {
+24:			y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = <optimized out>
+y = 1
+22:		for i := x; i < 3; i++ {
+27:		fmt.Println(x, y)
+26:		y = x + y //gdb-dbg=(x,y)//gdb-opt=(x,y)
+x = 0
+y = 1
+27:		fmt.Println(x, y)
+0: 5
+11:	}
diff --git a/src/cmd/compile/internal/ssa/testdata/scopes.go b/src/cmd/compile/internal/ssa/testdata/scopes.go
new file mode 100644
index 0000000..9434aba
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/scopes.go
@@ -0,0 +1,28 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "fmt"
+
+func main() {
+	test()
+}
+
+//go:noinline
+func id(x int) int {
+	return x
+}
+
+func test() {
+	x := id(0)
+	y := id(0)
+	fmt.Println(x)
+	for i := x; i < 3; i++ {
+		x := i * i
+		y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y)
+	}
+	y = x + y //gdb-dbg=(x,y)//gdb-opt=(x,y)
+	fmt.Println(x, y)
+}