Skip to content

Commit

Permalink
runtime: consider core PID in gdb test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Jul 21, 2023
1 parent 3bb51a6 commit ffd9bd7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/runtime/runtime-gdb_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package runtime_test

import (
"bytes"
"fmt"
"internal/testenv"
"io"
"os"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)

Expand Down

0 comments on commit ffd9bd7

Please sign in to comment.