代码拉取完成,页面将自动刷新
package xdebug
import (
"runtime"
"strings"
)
const (
maxDepth = 1000
xDebugCaller = "/xdebug/caller.go"
)
// GetSysPathSplitSymbol 根据系统获取路径分隔符
func GetSysPathSplitSymbol() (splitSymbol string) {
if runtime.GOOS == "windows" {
splitSymbol = "\\"
} else {
splitSymbol = "/"
}
return
}
// ParseCallFile 解析调用文件
func ParseCallFile(filename string) string {
lastIndex := strings.LastIndex(filename, GetSysPathSplitSymbol())
if lastIndex == -1 {
return ""
}
return filename[lastIndex+1:]
}
// callerFromIndex 返回调用者的位置和信息
// 说明: 返回的索引值应该是 <index - 1> 作为调用者的起始点
func callerFromIndex(filters []string) (pc uintptr, file string, line int, index int) {
var filtered, ok bool
for index = 0; index < maxDepth; index++ {
pc, file, line, ok = runtime.Caller(index)
if !ok {
break
}
filtered = false
for _, filter := range filters {
if filter != "" && strings.Contains(file, filter) {
filtered = true
break
}
}
if filtered {
continue
}
if strings.HasSuffix(file, xDebugCaller) {
continue
}
return
}
return 0, "", -1, -1
}
// CallerPathWithFilter 返回函数名和绝对文件路径调用者的行号
// filter 用于过滤调用者的路径。
func CallerWithFilter(filter string, skip ...int) (function string, path string, line int) {
num := 0
if len(skip) > 0 {
num = skip[0]
}
var ok bool
pc, file, line, start := callerFromIndex([]string{filter})
if start != -1 {
for i := start + num; i < maxDepth; i++ {
if i != start {
pc, file, line, ok = runtime.Caller(i)
}
if ok {
if filter != "" && strings.Contains(file, filter) {
continue
}
function := ""
if fn := runtime.FuncForPC(pc); fn == nil {
function = "unknown"
} else {
function = fn.Name()
}
return function, file, line
} else {
break
}
}
return function, file, line
}
return "", "", -1
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。