2019-06-30 22:21:08 +08:00
|
|
|
// Copyright 2019 gf Author(https://github.com/gogf/gf). 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
|
|
|
|
|
|
2019-06-30 22:21:08 +08:00
|
|
|
const (
|
|
|
|
|
gMAX_STACK_DEPTH = 32
|
|
|
|
|
)
|
|
|
|
|
|
2020-04-28 15:04:07 +08:00
|
|
|
// callers returns the stack callers.
|
|
|
|
|
func callers(skip ...int) stack {
|
|
|
|
|
var (
|
|
|
|
|
pcs [gMAX_STACK_DEPTH]uintptr
|
|
|
|
|
n = 3
|
|
|
|
|
)
|
|
|
|
|
if len(skip) > 0 {
|
|
|
|
|
n += skip[0]
|
|
|
|
|
}
|
|
|
|
|
return pcs[:runtime.Callers(n, pcs[:])]
|
2019-06-30 12:54:06 +08:00
|
|
|
}
|