proc

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package proc is a low-level package that provides methods to manipulate the process we are debugging.

proc implements all core functionality including: * creating / attaching to a process * process manipulation (step, next, continue, halt) * methods to explore the memory of the process

Index

Constants

View Source
const (
	GNUFlavour = AssemblyFlavour(iota)
	IntelFlavour
	GoFlavour
)
View Source
const (
	Gidle           uint64 = iota // 0
	Grunnable                     // 1 runnable and on a run queue
	Grunning                      // 2
	Gsyscall                      // 3
	Gwaiting                      // 4
	GmoribundUnused               // 5 currently unused, but hardcoded in gdb scripts
	Gdead                         // 6
	Genqueue                      // 7 Only the Gscanenqueue is used.
	Gcopystack                    // 8 in this state when newstack is moving the stack
)

G status, from: src/runtime/runtime2.go

View Source
const UnrecoveredPanic = "unrecovered-panic"

Variables

View Source
var (
	ErrFuncCallUnsupported        = errors.New("function calls not supported by this version of Go")
	ErrFuncCallUnsupportedBackend = errors.New("backend does not support function calls")
	ErrFuncCallInProgress         = errors.New("cannot call function while another function call is already in progress")
	ErrNotACallExpr               = errors.New("not a function call")
	ErrNoGoroutine                = errors.New("no goroutine selected")
	ErrGoroutineNotRunning        = errors.New("selected goroutine not running")
	ErrNotEnoughStack             = errors.New("not enough stack space")
	ErrTooManyArguments           = errors.New("too many arguments")
	ErrNotEnoughArguments         = errors.New("not enough arguments")
	ErrNoAddrUnsupported          = errors.New("arguments to a function call must have an address")
	ErrNotAGoFunction             = errors.New("not a Go function")
)
View Source
var NotExecutableErr = errors.New("not an executable file")
View Source
var NotRecordedErr = errors.New("not a recording")
View Source
var OperationOnSpecialFloatError = errors.New("operations on non-finite floats not implemented")
View Source
var UnknownRegisterError = errors.New("unknown register")
View Source
var UnsupportedDarwinArchErr = errors.New("unsupported architecture - only darwin/amd64 is supported")
View Source
var UnsupportedLinuxArchErr = errors.New("unsupported architecture - only linux/amd64 is supported")
View Source
var UnsupportedWindowsArchErr = errors.New("unsupported architecture of windows/386 - only windows/amd64 is supported")

Functions

func CallFunction added in v1.1.0

func CallFunction(p Process, expr string, retLoadCfg *LoadConfig) error

CallFunction starts a debugger injected function call on the current thread of p. See runtime.debugCallV1 in $GOROOT/src/runtime/asm_amd64.s for a description of the protocol.

func Continue added in v1.0.0

func Continue(dbp Process) error

Continue continues execution of the debugged process. It will continue until it hits a breakpoint or is otherwise stopped.

func CreateUnrecoveredPanicBreakpoint added in v1.1.0

func CreateUnrecoveredPanicBreakpoint(p Process, writeBreakpoint writeBreakpointFn, breakpoints *BreakpointMap)

CreateUnrecoverablePanicBreakpoint creates the unrecoverable-panic breakpoint. This function is meant to be called by implementations of the Process interface.

func FindFileLocation added in v1.0.0

func FindFileLocation(p Process, fileName string, lineno int) (uint64, error)

FindFileLocation returns the PC for a given file:line. Assumes that `file` is normalized to lower case and '/' on Windows.

func FindFunctionLocation added in v1.0.0

func FindFunctionLocation(p Process, funcName string, firstLine bool, lineOffset int) (uint64, error)

FindFunctionLocation finds address of a function's line If firstLine == true is passed FindFunctionLocation will attempt to find the first line of the function If lineOffset is passed FindFunctionLocation will return the address of that line Pass lineOffset == 0 and firstLine == false if you want the address for the function's entry point Note that setting breakpoints at that address will cause surprising behavior: https://github.com/derekparker/delve/issues/170

func FirstPCAfterPrologue added in v1.1.0

func FirstPCAfterPrologue(p Process, fn *Function, sameline bool) (uint64, error)

FirstPCAfterPrologue returns the address of the first instruction after the prologue for function fn. If sameline is set FirstPCAfterPrologue will always return an address associated with the same line as fn.Entry.

func LinuxX86XstateRead added in v1.0.0

func LinuxX86XstateRead(xstateargs []byte, readLegacy bool, regset *LinuxX86Xstate) error

LinuxX86XstateRead reads a byte array containing an XSAVE area into regset. If readLegacy is true regset.PtraceFpRegs will be filled with the contents of the legacy region of the XSAVE area. See Section 13.1 (and following) of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1: Basic Architecture.

func Next added in v1.0.0

func Next(dbp Process) (err error)

Next continues execution until the next source line.

func SameGoroutineCondition added in v1.0.0

func SameGoroutineCondition(g *G) ast.Expr

SameGoroutineCondition returns an expression that evaluates to true when the current goroutine is g.

func Step added in v1.0.0

func Step(dbp Process) (err error)

Step will continue until another source line is reached. Will step into functions.

func StepOut added in v1.0.0

func StepOut(dbp Process) error

StepOut will continue until the current goroutine exits the function currently being executed or a deferred function is executed

