debug

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PackageRegexp is regexp search that help us find those lines that
	// includes function calls in our package and its sub packages. The
	// following lines help you figure out what kind of lines we are talking
	// about:
	//   github.com/lainio/err2/try.To1[...](...)
	//   github.com/lainio/err2/assert.Asserter.True(...)
	PackageRegexp = regexp.MustCompile(`lainio/err2[a-zA-Z0-9_/.\[\]]*\(`)
)

Functions

func FprintStack

func FprintStack(w io.Writer, si StackInfo)

FprintStack prints the stack trace returned by runtime.Stack to the writer. The StackInfo tells what it prints from the stack.

func FuncName added in v0.8.12

func FuncName(si StackInfo) (n string, ln int, frame int, ok bool)

FuncName is similar to runtime.Caller, but instead to return program counter or function name with full path, funcName returns just function name, separated filename, and line number. If frame cannot be found ok is false.

See more information from runtime.Caller. The StackInfo tells how many stack frames we should go back (Level), and other fields tell how to find the actual line where calculation should be started.

func PrintStack

func PrintStack(stackLevel int)

PrintStack prints to standard error the stack trace returned by runtime.Stack by starting from stackLevel.

func PrintStackForTest added in v0.9.1

func PrintStackForTest(w io.Writer, stackLevel int)

PrintStackForTest prints to io.Writer the stack trace returned by runtime.Stack and processed to proper format to be shown in test output by starting from stackLevel.

Types

type StackInfo

type StackInfo struct {
	PackageName string
	FuncName    string
	Level       int

	*regexp.Regexp

	// these are used to filter out specific lines from output
	ExlRegexp []*regexp.Regexp
}

StackInfo has two parts. The first part is for anchor line, i.e., line in the call stack that we want to include, and where output starts. The second part is ExlRegexps that are used to filter out lines from final output.

Jump to

Keyboard shortcuts

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