target.go 3.0 KB
Newer Older
D
Derek Parker 已提交
1 2 3 4 5 6
package target

import (
	"debug/gosym"
	"go/ast"

D
Derek Parker 已提交
7
	"github.com/derekparker/delve/pkg/proc"
8 9 10
	"github.com/derekparker/delve/pkg/proc/core"
	"github.com/derekparker/delve/pkg/proc/gdbserial"
	"github.com/derekparker/delve/pkg/proc/native"
D
Derek Parker 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
)

// Target represents the target of the debugger. This
// target could be a system process, core file, etc.
type Interface interface {
	Info
	ProcessManipulation
	BreakpointManipulation
}

// Info is an interface that provides general information on the target.
type Info interface {
	Pid() int
	Exited() bool
	Running() bool
26
	BinInfo() *proc.BinaryInfo
D
Derek Parker 已提交
27 28 29 30

	ThreadInfo
	GoroutineInfo

31 32
	// FindFileLocation returns the address of the first instruction belonging
	// to line lineNumber in file fileName.
D
Derek Parker 已提交
33
	FindFileLocation(fileName string, lineNumber int) (uint64, error)
34 35 36 37 38

	// FirstPCAfterPrologue returns the first instruction address after fn's
	// prologue.
	// If sameline is true and the first instruction after the prologue belongs
	// to a different source line the entry point will be returned instead.
D
Derek Parker 已提交
39
	FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error)
40 41 42 43 44 45 46 47 48 49 50 51 52

	// 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
53
	FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error)
D
Derek Parker 已提交
54 55 56 57 58
}

// ThreadInfo is an interface for getting information on active threads
// in the process.
type ThreadInfo interface {
59 60 61
	FindThread(threadID int) (proc.IThread, bool)
	ThreadList() []proc.IThread
	CurrentThread() proc.IThread
D
Derek Parker 已提交
62 63 64 65 66 67 68 69 70
}

// GoroutineInfo is an interface for getting information on running goroutines.
type GoroutineInfo interface {
	SelectedGoroutine() *proc.G
}

// ProcessManipulation is an interface for changing the execution state of a process.
type ProcessManipulation interface {
71
	ContinueOnce() (trapthread proc.IThread, err error)
D
Derek Parker 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	StepInstruction() error
	SwitchThread(int) error
	SwitchGoroutine(int) error
	RequestManualStop() error
	Halt() error
	Kill() error
	Detach(bool) error
}

// BreakpointManipulation is an interface for managing breakpoints.
type BreakpointManipulation interface {
	Breakpoints() map[uint64]*proc.Breakpoint
	SetBreakpoint(addr uint64, kind proc.BreakpointKind, cond ast.Expr) (*proc.Breakpoint, error)
	ClearBreakpoint(addr uint64) (*proc.Breakpoint, error)
	ClearInternalBreakpoints() error
}

// VariableEval is an interface for dealing with eval scopes.
type VariableEval interface {
91
	FrameToScope(proc.Stackframe) *proc.EvalScope
D
Derek Parker 已提交
92 93
	ConvertEvalScope(gid, frame int) (*proc.EvalScope, error)
}
94

95 96 97
var _ Interface = &native.Process{}
var _ Interface = &core.CoreProcess{}
var _ Interface = &gdbserial.GdbserverProcess{}