]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: consider core PID in gdb test
authorIan Lance Taylor <iant@golang.org>
Fri, 21 Jul 2023 18:14:41 +0000 (11:14 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 21 Jul 2023 18:42:36 +0000 (18:42 +0000)
Add the PID to the core file name if the current system uses it
when generating core files.

Fixes #61487

Change-Id: I3b53a6c850c754795c8022921160f03c588d4c91
Reviewed-on: https://go-review.googlesource.com/c/go/+/511659
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>

src/runtime/runtime-gdb_unix_test.go

index f9cc64803e8a91e5a0e9e0e9d21bbfe287669dc9..5413306f772da3a8363dd47de2ccda9d7d76dd3b 100644 (file)
@@ -8,6 +8,7 @@ package runtime_test
 
 import (
        "bytes"
+       "fmt"
        "internal/testenv"
        "io"
        "os"
@@ -102,6 +103,18 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
                t.Skipf("Unexpected core pattern %q", string(b))
        }
 
+       coreUsesPID := false
+       b, err = os.ReadFile("/proc/sys/kernel/core_uses_pid")
+       if err == nil {
+               switch string(bytes.TrimSpace(b)) {
+               case "0":
+               case "1":
+                       coreUsesPID = true
+               default:
+                       t.Skipf("unexpected core_uses_pid value %q", string(b))
+               }
+       }
+
        dir := t.TempDir()
 
        // Build the source code.
@@ -136,6 +149,8 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
        }
        w.Close()
 
+       pid := cmd.Process.Pid
+
        // Wait for child to be ready.
        var buf [1]byte
        if _, err := r.Read(buf[:]); err != io.EOF {
@@ -167,12 +182,17 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
                t.Fatalf("CoreDump got %v want true", ws.CoreDump())
        }
 
+       coreFile := "core"
+       if coreUsesPID {
+               coreFile += fmt.Sprintf(".%d", pid)
+       }
+
        // Execute gdb commands.
        args := []string{"-nx", "-batch",
                "-iex", "add-auto-load-safe-path " + filepath.Join(testenv.GOROOT(t), "src", "runtime"),
                "-ex", "backtrace",
                filepath.Join(dir, "a.exe"),
-               filepath.Join(dir, "core"),
+               filepath.Join(dir, coreFile),
        }
        cmd = testenv.Command(t, "gdb", args...)