You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.2 KiB
109 lines
2.2 KiB
/*
|
|
---------------------------------------------------------
|
|
Project activething
|
|
Active Thing (activething.com) git.activething.com/go
|
|
|
|
File name stack_trace_frame.go
|
|
Created by DEV
|
|
Modified 23/10/2023
|
|
|
|
Copyright 2023 activething.com
|
|
---------------------------------------------------------
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
*/
|
|
|
|
package errs
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
|
|
|
|
type StackTraceFrame uintptr
|
|
|
|
|
|
|
|
|
|
func (f StackTraceFrame) PC() uintptr {
|
|
return uintptr(f) - 1 }
|
|
|
|
|
|
func (f StackTraceFrame) FileName() (fl string) {
|
|
fl, _ = f.FileLine()
|
|
return
|
|
}
|
|
|
|
|
|
func (f StackTraceFrame) FileFull() string {
|
|
return path.Base(f.FileName()) }
|
|
|
|
|
|
func (f StackTraceFrame) Line() (ln int) {
|
|
_, ln = f.FileLine()
|
|
return
|
|
}
|
|
|
|
|
|
func (f StackTraceFrame) FileLine() (string, int) {
|
|
pc := f.PC()
|
|
if fn := runtime.FuncForPC(pc); fn != nil {
|
|
return fn.FileLine(pc)
|
|
}
|
|
return traceUnknown, 0
|
|
}
|
|
|
|
|
|
func (f StackTraceFrame) FuncName() string {
|
|
return f.getFunc(true) }
|
|
|
|
|
|
func (f StackTraceFrame) FuncFull() string {
|
|
return f.getFunc(false) }
|
|
|
|
|
|
func (f StackTraceFrame) getFunc(cls bool) string {
|
|
if fn := runtime.FuncForPC(f.PC()); fn != nil {
|
|
nm := fn.Name()
|
|
if cls {
|
|
ix := strings.LastIndex(nm, "/")
|
|
nm = nm[ix+1:]
|
|
ix = strings.Index(nm, ".")
|
|
return nm[ix+1:]
|
|
}
|
|
return nm
|
|
}
|
|
return traceUnknown
|
|
}
|
|
|
|
|
|
func (f StackTraceFrame) String () string {
|
|
return fmt.Sprintf("%s:%d %s()\n", f.FileFull(), f.Line(), f.FuncName()) }
|
|
|
|
/*
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
|
|
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
|
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
|
|
|
SIDDHARTA
|
|
- HERMANN HESSE -
|
|
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
|
|
*/
|