if runtime.GOOS == "solaris" || runtime.GOOS == "illumos" {
t.Skip("skipping gdb python tests on illumos and solaris; see golang.org/issue/20821")
}
-
- cmd := exec.Command("gdb", "-nx", "-q", "--batch", "-iex", "python import sys; print('go gdb python support')")
+ args := []string{"-nx", "-q", "--batch", "-iex", "python import sys; print('go gdb python support')"}
+ gdbArgsFixup(args)
+ cmd := exec.Command("gdb", args...)
out, err := cmd.CombinedOutput()
if err != nil {
return 0
}
+func gdbArgsFixup(args []string) {
+ if runtime.GOOS != "windows" {
+ return
+ }
+ // On Windows, some gdb flavors expect -ex and -iex arguments
+ // containing spaces to be double quoted.
+ var quote bool
+ for i, arg := range args {
+ if arg == "-iex" || arg == "-ex" {
+ quote = true
+ } else if quote {
+ if strings.ContainsRune(arg, ' ') {
+ args[i] = `"` + arg + `"`
+ }
+ quote = false
+ }
+ }
+}
+
func TestGdbPython(t *testing.T) {
testGdbPython(t, false)
}
"-ex", "echo END\n",
filepath.Join(dir, "a.exe"),
)
+ gdbArgsFixup(args)
got, err := exec.Command("gdb", args...).CombinedOutput()
t.Logf("gdb output:\n%s", got)
if err != nil {
"-ex", "continue",
filepath.Join(dir, "a.exe"),
}
+ gdbArgsFixup(args)
cmd = testenv.Command(t, "gdb", args...)
// Work around the GDB hang reported in https://go.dev/issue/37405.
"-ex", "info types astruct",
filepath.Join(dir, "a.exe"),
}
+ gdbArgsFixup(args)
got, err := exec.Command("gdb", args...).CombinedOutput()
t.Logf("gdb output:\n%s", got)
if err != nil {
"-ex", "print 'runtime._PageSize'",
filepath.Join(dir, "a.exe"),
}
+ gdbArgsFixup(args)
got, err := exec.Command("gdb", args...).CombinedOutput()
t.Logf("gdb output:\n%s", got)
if err != nil {
"-ex", "backtrace",
filepath.Join(dir, "a.exe"),
}
+ gdbArgsFixup(args)
got, err := exec.Command("gdb", args...).CombinedOutput()
t.Logf("gdb output:\n%s", got)
if err != nil {
"-ex", "continue",
filepath.Join(dir, "a.exe"),
}
+ gdbArgsFixup(args)
got, err := exec.Command("gdb", args...).CombinedOutput()
t.Logf("gdb output:\n%s", got)
if err != nil {