From ffd9bd7e605cdd2eb66e38bad6e0d93b0d37963c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 21 Jul 2023 11:14:41 -0700 Subject: [PATCH] runtime: consider core PID in gdb test 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 Reviewed-by: Cherry Mui Reviewed-by: Michael Pratt Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- src/runtime/runtime-gdb_unix_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/runtime/runtime-gdb_unix_test.go b/src/runtime/runtime-gdb_unix_test.go index f9cc64803e..5413306f77 100644 --- a/src/runtime/runtime-gdb_unix_test.go +++ b/src/runtime/runtime-gdb_unix_test.go @@ -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...) -- 2.50.0