Files
sing-box-extended-mirror/experimental/libbox/debug.go
T

29 lines
471 B
Go
Raw Normal View History

2026-04-02 16:39:34 +08:00
package libbox
2026-04-09 19:34:27 +08:00
import (
"runtime"
2026-04-09 19:34:27 +08:00
"time"
"unsafe"
)
2026-04-02 16:39:34 +08:00
func TriggerGoPanic() {
time.AfterFunc(200*time.Millisecond, func() {
2026-04-09 19:34:27 +08:00
*(*int)(unsafe.Pointer(uintptr(0))) = 0
2026-04-02 16:39:34 +08:00
})
}
func TriggerGoHang(seconds int32) {
time.Sleep(time.Duration(seconds) * time.Second)
}
func GoroutineDump() string {
buffer := make([]byte, 64*1024)
for {
n := runtime.Stack(buffer, true)
if n < len(buffer) {
return string(buffer[:n])
}
buffer = make([]byte, 2*len(buffer))
}
}