gf/errors/gerror/gerror_stack.go

31 lines
758 B
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2019-06-30 12:54:06 +08:00
package gerror
import "runtime"
// stack represents a stack of program counters.
type stack []uintptr
const (
2020-12-11 01:08:15 +08:00
// maxStackDepth marks the max stack depth for error back traces.
maxStackDepth = 32
)
// callers returns the stack callers.
2020-12-11 01:08:15 +08:00
// Note that it here just retrieves the caller memory address array not the caller information.
func callers(skip ...int) stack {
var (
pcs [maxStackDepth]uintptr
n = 3
)
if len(skip) > 0 {
n += skip[0]
}
return pcs[:runtime.Callers(n, pcs[:])]
2019-06-30 12:54:06 +08:00
}