1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:00:03 -07:00

runtime: quote -ex and -iex gdb arguments on Windows

On Windows, some gdb flavors expect -ex and -iex arguments containing
spaces to be double quoted.

Change-Id: I2891e115f98c1df3a7a481bd9f9d9215bfbecd44
Reviewed-on: https://go-review.googlesource.com/c/go/+/534097
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
This commit is contained in:
qmuntal 2023-10-10 14:58:37 +02:00 committed by Quim Muntal
parent 7e1713e93c
commit e7015c9327

View File

@ -85,8 +85,9 @@ func checkGdbPython(t *testing.T) {
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 {
@ -156,6 +157,25 @@ func lastLine(src []byte) int {
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)
}
@ -269,6 +289,7 @@ func testGdbPython(t *testing.T, cgo bool) {
"-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 {
@ -443,6 +464,7 @@ func TestGdbBacktrace(t *testing.T) {
"-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.
@ -563,6 +585,7 @@ func TestGdbAutotmpTypes(t *testing.T) {
"-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 {
@ -631,6 +654,7 @@ func TestGdbConst(t *testing.T) {
"-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 {
@ -693,6 +717,7 @@ func TestGdbPanic(t *testing.T) {
"-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 {
@ -771,6 +796,7 @@ func TestGdbInfCallstack(t *testing.T) {
"-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 {