2015-01-14 14:32:01 -05:00
|
|
|
package runtime_test
|
|
|
|
|
|
|
|
|
|
import (
|
2015-01-16 01:23:56 -05:00
|
|
|
"fmt"
|
2015-01-14 14:32:01 -05:00
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
2015-01-16 01:23:56 -05:00
|
|
|
"runtime"
|
2015-01-14 14:32:01 -05:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func checkGdbPython(t *testing.T) {
|
2015-01-16 01:23:56 -05:00
|
|
|
cmd := exec.Command("gdb", "-nx", "-q", "--batch", "-ex", "python import sys; print('go gdb python support')")
|
2015-01-14 14:32:01 -05:00
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
2015-01-16 01:23:56 -05:00
|
|
|
t.Skipf("skipping due to issue running gdb: %v", err)
|
2015-01-14 14:32:01 -05:00
|
|
|
}
|
2015-01-16 01:23:56 -05:00
|
|
|
if string(out) != "go gdb python support\n" {
|
2015-01-14 14:32:01 -05:00
|
|
|
t.Skipf("skipping due to lack of python gdb support: %s", out)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const helloSource = `
|
|
|
|
|
package main
|
|
|
|
|
import "fmt"
|
|
|
|
|
func main() {
|
|
|
|
|
fmt.Println("hi")
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
func TestGdbLoadRuntimeSupport(t *testing.T) {
|
|
|
|
|
checkGdbPython(t)
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "go-build")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to create temp directory: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
|
|
src := filepath.Join(dir, "main.go")
|
|
|
|
|
err = ioutil.WriteFile(src, []byte(helloSource), 0644)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to create file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("go", "build", "-o", "a.exe")
|
|
|
|
|
cmd.Dir = dir
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("building source %v\n%s", err, out)
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 01:23:56 -05:00
|
|
|
got, _ := exec.Command("gdb", "-nx", "-q", "--batch", "-iex",
|
|
|
|
|
fmt.Sprintf("add-auto-load-safe-path %s/src/runtime", runtime.GOROOT()),
|
2015-01-14 14:32:01 -05:00
|
|
|
filepath.Join(dir, "a.exe")).CombinedOutput()
|
|
|
|
|
if string(got) != "Loading Go Runtime support.\n" {
|
|
|
|
|
t.Fatalf("%s", got)
|
|
|
|
|
}
|
|
|
|
|
}
|