Types

type AMD64

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

AMD64 represents the AMD64 CPU architecture.

func AMD64Arch

func AMD64Arch(goos string) *AMD64

AMD64Arch returns an initialized AMD64 struct.

func (*AMD64) BreakpointInstruction

func (a *AMD64) BreakpointInstruction() []byte

BreakpointInstruction returns the Breakpoint instruction for this architecture.

func (*AMD64) BreakpointSize

func (a *AMD64) BreakpointSize() int

BreakpointSize returns the size of the breakpoint instruction on this architecture.

func (*AMD64) DerefTLS added in v1.0.0

func (a *AMD64) DerefTLS() bool

If DerefTLS returns true the value of regs.TLS()+GStructOffset() is a pointer to the G struct

func (*AMD64) FixFrameUnwindContext added in v1.0.0

func (a *AMD64) FixFrameUnwindContext(fctxt *frame.FrameContext, pc uint64, bi *BinaryInfo) *frame.FrameContext

FixFrameUnwindContext adds default architecture rules to fctxt or returns the default frame unwind context if fctxt is nil.

func (*AMD64) GoroutineToDwarfRegisters added in v1.0.0

func (a *AMD64) GoroutineToDwarfRegisters(g *G) op.DwarfRegisters

GoroutineToDwarfRegisters extract the saved DWARF registers from a parked goroutine in the format used by the DWARF expression interpreter.

func (*AMD64) PtrSize

func (a *AMD64) PtrSize() int

PtrSize returns the size of a pointer on this architecture.

func (*AMD64) RegSize added in v1.0.0

func (a *AMD64) RegSize(regnum uint64) int

RegSize returns the size (in bytes) of register regnum. The mapping between hardware registers and DWARF registers is specified in the System V ABI AMD64 Architecture Processor Supplement page 57, figure 3.36 https://www.uclibc.org/docs/psABI-x86_64.pdf

func (*AMD64) RegistersToDwarfRegisters added in v1.0.0

func (a *AMD64) RegistersToDwarfRegisters(regs Registers) op.DwarfRegisters

RegistersToDwarfRegisters converts hardware registers to the format used by the DWARF expression interpreter.

type Arch

type Arch interface {
	PtrSize() int
	BreakpointInstruction() []byte
	BreakpointSize() int
	DerefTLS() bool
	FixFrameUnwindContext(fctxt *frame.FrameContext, pc uint64, bi *BinaryInfo) *frame.FrameContext
	RegSize(uint64) int
	RegistersToDwarfRegisters(Registers) op.DwarfRegisters
	GoroutineToDwarfRegisters(*G) op.DwarfRegisters
}

Arch defines an interface for representing a CPU architecture.

type AsmInstruction

type AsmInstruction struct {
	Loc        Location
	DestLoc    *Location
	Bytes      []byte
	Breakpoint bool
	AtPC       bool
	Inst       *ArchInst
}

func Disassemble added in v1.0.0

func Disassemble(dbp Process, g *G, startPC, endPC uint64) ([]AsmInstruction, error)

Disassemble disassembles target memory between startPC and endPC, marking the current instruction being executed in goroutine g. If currentGoroutine is set and thread is stopped at a CALL instruction Disassemble will evaluate the argument of the CALL instruction using the thread's registers Be aware that the Bytes field of each returned instruction is a slice of a larger array of size endPC - startPC

type AssemblyFlavour

type AssemblyFlavour int

type BinaryInfo

type BinaryInfo struct {
	GOOS string

	Arch Arch

	// Functions is a list of all DW_TAG_subprogram entries in debug_info, sorted by entry point
	Functions []Function
	// Sources is a list of all source files found in debug_line.
	Sources []string
	// LookupFunc maps function names to a description of the function.
	LookupFunc map[string]*Function
	// contains filtered or unexported fields
}

func NewBinaryInfo

func NewBinaryInfo(goos, goarch string) BinaryInfo

func (*BinaryInfo) AllPCsForFileLine added in v1.1.0

func (bi *BinaryInfo) AllPCsForFileLine(filename string, lineno int) []uint64

AllPCsForFileLine returns all PC addresses for the given filename:lineno.

func (*BinaryInfo) Close

func (bi *BinaryInfo) Close() error

func (*BinaryInfo) DwarfReader

func (bi *BinaryInfo) DwarfReader() *reader.Reader

DwarfReader returns a reader for the dwarf data

func (*BinaryInfo) GStructOffset added in v1.0.0

func (bi *BinaryInfo) GStructOffset() uint64

GStructOffset returns the offset of the G struct in thread local storage.

func (*BinaryInfo) LastModified

func (bi *BinaryInfo) LastModified() time.Time

func (*BinaryInfo) LineToPC added in v1.0.0

func (bi *BinaryInfo) LineToPC(filename string, lineno int) (pc uint64, fn *Function, err error)

LineToPC converts a file:line into a memory address.

func (*BinaryInfo) LoadBinaryInfo

func (bininfo *BinaryInfo) LoadBinaryInfo(path string, wg *sync.WaitGroup) error

func (*BinaryInfo) LoadBinaryInfoElf

func (bi *BinaryInfo) LoadBinaryInfoElf(path string, wg *sync.WaitGroup) error

func (*BinaryInfo) LoadBinaryInfoMacho

func (bi *BinaryInfo) LoadBinaryInfoMacho(path string, wg *sync.WaitGroup) error

func (*BinaryInfo) LoadBinaryInfoPE

func (bi *BinaryInfo) LoadBinaryInfoPE(path string, wg *sync.WaitGroup) error

func (*BinaryInfo) LoadError added in v1.0.0

func (bi *BinaryInfo) LoadError() error

func (*BinaryInfo) LoadFromData added in v1.0.0

func (bi *BinaryInfo) LoadFromData(dwdata *dwarf.Data, debugFrameBytes, debugLineBytes, debugLocBytes []byte)

LoadFromData creates a new BinaryInfo object using the specified data. This is used for debugging BinaryInfo, you should use LoadBinary instead.

func (*BinaryInfo) Location added in v1.0.0

func (bi *BinaryInfo) Location(entry reader.Entry, attr dwarf.Attr, pc uint64, regs op.DwarfRegisters) (int64, []op.Piece, string, error)

Location returns the location described by attribute attr of entry. This will either be an int64 address or a slice of Pieces for locations that don't correspond to a single memory address (registers, composite locations).

func (*BinaryInfo) PCToFunc added in v1.0.0

func (bi *BinaryInfo) PCToFunc(pc uint64) *Function

PCToFunc returns the function containing the given PC address

func (*BinaryInfo) PCToLine

func (bi *BinaryInfo) PCToLine(pc uint64) (string, int, *Function)

PCToLine converts an instruction address to a file/line/function.

func (*BinaryInfo) Producer added in v1.1.0

func (bi *BinaryInfo) Producer() string

func (*BinaryInfo) Type added in v1.1.0

func (bi *BinaryInfo) Type(offset dwarf.Offset) (godwarf.Type, error)

Type returns the Dwarf type entry at `offset`.

func (*BinaryInfo) Types

func (bi *BinaryInfo) Types() ([]string, error)

Types returns list of types present in the debugged program.

type Breakpoint

type Breakpoint struct {
	// File & line information for printing.
	FunctionName string
	File         string
	Line         int

	Addr         uint64 // Address breakpoint is set for.
	OriginalData []byte // If software breakpoint, the data we replace with breakpoint instruction.
	Name         string // User defined name of the breakpoint
	ID           int    // Monotonically increasing ID.

	// Kind describes whether this is an internal breakpoint (for next'ing or
	// stepping).
	// A single breakpoint can be both a UserBreakpoint and some kind of
	// internal breakpoint, but it can not be two different kinds of internal
	// breakpoint.
	Kind BreakpointKind

	// Breakpoint information
	Tracepoint    bool     // Tracepoint flag
	Goroutine     bool     // Retrieve goroutine information
	Stacktrace    int      // Number of stack frames to retrieve
	Variables     []string // Variables to evaluate
	LoadArgs      *LoadConfig
	LoadLocals    *LoadConfig
	HitCount      map[int]uint64 // Number of times a breakpoint has been reached in a certain goroutine
	TotalHitCount uint64         // Number of times a breakpoint has been reached

	// DeferReturns: when kind == NextDeferBreakpoint this breakpoint
	// will also check if the caller is runtime.gopanic or if the return
	// address is in the DeferReturns array.
	// Next uses NextDeferBreakpoints for the breakpoint it sets on the
	// deferred function, DeferReturns is populated with the
	// addresses of calls to runtime.deferreturn in the current
	// function. This insures that the breakpoint on the deferred
	// function only triggers on panic or on the defer call to
	// the function, not when the function is called directly
	DeferReturns []uint64
	// Cond: if not nil the breakpoint will be triggered only if evaluating Cond returns true
	Cond ast.Expr
	// contains filtered or unexported fields
}

Breakpoint represents a breakpoint. Stores information on the break point including the byte of data that originally was stored at that address.

func (*Breakpoint) CheckCondition added in v1.0.0

func (bp *Breakpoint) CheckCondition(thread Thread) BreakpointState

CheckCondition evaluates bp's condition on thread.

func (*Breakpoint) IsInternal added in v1.0.0

func (bp *Breakpoint) IsInternal() bool

IsInternal returns true if bp is an internal breakpoint. User-set breakpoints can overlap with internal breakpoints, in that case both IsUser and IsInternal will be true.

func (*Breakpoint) IsUser added in v1.0.0

func (bp *Breakpoint) IsUser() bool

IsUser returns true if bp is a user-set breakpoint. User-set breakpoints can overlap with internal breakpoints, in that case both IsUser and IsInternal will be true.

func (*Breakpoint) String

func (bp *Breakpoint) String() string

type BreakpointExistsError

type BreakpointExistsError struct {
	File string
	Line int
	Addr uint64
}

BreakpointExistsError is returned when trying to set a breakpoint at an address that already has a breakpoint set for it.

func (BreakpointExistsError) Error

func (bpe BreakpointExistsError) Error() string

type BreakpointKind

type BreakpointKind uint16

Breakpoint Kind determines the behavior of delve when the breakpoint is reached.

const (
	// UserBreakpoint is a user set breakpoint
	UserBreakpoint BreakpointKind = (1 << iota)
	// NextBreakpoint is a breakpoint set by Next, Continue
	// will stop on it and delete it
	NextBreakpoint
	// NextDeferBreakpoint is a breakpoint set by Next on the
	// first deferred function. In addition to checking their condition
	// breakpoints of this kind will also check that the function has been
	// called by runtime.gopanic or through runtime.deferreturn.
	NextDeferBreakpoint
	// StepBreakpoint is a breakpoint set by Step on a CALL instruction,
	// Continue will set a new breakpoint (of NextBreakpoint kind) on the
	// destination of CALL, delete this breakpoint and then continue again
	StepBreakpoint
)

type BreakpointManipulation added in v1.0.0

type BreakpointManipulation interface {
	Breakpoints() *BreakpointMap
	SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Expr) (*Breakpoint, error)
	ClearBreakpoint(addr uint64) (*Breakpoint, error)
	ClearInternalBreakpoints() error
}

BreakpointManipulation is an interface for managing breakpoints.

type BreakpointMap added in v1.0.0

type BreakpointMap struct {
	M map[uint64]*Breakpoint
	// contains filtered or unexported fields
}

BreakpointMap represents an (address, breakpoint) map.

func NewBreakpointMap added in v1.0.0

func NewBreakpointMap() BreakpointMap

NewBreakpointMap creates a new BreakpointMap.

func (*BreakpointMap) Clear added in v1.0.0

func (bpmap *BreakpointMap) Clear(addr uint64, clearBreakpoint clearBreakpointFn) (*Breakpoint, error)

Clear clears the breakpoint at addr. Do not call this function call proc.Process.ClearBreakpoint instead.

func (*BreakpointMap) ClearInternalBreakpoints added in v1.0.0

func (bpmap *BreakpointMap) ClearInternalBreakpoints(clearBreakpoint clearBreakpointFn) error

ClearInternalBreakpoints removes all internal breakpoints from the map, calling clearBreakpoint on each one. Do not call this function, call proc.Process.ClearInternalBreakpoints instead, this function is used to implement that.

func (*BreakpointMap) HasInternalBreakpoints added in v1.0.0

func (bpmap *BreakpointMap) HasInternalBreakpoints() bool

HasInternalBreakpoints returns true if bpmap has at least one internal breakpoint set.

func (*BreakpointMap) ResetBreakpointIDCounter added in v1.0.0

func (bpmap *BreakpointMap) ResetBreakpointIDCounter()

ResetBreakpointIDCounter resets the breakpoint ID counter of bpmap.

func (*BreakpointMap) Set added in v1.0.0

func (bpmap *BreakpointMap) Set(addr uint64, kind BreakpointKind, cond ast.Expr, writeBreakpoint writeBreakpointFn) (*Breakpoint, error)

Set creates a breakpoint at addr calling writeBreakpoint. Do not call this function, call proc.Process.SetBreakpoint instead, this function exists to implement proc.Process.SetBreakpoint.

func (*BreakpointMap) SetWithID added in v1.0.0

func (bpmap *BreakpointMap) SetWithID(id int, addr uint64, writeBreakpoint writeBreakpointFn) (*Breakpoint, error)

SetWithID creates a breakpoint at addr, with the specified ID.

type BreakpointState added in v1.0.0

type BreakpointState struct {
	*Breakpoint
	// Active is true if the breakpoint condition was met.
	Active bool
	// Internal is true if the breakpoint was matched as an internal
	// breakpoint.
	Internal bool
	// CondError contains any error encountered while evaluating the
	// breakpoint's condition.
	CondError error
}

BreakpointState describes the state of a breakpoint in a thread.

func (*BreakpointState) Clear added in v1.0.0

func (bpstate *BreakpointState) Clear()

func (*BreakpointState) String added in v1.0.0

func (bpstate *BreakpointState) String() string

type Checkpoint added in v1.0.0

type Checkpoint struct {
	ID    int
	When  string
	Where string
}

Checkpoint is a checkpoint

type CommonProcess added in v1.1.0

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

CommonProcess contains fields used by this package, common to all implementations of the Process interface.

func NewCommonProcess added in v1.1.0

func NewCommonProcess(fncallEnabled bool) CommonProcess

func (*CommonProcess) ClearAllGCache added in v1.1.0

func (p *CommonProcess) ClearAllGCache()

ClearAllGCache clears the cached contents of the cache for runtime.allgs.

type CommonThread added in v1.1.0

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

CommonThread contains fields used by this package, common to all implementations of the Thread interface.

func (*CommonThread) ReturnValues added in v1.1.0

func (t *CommonThread) ReturnValues(cfg LoadConfig) []*Variable

type Defer added in v1.1.0

type Defer struct {
	DeferredPC uint64 // Value of field _defer.fn.fn, the deferred function
	DeferPC    uint64 // PC address of instruction that added this defer
	SP         uint64 // Value of SP register when this function was deferred (this field gets adjusted when the stack is moved to match the new stack space)

	Unreadable error
	// contains filtered or unexported fields
}

Defer represents one deferred call

func (*Defer) Next added in v1.1.0

func (d *Defer) Next() *Defer

Next returns the next defer in the linked list

type Direction added in v1.0.0

type Direction int8
const (
	Forward  Direction = 0
	Backward Direction = 1
)

type EvalScope

type EvalScope struct {
	Location
	Regs    op.DwarfRegisters
	Mem     MemoryReadWriter // Target's memory
	Gvar    *Variable
	BinInfo *BinaryInfo
	// contains filtered or unexported fields
}

EvalScope is the scope for variable evaluation. Contains the thread, current location (PC), and canonical frame address.

func ConvertEvalScope added in v1.0.0

func ConvertEvalScope(dbp Process, gid, frame int) (*EvalScope, error)

ConvertEvalScope returns a new EvalScope in the context of the specified goroutine ID and stack frame.

func FrameToScope added in v1.0.0

func FrameToScope(bi *BinaryInfo, thread MemoryReadWriter, g *G, frames ...Stackframe) *EvalScope

FrameToScope returns a new EvalScope for frames[0]. If frames has at least two elements all memory between frames[0].Regs.SP() and frames[1].Regs.CFA will be cached. Otherwise all memory between frames[0].Regs.SP() and frames[0].Regs.CFA will be cached.

func GoroutineScope added in v1.0.0

func GoroutineScope(thread Thread) (*EvalScope, error)

GoroutineScope returns an EvalScope for the goroutine running on this thread.

func ThreadScope added in v1.0.0

func ThreadScope(thread Thread) (*EvalScope, error)

ThreadScope returns an EvalScope for this thread.

func (*EvalScope) DwarfReader

func (scope *EvalScope) DwarfReader() *reader.Reader

DwarfReader returns the DwarfReader containing the Dwarf information for the target process.

func (*EvalScope) EvalExpression

func (scope *EvalScope) EvalExpression(expr string, cfg LoadConfig) (*Variable, error)

EvalExpression returns the value of the given expression.

func (*EvalScope) EvalVariable

func (scope *EvalScope) EvalVariable(name string, cfg LoadConfig) (*Variable, error)

EvalVariable returns the value of the given expression (backwards compatibility).

func (*EvalScope) FunctionArguments

func (scope *EvalScope) FunctionArguments(cfg LoadConfig) ([]*Variable, error)

FunctionArguments returns the name, value, and type of all current function arguments.

func (*EvalScope) LocalVariables

func (scope *EvalScope) LocalVariables(cfg LoadConfig) ([]*Variable, error)

LocalVariables returns all local variables from the current function scope.

func (*EvalScope) Locals added in v1.1.0

func (scope *EvalScope) Locals() ([]*Variable, error)

Fetches all variables of a specific type in the current function scope

func (*EvalScope) PackageVariables

func (scope *EvalScope) PackageVariables(cfg LoadConfig) ([]*Variable, error)

PackageVariables returns the name, value, and type of all package variables in the application.

func (*EvalScope) PtrSize

func (scope *EvalScope) PtrSize() int

PtrSize returns the size of a pointer.

func (*EvalScope) SetVariable

func (scope *EvalScope) SetVariable(name, value string) error

SetVariable sets the value of the named variable

type FloatSpecial

type FloatSpecial uint8
const (
	FloatIsNormal FloatSpecial = iota
	FloatIsNaN
	FloatIsPosInf
	FloatIsNegInf
)

type Function added in v1.0.0

type Function struct {
	Name       string
	Entry, End uint64 // same as DW_AT_lowpc and DW_AT_highpc
	// contains filtered or unexported fields
}

Function describes a function in the target program.

func (*Function) BaseName added in v1.0.0

func (fn *Function) BaseName() string

BaseName returns the symbol name without the package or receiver name. Borrowed from $GOROOT/debug/gosym/symtab.go

func (*Function) Optimized added in v1.0.0

func (fn *Function) Optimized() bool

Optimized returns true if the function was optimized by the compiler.

func (*Function) PackageName added in v1.0.0

func (fn *Function) PackageName() string

PackageName returns the package part of the symbol name, or the empty string if there is none. Borrowed from $GOROOT/debug/gosym/symtab.go

func (*Function) ReceiverName added in v1.0.0

func (fn *Function) ReceiverName() string

ReceiverName returns the receiver type name of this symbol, or the empty string if there is none. Borrowed from $GOROOT/debug/gosym/symtab.go

type FunctionNotFoundError added in v1.1.0

type FunctionNotFoundError struct {
	FuncName string
}

func (*FunctionNotFoundError) Error added in v1.1.0

func (err *FunctionNotFoundError) Error() string

type G

type G struct {
	ID         int    // Goroutine ID
	PC         uint64 // PC of goroutine when it was parked.
	SP         uint64 // SP of goroutine when it was parked.
	BP         uint64 // BP of goroutine when it was parked (go >= 1.7).
	GoPC       uint64 // PC of 'go' statement that created this goroutine.
	StartPC    uint64 // PC of the first function run on this goroutine.
	WaitReason string // Reason for goroutine being parked.
	Status     uint64

	SystemStack bool // SystemStack is true if this goroutine is currently executing on a system stack.

	// Information on goroutine location
	CurrentLoc Location

	// Thread that this goroutine is currently allocated to
	Thread Thread
	// contains filtered or unexported fields
}

G represents a runtime G (goroutine) structure (at least the fields that Delve is interested in).

func FindGoroutine added in v1.0.0

func FindGoroutine(dbp Process, gid int) (*G, error)

FindGoroutine returns a G struct representing the goroutine specified by `gid`.

func GetG added in v1.0.0

func GetG(thread Thread) (*G, error)

GetG returns information on the G (goroutine) that is executing on this thread.

The G structure for a thread is stored in thread local storage. Here we simply calculate the address and read and parse the G struct.

We cannot simply use the allg linked list in order to find the M that represents the given OS thread and follow its G pointer because on Darwin mach ports are not universal, so our port for this thread would not map to the `id` attribute of the M structure. Also, when linked against libc, Go prefers the libc version of clone as opposed to the runtime version. This has the consequence of not setting M.id for any thread, regardless of OS.

In order to get around all this craziness, we read the address of the G structure for the current thread from the thread local storage area.

func GoroutinesInfo added in v1.0.0

func GoroutinesInfo(dbp Process) ([]*G, error)

GoroutinesInfo returns an array of G structures representing the information Delve cares about from the internal runtime G structure.

func (*G) Defer added in v1.1.0

func (g *G) Defer() *Defer

Defer returns the top-most defer of the goroutine.

func (*G) Go

func (g *G) Go() Location

Go returns the location of the 'go' statement that spawned this goroutine.

func (*G) Stacktrace

func (g *G) Stacktrace(depth int, readDefers bool) ([]Stackframe, error)

Stacktrace returns the stack trace for a goroutine. Note the locations in the array are return addresses not call addresses.

func (*G) StartLoc added in v1.1.0

func (g *G) StartLoc() Location

StartLoc returns the starting location of the goroutine.

func (*G) UserCurrent

func (g *G) UserCurrent() Location

UserCurrent returns the location the users code is at, or was at before entering a runtime function.

type GoroutineInfo added in v1.0.0

type GoroutineInfo interface {
	SelectedGoroutine() *G
}

GoroutineInfo is an interface for getting information on running goroutines.

type Info added in v1.0.0

type Info interface {
	Pid() int
	// ResumeNotify specifies a channel that will be closed the next time
	// ContinueOnce finishes resuming the target.
	ResumeNotify(chan<- struct{})
	// Valid returns true if this Process can be used. When it returns false it
	// also returns an error describing why the Process is invalid (either
	// ProcessExitedError or ProcessDetachedError).
	Valid() (bool, error)
	BinInfo() *BinaryInfo
	// Common returns a struct with fields common to all backends
	Common() *CommonProcess

	ThreadInfo
	GoroutineInfo
}

Info is an interface that provides general information on the target.

type InvalidAddressError

type InvalidAddressError struct {
	Address uint64
}

InvalidAddressError represents the result of attempting to set a breakpoint at an invalid address.

func (InvalidAddressError) Error

func (iae InvalidAddressError) Error() string

type IsNilErr

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

IsNilErr is returned when a variable is nil.

func (*IsNilErr) Error

func (err *IsNilErr) Error() string

type LinuxX86Xstate added in v1.0.0

type LinuxX86Xstate struct {
	PtraceFpRegs
	Xsave    []byte // raw xsave area
	AvxState bool   // contains AVX state
	YmmSpace [256]byte
}

LinuxX86Xstate represents amd64 XSAVE area. See Section 13.1 (and following) of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1: Basic Architecture.

func (*LinuxX86Xstate) Decode added in v1.0.0

func (xsave *LinuxX86Xstate) Decode() (regs []Register)

Decode decodes an XSAVE area to a list of name/value pairs of registers.

type LoadConfig

type LoadConfig struct {
	// FollowPointers requests pointers to be automatically dereferenced.
	FollowPointers bool
	// MaxVariableRecurse is how far to recurse when evaluating nested types.
	MaxVariableRecurse int
	// MaxStringLen is the maximum number of bytes read from a string
	MaxStringLen int
	// MaxArrayValues is the maximum number of elements read from an array, a slice or a map.
	MaxArrayValues int
	// MaxStructFields is the maximum number of fields read from a struct, -1 will read all fields.
	MaxStructFields int
}

type Location

type Location struct {
	PC   uint64
	File string
	Line int
	Fn   *Function
}

Location represents the location of a thread. Holds information on the current instruction address, the source file:line, and the function.

type MemoryReadWriter added in v1.0.0

type MemoryReadWriter interface {
	MemoryReader
	WriteMemory(addr uintptr, data []byte) (written int, err error)
}

func DereferenceMemory added in v1.0.0

func DereferenceMemory(mem MemoryReadWriter) MemoryReadWriter

DereferenceMemory returns a MemoryReadWriter that can read and write the memory pointed to by pointers in this memory. Normally mem and mem.Dereference are the same object, they are different only if this MemoryReadWriter is used to access memory outside of the normal address space of the inferior process (such as data contained in registers, or composite memory).

type MemoryReader added in v1.0.0

type MemoryReader interface {
	// ReadMemory is just like io.ReaderAt.ReadAt.
	ReadMemory(buf []byte, addr uintptr) (n int, err error)
}

MemoryReader is like io.ReaderAt, but the offset is a uintptr so that it can address all of 64-bit memory. Redundant with memoryReadWriter but more easily suited to working with the standard io package.

type NoBreakpointError

type NoBreakpointError struct {
	Addr uint64
}

NoBreakpointError is returned when trying to clear a breakpoint that does not exist.

func (NoBreakpointError) Error

func (nbp NoBreakpointError) Error() string

type NoBuildIdNoteError added in v1.1.0

type NoBuildIdNoteError struct{}

This error is used in openSeparateDebugInfo to signal there's no build-id note on the binary, so LoadBinaryInfoElf will return the error message coming from elfFile.DWARF() instead.

func (*NoBuildIdNoteError) Error added in v1.1.0

func (e *NoBuildIdNoteError) Error() string

type NoGError

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

NoGError returned when a G could not be found for a specific thread.

func (NoGError) Error

func (ng NoGError) Error() string

type NoSourceForPCError added in v1.0.0

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

func (*NoSourceForPCError) Error added in v1.0.0

func (err *NoSourceForPCError) Error() string

type NullAddrError

type NullAddrError struct{}

NullAddrError is an error for a null address.

func (NullAddrError) Error

func (n NullAddrError) Error() string

type Process

Process represents the target of the debugger. This target could be a system process, core file, etc.

Implementations of Process are not required to be thread safe and users of Process should not assume they are. There is one exception to this rule: it is safe to call RequestManualStop concurrently with ContinueOnce.

type ProcessDetachedError added in v1.1.0

type ProcessDetachedError struct {
}

ProcessDetachedError indicates that we detached from the target process.

func (ProcessDetachedError) Error added in v1.1.0

func (pe ProcessDetachedError) Error() string

type ProcessExitedError

type ProcessExitedError struct {
	Pid    int
	Status int
}

ProcessExitedError indicates that the process has exited and contains both process id and exit status.

func (ProcessExitedError) Error

func (pe ProcessExitedError) Error() string

type ProcessManipulation added in v1.0.0

type ProcessManipulation interface {
	ContinueOnce() (trapthread Thread, err error)
	StepInstruction() error
	SwitchThread(int) error
	SwitchGoroutine(int) error
	RequestManualStop() error
	// CheckAndClearManualStopRequest returns true the first time it's called
	// after a call to RequestManualStop.
	CheckAndClearManualStopRequest() bool
	Detach(bool) error
}

ProcessManipulation is an interface for changing the execution state of a process.

type PtraceFpRegs added in v1.0.0

type PtraceFpRegs struct {
	Cwd      uint16
	Swd      uint16
	Ftw      uint16
	Fop      uint16
	Rip      uint64
	Rdp      uint64
	Mxcsr    uint32
	MxcrMask uint32
	StSpace  [32]uint32
	XmmSpace [256]byte
	Padding  [24]uint32
}

tracks user_fpregs_struct in /usr/include/x86_64-linux-gnu/sys/user.h

type RecordingManipulation added in v1.0.0

type RecordingManipulation interface {
	// Recorded returns true if the current process is a recording and the path
	// to the trace directory.
	Recorded() (recorded bool, tracedir string)
	// Restart restarts the recording from the specified position, or from the
	// last checkpoint if pos == "".
	// If pos starts with 'c' it's a checkpoint ID, otherwise it's an event
	// number.
	Restart(pos string) error
	// Direction changes execution direction.
	Direction(Direction) error
	// When returns current recording position.
	When() (string, error)
	// Checkpoint sets a checkpoint at the current position.
	Checkpoint(where string) (id int, err error)
	// Checkpoints returns the list of currently set checkpoint.
	Checkpoints() ([]Checkpoint, error)
	// ClearCheckpoint removes a checkpoint.
	ClearCheckpoint(id int) error
}

RecordingManipulation is an interface for manipulating process recordings.

type Register

type Register struct {
	Name  string
	Bytes []byte
	Value string
}

func AppendDwordReg added in v1.0.0

func AppendDwordReg(regs []Register, name string, value uint32) []Register

AppendDwordReg appends a double word (32 bit) register to regs.

func AppendEflagReg added in v1.0.0

func AppendEflagReg(regs []Register, name string, value uint64) []Register

AppendEflagReg appends EFLAG register to regs.

func AppendMxcsrReg added in v1.0.0

func AppendMxcsrReg(regs []Register, name string, value uint64) []Register

AppendMxcsrReg appends MXCSR register to regs.

func AppendQwordReg added in v1.0.0

func AppendQwordReg(regs []Register, name string, value uint64) []Register

AppendQwordReg appends a quad word (64 bit) register to regs.

func AppendSSEReg added in v1.0.0

func AppendSSEReg(regs []Register, name string, xmm []byte) []Register

AppendSSEReg appends a 256 bit SSE register to regs.

func AppendWordReg added in v1.0.0

func AppendWordReg(regs []Register, name string, value uint16) []Register

AppendWordReg appends a word (16 bit) register to regs.

func AppendX87Reg added in v1.0.0

func AppendX87Reg(regs []Register, index int, exponent uint16, mantissa uint64) []Register

AppendX87Reg appends a 80 bit float register to regs.

type Registers

type Registers interface {
	PC() uint64
	SP() uint64
	BP() uint64
	CX() uint64
	TLS() uint64
	// GAddr returns the address of the G variable if it is known, 0 and false otherwise
	GAddr() (uint64, bool)
	Get(int) (uint64, error)
	Slice() []Register
	// Save saves a copy of this object that will survive restarts
	Save() SavedRegisters
}

Registers is an interface for a generic register type. The interface encapsulates the generic values / actions we need independent of arch. The concrete register types will be different depending on OS/Arch.

type SavedRegisters added in v1.1.0

type SavedRegisters interface {
}

type Stackframe

type Stackframe struct {
	Current, Call Location

	// Frame registers.
	Regs op.DwarfRegisters

	// Return address for this stack frame (as read from the stack frame itself).
	Ret uint64

	// Err is set if an error occurred during stacktrace
	Err error
	// SystemStack is true if this frame belongs to a system stack.
	SystemStack bool
	// Inlined is true if this frame is actually an inlined call.
	Inlined bool

	// TopmostDefer is the defer that would be at the top of the stack when a
	// panic unwind would get to this call frame, in other words it's the first
	// deferred function that will  be called if the runtime unwinds past this
	// call frame.
	TopmostDefer *Defer

	// Defers is the list of functions deferred by this stack frame (so far).
	Defers []*Defer
	// contains filtered or unexported fields
}

Stackframe represents a frame in a system stack.

Each stack frame has two locations Current and Call.

For the topmost stackframe Current and Call are the same location.

For stackframes after the first Current is the location corresponding to the return address and Call is the location of the CALL instruction that was last executed on the frame. Note however that Call.PC is always equal to Current.PC, because finding the correct value for Call.PC would require disassembling each function in the stacktrace.

For synthetic stackframes generated for inlined function calls Current.Fn is the function containing the inlining and Call.Fn in the inlined function.

func ThreadStacktrace added in v1.0.0

func ThreadStacktrace(thread Thread, depth int) ([]Stackframe, error)

ThreadStacktrace returns the stack trace for thread. Note the locations in the array are return addresses not call addresses.

func (*Stackframe) FrameOffset added in v1.0.0

func (frame *Stackframe) FrameOffset() int64

FrameOffset returns the address of the stack frame, absolute for system stack frames or as an offset from stackhi for goroutine stacks (a negative value).

func (*Stackframe) FramePointerOffset added in v1.0.0

func (frame *Stackframe) FramePointerOffset() int64

FramePointerOffset returns the value of the frame pointer, absolute for system stack frames or as an offset from stackhi for goroutine stacks (a negative value).

type Thread

type Thread interface {
	MemoryReadWriter
	Location() (*Location, error)
	// Breakpoint will return the breakpoint that this thread is stopped at or
	// nil if the thread is not stopped at any breakpoint.
	Breakpoint() BreakpointState
	ThreadID() int
	Registers(floatingPoint bool) (Registers, error)
	// RestoreRegisters restores saved registers
	RestoreRegisters(SavedRegisters) error
	Arch() Arch
	BinInfo() *BinaryInfo
	StepInstruction() error
	// Blocked returns true if the thread is blocked
	Blocked() bool
	// SetCurrentBreakpoint updates the current breakpoint of this thread
	SetCurrentBreakpoint() error
	// Common returns the CommonThread structure for this thread
	Common() *CommonThread

	SetPC(uint64) error
	SetSP(uint64) error
	SetDX(uint64) error
}

Thread represents a thread.

type ThreadBlockedError

type ThreadBlockedError struct{}

ThreadBlockedError is returned when the thread is blocked in the scheduler.

func (ThreadBlockedError) Error

func (tbe ThreadBlockedError) Error() string

type ThreadInfo added in v1.0.0

type ThreadInfo interface {
	FindThread(threadID int) (Thread, bool)
	ThreadList() []Thread
	CurrentThread() Thread
}

ThreadInfo is an interface for getting information on active threads in the process.

type Variable

type Variable struct {
	Addr      uintptr
	OnlyAddr  bool
	Name      string
	DwarfType godwarf.Type
	RealType  godwarf.Type
	Kind      reflect.Kind

	Value        constant.Value
	FloatSpecial FloatSpecial

	Len int64
	Cap int64

	Flags VariableFlags

	// Base address of arrays, Base address of the backing array for slices (0 for nil slices)
	// Base address of the backing byte array for strings
	// address of the struct backing chan and map variables
	// address of the function entry point for function variables (0 for nil function pointers)
	Base uintptr

	Children []Variable

	Unreadable error

	LocationExpr string // location expression
	DeclLine     int64  // line number of this variable's declaration
	// contains filtered or unexported fields
}

Variable represents a variable. It contains the address, name, type and other information parsed from both the Dwarf information and the memory of the debugged process. If OnlyAddr is true, the variables value has not been loaded.

func (*Variable) ConstDescr added in v1.0.0

func (v *Variable) ConstDescr() string

ConstDescr describes the value of v using constants.

func (*Variable) TypeString

func (v *Variable) TypeString() string

TypeString returns the string representation of the type of this variable.

type VariableFlags added in v1.0.0

type VariableFlags uint16
const (
	// VariableEscaped is set for local variables that escaped to the heap
	//
	// The compiler performs escape analysis on local variables, the variables
	// that may outlive the stack frame are allocated on the heap instead and
	// only the address is recorded on the stack. These variables will be
	// marked with this flag.
	VariableEscaped VariableFlags = (1 << iota)
	// VariableShadowed is set for local variables that are shadowed by a
	// variable with the same name in another scope
	VariableShadowed
	// VariableConstant means this variable is a constant value
	VariableConstant
	// VariableArgument means this variable is a function argument
	VariableArgument
	// VariableReturnArgument means this variable is a function return value
	VariableReturnArgument
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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