t.Fatalf("building source %v\n%s", err, out)
}
- got, _ := exec.Command("gdb", "-nx", "-q", "--batch", "-iex",
+ args := []string{"-nx", "-q", "--batch", "-iex",
fmt.Sprintf("add-auto-load-safe-path %s/src/runtime", runtime.GOROOT()),
"-ex", "br main.go:10",
"-ex", "run",
"-ex", "echo END\n",
"-ex", "echo BEGIN print ptrvar\n",
"-ex", "print ptrvar",
- "-ex", "echo END\n",
- "-ex", "echo BEGIN goroutine 2 bt\n",
- "-ex", "goroutine 2 bt",
- "-ex", "echo END\n",
- filepath.Join(dir, "a.exe")).CombinedOutput()
+ "-ex", "echo END\n"}
+
+ // without framepointer, gdb cannot backtrace our non-standard
+ // stack frames on RISC architectures.
+ canBackTrace := false
+ switch runtime.GOARCH {
+ case "amd64", "386":
+ canBackTrace = true
+ args = append(args,
+ "-ex", "echo BEGIN goroutine 2 bt\n",
+ "-ex", "goroutine 2 bt",
+ "-ex", "echo END\n")
+ }
+
+ args = append(args, filepath.Join(dir, "a.exe"))
+ got, _ := exec.Command("gdb", args...).CombinedOutput()
firstLine := bytes.SplitN(got, []byte("\n"), 2)[0]
if string(firstLine) != "Loading Go Runtime support." {
}
btGoroutineRe := regexp.MustCompile(`^#0\s+runtime.+at`)
- if bl := blocks["goroutine 2 bt"]; !btGoroutineRe.MatchString(bl) {
+ if bl := blocks["goroutine 2 bt"]; canBackTrace && !btGoroutineRe.MatchString(bl) {
t.Fatalf("goroutine 2 bt failed: %s", bl)
+ } else if !canBackTrace {
+ t.Logf("gdb cannot backtrace for GOARCH=%s, skipped goroutine backtrace test", runtime.GOARCH)
}
}