mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
sys: Fix DumpStack to return the correct part of the buffer.
This commit is contained in:
parent
1a1c2e017a
commit
00ed6923f7
|
@ -2,10 +2,15 @@ package sys
|
|||
|
||||
import "runtime"
|
||||
|
||||
const dumpStackBufSizeInit = 4096
|
||||
|
||||
func DumpStack() string {
|
||||
buf := make([]byte, 1024)
|
||||
for runtime.Stack(buf, true) == cap(buf) {
|
||||
buf := make([]byte, dumpStackBufSizeInit)
|
||||
for {
|
||||
n := runtime.Stack(buf, true)
|
||||
if n < cap(buf) {
|
||||
return string(buf[:n])
|
||||
}
|
||||
buf = make([]byte, cap(buf)*2)
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user