Skip to content

Commit ffd9bd7

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 3bb51a6 commit ffd9bd7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/runtime/runtime-gdb_unix_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package runtime_test
88

99
import (
1010
"bytes"
11+
"fmt"
1112
"internal/testenv"
1213
"io"
1314
"os"
@@ -102,6 +103,18 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
102103
t.Skipf("Unexpected core pattern %q", string(b))
103104
}
104105

106+
coreUsesPID := false
107+
b, err = os.ReadFile("/proc/sys/kernel/core_uses_pid")
108+
if err == nil {
109+
switch string(bytes.TrimSpace(b)) {
110+
case "0":
111+
case "1":
112+
coreUsesPID = true
113+
default:
114+
t.Skipf("unexpected core_uses_pid value %q", string(b))
115+
}
116+
}
117+
105118
dir := t.TempDir()
106119

107120
// Build the source code.
@@ -136,6 +149,8 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
136149
}
137150
w.Close()
138151

152+
pid := cmd.Process.Pid
153+
139154
// Wait for child to be ready.
140155
var buf [1]byte
141156
if _, err := r.Read(buf[:]); err != io.EOF {
@@ -167,12 +182,17 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
167182
t.Fatalf("CoreDump got %v want true", ws.CoreDump())
168183
}
169184

185+
coreFile := "core"
186+
if coreUsesPID {
187+
coreFile += fmt.Sprintf(".%d", pid)
188+
}
189+
170190
// Execute gdb commands.
171191
args := []string{"-nx", "-batch",
172192
"-iex", "add-auto-load-safe-path " + filepath.Join(testenv.GOROOT(t), "src", "runtime"),
173193
"-ex", "backtrace",
174194
filepath.Join(dir, "a.exe"),
175-
filepath.Join(dir, "core"),
195+
filepath.Join(dir, coreFile),
176196
}
177197
cmd = testenv.Command(t, "gdb", args...)
178198

0 commit comments

Comments
 (0)