trap

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const SKIP = 2

skip 2: <user func> -> runtime.XgoTrap -> trap

Variables

View Source
var ErrMocked = errors.New("func mocked by xgo")

ErrMocked indicates the target function is mocked

View Source
var ErrNotInstrumented = errors.New("not instrumented by xgo, see https://github.com/xhd2015/xgo/tree/master/doc/ERR_NOT_INSTRUMENTED.md")

ErrNotInstrumented is the error returned when a function or variable is not instrumented by xgo. when this error happened, user should check if `--trap` was correctly passed to the xgo compiler for variable, only variables within main module are available, and the variable should be declared with type specified:

var SomeVar int = 10 // good
var SomeVar = 10 // bad: xgo cannot generate trap function for untyped variables

and when used as method receiver, should wrap the variable in type conversion:

MyInt(SomeVar).String() // good
SomeVar.String() // bad: xgo cannot determine if it is a pointer receiver

check https://github.com/xhd2015/xgo/tree/master/doc/ERR_NOT_INSTRUMENTED.md for more details

Functions

func Inspect

func Inspect(f interface{}) (recvPtr interface{}, funcInfo *core.FuncInfo, funcPC uintptr, trappingPC uintptr)

Inspect inspects the function and returns the receiver pointer, function PC and trapping PC. for ordinary function, `funcPC` is the same with `trappingPC` for method,`funcPC` and `trappingPC` are different, `funcPC` is the PC of the method, which binds a special pointer to its receiver, and `trappingPC` is the PC of the general type method

func PushInterceptor

func PushInterceptor(pre PreInterceptor, post PostInterceptor) func()

func PushMockByName

func PushMockByName(pkgPath string, funcName string, interceptor Interceptor) func()

func PushMockInterceptor

func PushMockInterceptor(fn interface{}, interceptor Interceptor) func()

func PushMockMethodByName

func PushMockMethodByName(instance interface{}, method string, interceptor Interceptor) func()

func PushMockReplacer

func PushMockReplacer(fn interface{}, replacer interface{}) func()

func PushMockReplacerByName

func PushMockReplacerByName(pkgPath string, funcName string, replacer interface{}) func()

func PushMockReplacerMethodByName

func PushMockReplacerMethodByName(instance interface{}, method string, replacer interface{}) func()

func PushRecordHandler

func PushRecordHandler(pc uintptr, recvPtr interface{}, pre func(fnInfo *core.FuncInfo, recvPtr interface{}, args []interface{}, results []interface{}) (interface{}, bool), post func(fnInfo *core.FuncInfo, recvPtr interface{}, args []interface{}, results []interface{}, data interface{})) func()

func PushRecorder

func PushRecorder(fn interface{}, pre interface{}, post interface{}) func()

func PushRecorderInterceptor

func PushRecorderInterceptor(fn interface{}, preInterceptor PreInterceptor, postInterceptor PostInterceptor) func()

func PushVarPtrRecordHandler

func PushVarPtrRecordHandler(varAddr uintptr, pre func(fnInfo *core.FuncInfo, res interface{}) (interface{}, bool), post func(fnInfo *core.FuncInfo, res interface{}, data interface{})) func()

func PushVarRecordHandler

func PushVarRecordHandler(varAddr uintptr, pre func(fnInfo *core.FuncInfo, res interface{}) (interface{}, bool), post func(fnInfo *core.FuncInfo, res interface{}, data interface{})) func()

Types

type Interceptor

type Interceptor func(ctx context.Context, fn *core.FuncInfo, args core.Object, results core.Object) error

type PostInterceptor

type PostInterceptor func(ctx context.Context, fn *core.FuncInfo, args core.Object, results core.Object, data interface{}) error

type PreInterceptor

type PreInterceptor func(ctx context.Context, fn *core.FuncInfo, args core.Object, results core.Object) (interface{}, error)

type StackData

type StackData struct {
	// contains filtered or unexported fields
}

type StackDataExportImpl

type StackDataExportImpl struct {
	// contains filtered or unexported fields
}

func (*StackDataExportImpl) Data

func (*StackDataExportImpl) JSON

func (c *StackDataExportImpl) JSON() ([]byte, error)

Jump to

Keyboard shortcuts

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