aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime-gdb_test.go
diff options
context:
space:
mode:
authorAlessandro Arzilli <alessandro.arzilli@gmail.com>2017-09-03 11:59:18 +0200
committerAustin Clements <austin@google.com>2017-09-22 17:44:50 +0000
commit9daee931214a7ad68579f4bb2695bba561067c58 (patch)
tree07a67f3764e92a5c5e18555853a02e247620f9e0 /src/runtime/runtime-gdb_test.go
parentf366379d847274158bd14e160c85c7e2bc0f2bc1 (diff)
downloadgo-9daee931214a7ad68579f4bb2695bba561067c58.tar.gz
go-9daee931214a7ad68579f4bb2695bba561067c58.zip
cmd/compile,cmd/link: export int global consts to DWARF
Updates #14517 Change-Id: I23ef88e71c89da12dffcadf5562ea2d7557b62cf Reviewed-on: https://go-review.googlesource.com/61019 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/runtime-gdb_test.go')
-rw-r--r--src/runtime/runtime-gdb_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go
index ba13ee95da..7b035871d5 100644
--- a/src/runtime/runtime-gdb_test.go
+++ b/src/runtime/runtime-gdb_test.go
@@ -381,3 +381,61 @@ func TestGdbAutotmpTypes(t *testing.T) {
}
}
}
+
+const constsSource = `
+package main
+
+const aConstant int = 42
+const largeConstant uint64 = ^uint64(0)
+const minusOne int64 = -1
+
+func main() {
+ println("hello world")
+}
+`
+
+func TestGdbConst(t *testing.T) {
+ t.Parallel()
+ checkGdbEnvironment(t)
+ checkGdbVersion(t)
+
+ dir, err := ioutil.TempDir("", "go-build")
+ if err != nil {
+ t.Fatalf("failed to create temp directory: %v", err)
+ }
+ defer os.RemoveAll(dir)
+
+ // Build the source code.
+ src := filepath.Join(dir, "main.go")
+ err = ioutil.WriteFile(src, []byte(constsSource), 0644)
+ if err != nil {
+ t.Fatalf("failed to create file: %v", err)
+ }
+ cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags=-N -l", "-o", "a.exe")
+ cmd.Dir = dir
+ out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
+ if err != nil {
+ t.Fatalf("building source %v\n%s", err, out)
+ }
+
+ // Execute gdb commands.
+ args := []string{"-nx", "-batch",
+ "-ex", "set startup-with-shell off",
+ "-ex", "break main.main",
+ "-ex", "run",
+ "-ex", "print main.aConstant",
+ "-ex", "print main.largeConstant",
+ "-ex", "print main.minusOne",
+ "-ex", "print 'runtime._MSpanInUse'",
+ filepath.Join(dir, "a.exe"),
+ }
+ got, _ := exec.Command("gdb", args...).CombinedOutput()
+
+ sgot := string(got)
+
+ t.Logf("output %q", sgot)
+
+ if strings.Index(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'") < 0 {
+ t.Fatalf("output mismatch")
+ }
+}