diff --git a/src/runtime/runtime-gdb_unix_test.go b/src/runtime/runtime-gdb_unix_test.go index a1f2401a6e4423..4a64114df790f6 100644 --- a/src/runtime/runtime-gdb_unix_test.go +++ b/src/runtime/runtime-gdb_unix_test.go @@ -18,6 +18,7 @@ import ( "runtime" "syscall" "testing" + _ "unsafe" // for go:linkname ) func canGenerateCore(t *testing.T) bool { @@ -282,6 +283,9 @@ func main() { } ` +//go:linkname totalSleepTimeUs runtime.totalSleepTimeUs +var totalSleepTimeUs int + // TestGdbCoreCrashThreadBacktrace tests that runtime could let the fault thread to crash process // and make fault thread as number one thread while gdb in a core file func TestGdbCoreCrashThreadBacktrace(t *testing.T) { @@ -303,6 +307,7 @@ func TestGdbCoreCrashThreadBacktrace(t *testing.T) { coreUsesPID := canGenerateCore(t) + totalSleepTimeUs = 60 * 1000 * 1000 // Build the source code. dir := t.TempDir() src := filepath.Join(dir, "main.go") diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 84391d58ed7f22..9fb7a7a279b629 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -599,6 +599,9 @@ func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool { // GOTRACEBACK=crash when a signal is received. var crashing atomic.Int32 +// declared as global for dynamic change in TestGdbCoreCrashThreadBacktrace, see issue 64752. +var totalSleepTimeUs = 5 * 1000 * 1000 + // testSigtrap and testSigusr1 are used by the runtime tests. If // non-nil, it is called on SIGTRAP/SIGUSR1. If it returns true, the // normal behavior on this signal is suppressed. @@ -775,13 +778,14 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) { raiseproc(_SIGQUIT) } if isCrashThread { - i := 0 - for (crashing.Load() < mcount()-int32(extraMLength.Load())) && i < 10 { - i++ - usleep(500 * 1000) + perLoopSleepTimeUs := 5000 + i := totalSleepTimeUs / perLoopSleepTimeUs + for (crashing.Load() < mcount()-int32(extraMLength.Load())) && i > 0 { + i-- + usleep(uint32(perLoopSleepTimeUs)) } } else { - usleep(5 * 1000 * 1000) + usleep(uint32(totalSleepTimeUs)) } printDebugLog() crash()