callstack

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncName

func FuncName(fn *runtime.Func) string

FuncName given a runtime function spec returns a short function name in format `<package name>.<function name>` or if the function has a receiver in format `<package name>.(<receiver>).<function name>`.

func GetCallStack

func GetCallStack(frames StackTrace) string

func GoRoutineID

func GoRoutineID() uint64

GoRoutineID returns the current goroutine id.

Types

type CallStack

type CallStack []uintptr

CallStack represents a stack of program counters.

func New

func New(skip int) *CallStack

New creates a new CallStack struct from current stack minus 'skip' number of frames.

func (*CallStack) Format

func (cs *CallStack) Format(st fmt.State, verb rune)

func (*CallStack) StackTrace

func (cs *CallStack) StackTrace() StackTrace

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type FrameInfo

type FrameInfo struct {
	CallStack string
	Func      string
	File      string
	LineNo    int
}

func GetLastFrame

func GetLastFrame(frames StackTrace) FrameInfo

GetLastFrame returns Caller information on the first frame in the stack trace.

type HasStackTrace

type HasStackTrace interface {
	StackTrace() StackTrace
}

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL