]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: quote -ex and -iex gdb arguments on Windows
authorqmuntal <quimmuntal@gmail.com>
Tue, 10 Oct 2023 12:58:37 +0000 (14:58 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 10 Oct 2023 18:22:05 +0000 (18:22 +0000)
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>

src/runtime/runtime-gdb_test.go

index ced71ca4767d0f9d070ed15ddbdd985fbc4a3377..1ae6ff041a90f4c65400a31774f197f372f62280 100644 (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 {