@@ -8,6 +8,7 @@ package runtime_test
8
8
9
9
import (
10
10
"bytes"
11
+ "fmt"
11
12
"internal/testenv"
12
13
"io"
13
14
"os"
@@ -102,6 +103,18 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
102
103
t .Skipf ("Unexpected core pattern %q" , string (b ))
103
104
}
104
105
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
+
105
118
dir := t .TempDir ()
106
119
107
120
// Build the source code.
@@ -136,6 +149,8 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
136
149
}
137
150
w .Close ()
138
151
152
+ pid := cmd .Process .Pid
153
+
139
154
// Wait for child to be ready.
140
155
var buf [1 ]byte
141
156
if _ , err := r .Read (buf [:]); err != io .EOF {
@@ -167,12 +182,17 @@ func TestGdbCoreSignalBacktrace(t *testing.T) {
167
182
t .Fatalf ("CoreDump got %v want true" , ws .CoreDump ())
168
183
}
169
184
185
+ coreFile := "core"
186
+ if coreUsesPID {
187
+ coreFile += fmt .Sprintf (".%d" , pid )
188
+ }
189
+
170
190
// Execute gdb commands.
171
191
args := []string {"-nx" , "-batch" ,
172
192
"-iex" , "add-auto-load-safe-path " + filepath .Join (testenv .GOROOT (t ), "src" , "runtime" ),
173
193
"-ex" , "backtrace" ,
174
194
filepath .Join (dir , "a.exe" ),
175
- filepath .Join (dir , "core" ),
195
+ filepath .Join (dir , coreFile ),
176
196
}
177
197
cmd = testenv .Command (t , "gdb" , args ... )
178
198
0 commit comments