aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime-gdb_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/runtime-gdb_test.go')
-rw-r--r--src/runtime/runtime-gdb_test.go97
1 files changed, 81 insertions, 16 deletions
diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go
index 1318babdea..5e0508631f 100644
--- a/src/runtime/runtime-gdb_test.go
+++ b/src/runtime/runtime-gdb_test.go
@@ -22,11 +22,15 @@ import (
func checkGdbEnvironment(t *testing.T) {
testenv.MustHaveGoBuild(t)
- if runtime.GOOS == "darwin" {
+ switch runtime.GOOS {
+ case "darwin":
t.Skip("gdb does not work on darwin")
- }
- if runtime.GOOS == "linux" && runtime.GOARCH == "ppc64" {
- t.Skip("skipping gdb tests on linux/ppc64; see golang.org/issue/17366")
+ case "netbsd":
+ t.Skip("gdb does not work with threads on NetBSD; see golang.org/issue/22893 and gnats.netbsd.org/52548")
+ case "linux":
+ if runtime.GOARCH == "ppc64" {
+ t.Skip("skipping gdb tests on linux/ppc64; see golang.org/issue/17366")
+ }
}
if final := os.Getenv("GOROOT_FINAL"); final != "" && runtime.GOROOT() != final {
t.Skip("gdb test can fail with GOROOT_FINAL pending")
@@ -76,7 +80,7 @@ import "fmt"
import "runtime"
var gslice []string
func main() {
- mapvar := make(map[string]string,5)
+ mapvar := make(map[string]string, 13)
mapvar["abc"] = "def"
mapvar["ghi"] = "jkl"
strvar := "abc"
@@ -84,7 +88,7 @@ func main() {
slicevar := make([]string, 0, 16)
slicevar = append(slicevar, mapvar["abc"])
fmt.Println("hi") // line 13
- _ = ptrvar
+ runtime.KeepAlive(ptrvar)
gslice = slicevar
runtime.KeepAlive(mapvar)
}
@@ -106,8 +110,8 @@ func testGdbPython(t *testing.T, cgo bool) {
t.Skip("skipping because cgo is not enabled")
}
- t.Parallel()
checkGdbEnvironment(t)
+ t.Parallel()
checkGdbVersion(t)
checkGdbPython(t)
@@ -132,7 +136,7 @@ func testGdbPython(t *testing.T, cgo bool) {
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe")
cmd.Dir = dir
- out, err := testEnv(cmd).CombinedOutput()
+ out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
if err != nil {
t.Fatalf("building source %v\n%s", err, out)
}
@@ -198,8 +202,10 @@ func testGdbPython(t *testing.T, cgo bool) {
t.Fatalf("info goroutines failed: %s", bl)
}
- printMapvarRe := regexp.MustCompile(`\Q = map[string]string = {["abc"] = "def", ["ghi"] = "jkl"}\E$`)
- if bl := blocks["print mapvar"]; !printMapvarRe.MatchString(bl) {
+ printMapvarRe1 := regexp.MustCompile(`\Q = map[string]string = {["abc"] = "def", ["ghi"] = "jkl"}\E$`)
+ printMapvarRe2 := regexp.MustCompile(`\Q = map[string]string = {["ghi"] = "jkl", ["abc"] = "def"}\E$`)
+ if bl := blocks["print mapvar"]; !printMapvarRe1.MatchString(bl) &&
+ !printMapvarRe2.MatchString(bl) {
t.Fatalf("print mapvar failed: %s", bl)
}
@@ -212,7 +218,7 @@ func testGdbPython(t *testing.T, cgo bool) {
// a collection of scalar vars holding the fields. In such cases
// the DWARF variable location expression should be of the
// form "var.field" and not just "field".
- infoLocalsRe := regexp.MustCompile(`^slicevar.len = `)
+ infoLocalsRe := regexp.MustCompile(`.*\sslicevar.cap = `)
if bl := blocks["info locals"]; !infoLocalsRe.MatchString(bl) {
t.Fatalf("info locals failed: %s", bl)
}
@@ -260,8 +266,8 @@ func TestGdbBacktrace(t *testing.T) {
testenv.SkipFlaky(t, 15603)
}
- t.Parallel()
checkGdbEnvironment(t)
+ t.Parallel()
checkGdbVersion(t)
dir, err := ioutil.TempDir("", "go-build")
@@ -278,7 +284,7 @@ func TestGdbBacktrace(t *testing.T) {
}
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe")
cmd.Dir = dir
- out, err := testEnv(cmd).CombinedOutput()
+ out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
if err != nil {
t.Fatalf("building source %v\n%s", err, out)
}
@@ -330,8 +336,8 @@ func main() {
// TestGdbAutotmpTypes ensures that types of autotmp variables appear in .debug_info
// See bug #17830.
func TestGdbAutotmpTypes(t *testing.T) {
- t.Parallel()
checkGdbEnvironment(t)
+ t.Parallel()
checkGdbVersion(t)
dir, err := ioutil.TempDir("", "go-build")
@@ -346,9 +352,9 @@ func TestGdbAutotmpTypes(t *testing.T) {
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 := exec.Command(testenv.GoToolPath(t), "build", "-gcflags=all=-N -l", "-o", "a.exe")
cmd.Dir = dir
- out, err := testEnv(cmd).CombinedOutput()
+ out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
if err != nil {
t.Fatalf("building source %v\n%s", err, out)
}
@@ -381,3 +387,62 @@ 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) {
+ checkGdbEnvironment(t)
+ t.Parallel()
+ 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=all=-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'",
+ "-ex", "print 'runtime._PageSize'",
+ filepath.Join(dir, "a.exe"),
+ }
+ got, _ := exec.Command("gdb", args...).CombinedOutput()
+
+ sgot := strings.Replace(string(got), "\r\n", "\n", -1)
+
+ t.Logf("output %q", sgot)
+
+ if !strings.Contains(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'\n$5 = 8192") {
+ t.Fatalf("output mismatch")
+ }
+}