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
- func PtraceAttach(pid int) error
- func PtraceCont(tid, sig int) error
- func PtraceDetach(tid, sig int) error
- func PtracePeekUser(tid int, off uintptr) (uintptr, error)
- func PtracePokeUser(tid int, off, addr uintptr) error
- func PtraceSingleStep(tid int) error
- type AMD64
- type Arch
- type Breakpoint
- type BreakpointExistsError
- type EvalScope
- func (scope *EvalScope) DwarfReader() *reader.Reader
- func (scope *EvalScope) EvalExpression(expr string) (*Variable, error)
- func (scope *EvalScope) EvalVariable(name string) (*Variable, error)
- func (scope *EvalScope) FunctionArguments() ([]*Variable, error)
- func (scope *EvalScope) LocalVariables() ([]*Variable, error)
- func (scope *EvalScope) PackageVariables() ([]*Variable, error)
- func (scope *EvalScope) PtrSize() int
- func (scope *EvalScope) SetVariable(name, value string) error
- func (scope *EvalScope) Type(offset dwarf.Offset) (dwarf.Type, error)
- type G
- type GoVersion
- type GoroutineExitingError
- type InvalidAddressError
- type IsNilErr
- type Location
- type M
- type NoBreakpointError
- type NoGError
- type NoReturnAddr
- type NullAddrError
- type OSProcessDetails
- type OSSpecificDetails
- type Process
- func (dbp *Process) ClearBreakpoint(addr uint64) (*Breakpoint, error)
- func (dbp *Process) Continue() error
- func (dbp *Process) ConvertEvalScope(gid, frame int) (*EvalScope, error)
- func (dbp *Process) CurrentBreakpoint() *Breakpoint
- func (dbp *Process) CurrentLocation() (*Location, error)
- func (dbp *Process) Detach(kill bool) (err error)
- func (dbp *Process) DwarfReader() *reader.Reader
- func (dbp *Process) EvalPackageVariable(name string) (*Variable, error)
- func (dbp *Process) Exited() bool
- func (dbp *Process) FindBreakpoint(pc uint64) (*Breakpoint, bool)
- func (dbp *Process) FindBreakpointByID(id int) (*Breakpoint, bool)
- func (dbp *Process) FindFileLocation(fileName string, lineno int) (uint64, error)
- func (dbp *Process) FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error)
- func (dbp *Process) FindGoroutine(gid int) (*G, error)
- func (dbp *Process) Funcs() []gosym.Func
- func (dbp *Process) FunctionEntryToFirstLine(entry uint64) (uint64, error)
- func (dbp *Process) GoroutineLocation(g *G) *Location
- func (dbp *Process) GoroutineStacktrace(g *G, depth int) ([]Stackframe, error)
- func (dbp *Process) GoroutinesInfo() ([]*G, error)
- func (dbp *Process) Halt() (err error)
- func (dbp *Process) Kill() (err error)
- func (dbp *Process) LoadInformation(path string) error
- func (dbp *Process) Next() (err error)
- func (dbp *Process) PC() (uint64, error)
- func (dbp *Process) PCToLine(pc uint64) (string, int, *gosym.Func)
- func (dbp *Process) Registers() (Registers, error)
- func (dbp *Process) RequestManualStop() error
- func (dbp *Process) Running() bool
- func (dbp *Process) SetBreakpoint(addr uint64) (*Breakpoint, error)
- func (dbp *Process) SetTempBreakpoint(addr uint64) (*Breakpoint, error)
- func (dbp *Process) Sources() map[string]*gosym.Obj
- func (dbp *Process) Status() *WaitStatus
- func (dbp *Process) Step() (err error)
- func (dbp *Process) StepInstruction() (err error)
- func (dbp *Process) SwitchGoroutine(gid int) error
- func (dbp *Process) SwitchThread(tid int) error
- type ProcessExitedError
- type Registers
- type Regs
- type StackIterator
- type Stackframe
- type Thread
- func (thread *Thread) Continue() error
- func (thread *Thread) GetG() (g *G, err error)
- func (thread *Thread) Halt() (err error)
- func (thread *Thread) Location() (*Location, error)
- func (t *Thread) PC() (uint64, error)
- func (t *Thread) Registers() (Registers, error)
- func (t *Thread) ReturnAddress() (uint64, error)
- func (thread *Thread) Scope() (*EvalScope, error)
- func (thread *Thread) SetCurrentBreakpoint() error
- func (thread *Thread) SetPC(pc uint64) error
- func (t *Thread) Stacktrace(depth int) ([]Stackframe, error)
- func (thread *Thread) StepInstruction() (err error)
- func (thread *Thread) Stopped() bool
- type ThreadBlockedError
- type Variable
- type WaitStatus
Constants ¶
const ( StatusSleeping = 'S' StatusRunning = 'R' StatusTraceStop = 't' StatusZombie = 'Z' )
Process statuses
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
Variables ¶
This section is empty.
Functions ¶
func PtraceAttach ¶
PtraceAttach executes the sys.PtraceAttach call.
func PtracePeekUser ¶
PtracePeekUser execute ptrace PTRACE_PEEK_USER.
func PtracePokeUser ¶
PtracePokeUser execute ptrace PTRACE_POKE_USER.
func PtraceSingleStep ¶
PtraceSingleStep executes ptrace PTRACE_SINGLE_STEP.
Types ¶
type AMD64 ¶
type AMD64 struct {
// contains filtered or unexported fields
}
AMD64 represents the AMD64 CPU architecture.
func (*AMD64) BreakpointInstruction ¶
BreakpointInstruction returns the Breakpoint instruction for this architecture.
func (*AMD64) BreakpointSize ¶
BreakpointSize returns the size of the breakpoint instruction on this architecture.
func (*AMD64) GStructOffset ¶
GStructOffset returns the offset of the G struct in thread local storage.
func (*AMD64) SetGStructOffset ¶
SetGStructOffset sets the offset of the G struct on the AMD64 arch struct. The offset is depandant on the Go compiler Version and whether or not the target program was externally linked.
type Arch ¶
type Arch interface { SetGStructOffset(ver GoVersion, iscgo bool) PtrSize() int BreakpointInstruction() []byte BreakpointSize() int GStructOffset() uint64 }
Arch defines an interface for representing a CPU architecture.
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. ID int // Monotonically increasing ID. Temp bool // Whether this is a temp breakpoint (for next'ing). // Breakpoint information Tracepoint bool // Tracepoint flag Stacktrace int // Number of stack frames to retrieve Goroutine bool // Retrieve goroutine information Variables []string // Variables to evaluate 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 Cond ast.Expr // When Cond is not nil the breakpoint will be triggered only if evaluating Cond returns true }
Breakpoint represents a breakpoint. Stores information on the break point including the byte of data that originally was stored at that address.
func (*Breakpoint) Clear ¶
func (bp *Breakpoint) Clear(thread *Thread) (*Breakpoint, error)
Clear this breakpoint appropriately depending on whether it is a hardware or software breakpoint.
func (*Breakpoint) String ¶
func (bp *Breakpoint) String() string
type BreakpointExistsError ¶
type BreakpointExistsError struct {
// contains filtered or unexported fields
}
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 EvalScope ¶
EvalScope is the scope for variable evaluation. Contains the thread, current location (PC), and canonical frame address.
func (*EvalScope) DwarfReader ¶
DwarfReader returns the DwarfReader containing the Dwarf information for the target process.
func (*EvalScope) EvalExpression ¶
EvalExpression returns the value of the given expression.
func (*EvalScope) EvalVariable ¶
EvalVariable returns the value of the given expression (backwards compatibility).
func (*EvalScope) FunctionArguments ¶
FunctionArguments returns the name, value, and type of all current function arguments.
func (*EvalScope) LocalVariables ¶
LocalVariables returns all local variables from the current function scope.
func (*EvalScope) PackageVariables ¶
PackageVariables returns the name, value, and type of all package variables in the application.
func (*EvalScope) SetVariable ¶
SetVariable sets the value of the named variable
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. GoPC uint64 // PC of 'go' statement that created this goroutine. WaitReason string // Reason for goroutine being parked. Status uint64 // Information on goroutine location CurrentLoc Location // PC of entry to top-most deferred function. DeferPC uint64 // contains filtered or unexported fields }
G represents a runtime G (goroutine) structure (at least the fields that Delve is interested in).
func (*G) ChanRecvBlocked ¶
ChanRecvBlocked returns whether the goroutine is blocked on a channel read operation.
func (*G) UserCurrent ¶
UserCurrent returns the location the users code is at, or was at before entering a runtime function.
type GoVersion ¶
GoVersion represents the Go version of the Go compiler version used to compile the target binary.
func (*GoVersion) AfterOrEqual ¶
AfterOrEqual returns whether one GoVersion is after or equal to the other.
type GoroutineExitingError ¶
type GoroutineExitingError struct {
// contains filtered or unexported fields
}
GoroutineExitingError is returned when the goroutine specified by `goid` is in the process of exiting.
func (GoroutineExitingError) Error ¶
func (ge GoroutineExitingError) Error() string
type InvalidAddressError ¶
type InvalidAddressError struct {
// contains filtered or unexported fields
}
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.
type Location ¶
Location represents the location of a thread. Holds information on the current instruction address, the source file:line, and the function.
type M ¶
type M struct {
// contains filtered or unexported fields
}
M represents a runtime M (OS thread) structure.
type NoBreakpointError ¶
type NoBreakpointError struct {
// contains filtered or unexported fields
}
NoBreakpointError is returned when trying to clear a breakpoint that does not exist.
func (NoBreakpointError) Error ¶
func (nbp NoBreakpointError) 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.
type NoReturnAddr ¶
type NoReturnAddr struct {
// contains filtered or unexported fields
}
NoReturnAddr is returned when return address could not be found during stack tracae.
func (NoReturnAddr) Error ¶
func (nra NoReturnAddr) Error() string
type NullAddrError ¶
type NullAddrError struct{}
NullAddrError is an error for a null address.
func (NullAddrError) Error ¶
func (n NullAddrError) Error() string
type OSProcessDetails ¶
type OSProcessDetails struct {
// contains filtered or unexported fields
}
OSProcessDetails contains Linux specific process details.
type OSSpecificDetails ¶
type OSSpecificDetails struct {
// contains filtered or unexported fields
}
OSSpecificDetails hold Linux specific process details.
type Process ¶
type Process struct { Pid int // Process Pid Process *os.Process // Pointer to process struct for the actual process we are debugging // Breakpoint table, holds information on breakpoints. // Maps instruction address to Breakpoint struct. Breakpoints map[uint64]*Breakpoint // List of threads mapped as such: pid -> *Thread Threads map[int]*Thread // Active thread CurrentThread *Thread // Goroutine that will be used by default to set breakpoint, eval variables, etc... // Normally SelectedGoroutine is CurrentThread.GetG, it will not be only if SwitchGoroutine is called with a goroutine that isn't attached to a thread SelectedGoroutine *G // contains filtered or unexported fields }
Process represents all of the information the debugger is holding onto regarding the process we are debugging.
func Launch ¶
Launch creates and begins debugging a new process. First entry in `cmd` is the program to run, and then rest are the arguments to be supplied to that process.
func New ¶
New returns an initialized Process struct. Before returning, it will also launch a goroutine in order to handle ptrace(2) functions. For more information, see the documentation on `handlePtraceFuncs`.
func (*Process) ClearBreakpoint ¶
func (dbp *Process) ClearBreakpoint(addr uint64) (*Breakpoint, error)
ClearBreakpoint clears the breakpoint at addr.
func (*Process) Continue ¶
Continue continues execution of the debugged process. It will continue until it hits a breakpoint or is otherwise stopped.
func (*Process) ConvertEvalScope ¶
ConvertEvalScope returns a new EvalScope in the context of the specified goroutine ID and stack frame.
func (*Process) CurrentBreakpoint ¶
func (dbp *Process) CurrentBreakpoint() *Breakpoint
CurrentBreakpoint returns the breakpoint the current thread is stopped at.
func (*Process) CurrentLocation ¶
CurrentLocation returns the location of the current thread.
func (*Process) DwarfReader ¶
DwarfReader returns a reader for the dwarf data
func (*Process) EvalPackageVariable ¶
EvalPackageVariable will evaluate the package level variable specified by 'name'.
func (*Process) FindBreakpoint ¶
func (dbp *Process) FindBreakpoint(pc uint64) (*Breakpoint, bool)
FindBreakpoint finds the breakpoint for the given pc.
func (*Process) FindBreakpointByID ¶
func (dbp *Process) FindBreakpointByID(id int) (*Breakpoint, bool)
FindBreakpointByID finds the breakpoint for the given ID.
func (*Process) FindFileLocation ¶
FindFileLocation returns the PC for a given file:line.
func (*Process) FindFunctionLocation ¶
func (dbp *Process) FindFunctionLocation(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 (*Process) FindGoroutine ¶
FindGoroutine returns a G struct representing the goroutine specified by `gid`.
func (*Process) FunctionEntryToFirstLine ¶
func (*Process) GoroutineLocation ¶
GoroutineLocation returns the location of the given goroutine.
func (*Process) GoroutineStacktrace ¶
func (dbp *Process) GoroutineStacktrace(g *G, depth int) ([]Stackframe, error)
GoroutineStacktrace returns the stack trace for a goroutine. Note the locations in the array are return addresses not call addresses.
func (*Process) GoroutinesInfo ¶
GoroutinesInfo returns an array of G structures representing the information Delve cares about from the internal runtime G structure.
func (*Process) LoadInformation ¶
LoadInformation finds the executable and then uses it to parse the following information: * Dwarf .debug_frame section * Dwarf .debug_line section * Go symbol table.
func (*Process) Registers ¶
Registers obtains register values from the "current" thread of the traced process.
func (*Process) RequestManualStop ¶
RequestManualStop sets the `halt` flag and sends SIGSTOP to all threads.
func (*Process) SetBreakpoint ¶
func (dbp *Process) SetBreakpoint(addr uint64) (*Breakpoint, error)
SetBreakpoint sets a breakpoint at addr, and stores it in the process wide break point table. Setting a break point must be thread specific due to ptrace actions needing the thread to be in a signal-delivery-stop.
func (*Process) SetTempBreakpoint ¶
func (dbp *Process) SetTempBreakpoint(addr uint64) (*Breakpoint, error)
SetTempBreakpoint sets a temp breakpoint. Used during 'next' operations.
func (*Process) Status ¶
func (dbp *Process) Status() *WaitStatus
Status returns the status of the current main thread context.
func (*Process) Step ¶
Step will continue until another source line is reached. Will step into functions.
func (*Process) StepInstruction ¶
StepInstruction will continue the current thread for exactly one instruction. This method affects only the thread asssociated with the selected goroutine. All other threads will remain stopped.
func (*Process) SwitchGoroutine ¶
SwitchGoroutine changes from current thread to the thread running the specified goroutine.
func (*Process) SwitchThread ¶
SwitchThread changes from current thread to the thread specified by `tid`.
type ProcessExitedError ¶
ProcessExitedError indicates that the process has exited and contains both process id and exit status.
func (ProcessExitedError) Error ¶
func (pe ProcessExitedError) Error() string
type Registers ¶
type Registers interface { PC() uint64 SP() uint64 CX() uint64 TLS() uint64 SetPC(*Thread, uint64) error String() string }
Registers is an interface for a generic register type. The interface encapsulates the generic values / actions we need independant of arch. The concrete register types will be different depending on OS/Arch.
type Regs ¶
type Regs struct {
// contains filtered or unexported fields
}
Regs is a wrapper for sys.PtraceRegs.
type StackIterator ¶
type StackIterator struct {
// contains filtered or unexported fields
}
StackIterator holds information required to iterate and walk the program stack.
func (*StackIterator) Err ¶
func (it *StackIterator) Err() error
Err returns the error encountered during stack iteration.
func (*StackIterator) Frame ¶
func (it *StackIterator) Frame() Stackframe
Frame returns the frame the iterator is pointing at.
func (*StackIterator) Next ¶
func (it *StackIterator) Next() bool
Next points the iterator to the next stack frame.
type Stackframe ¶
type Stackframe struct { // Address the function above this one on the call stack will return to. Current Location // Address of the call instruction for the function above on the call stack. Call Location CFA int64 Ret uint64 }
Stackframe represents a frame in a system stack.
func (*Stackframe) Scope ¶
func (frame *Stackframe) Scope(thread *Thread) *EvalScope
Scope returns a new EvalScope using this frame.
type Thread ¶
type Thread struct { ID int // Thread ID or mach port Status *WaitStatus // Status returned from last wait call CurrentBreakpoint *Breakpoint // Breakpoint thread is currently stopped at BreakpointConditionMet bool // Output of evaluating the breakpoint's condition BreakpointConditionError error // Error evaluating the breakpoint's condition // contains filtered or unexported fields }
Thread represents a single thread in the traced process ID represents the thread id or port, Process holds a reference to the Process struct that contains info on the process as a whole, and Status represents the last result of a `wait` call on this thread.
func (*Thread) Continue ¶
Continue the execution of this thread.
If we are currently at a breakpoint, we'll clear it first and then resume execution. Thread will continue until it hits a breakpoint or is signaled.
func (*Thread) GetG ¶
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 (*Thread) Halt ¶
Halt stops this thread from executing. Actual implementation is OS dependant. Look in OS thread file.
func (*Thread) Location ¶
Location returns the threads location, including the file:line of the corresponding source code, the function we're in and the current instruction address.
func (*Thread) ReturnAddress ¶
ReturnAddress returns the return address of the function this thread is executing.
func (*Thread) SetCurrentBreakpoint ¶
SetCurrentBreakpoint sets the current breakpoint that this thread is stopped at as CurrentBreakpoint on the thread struct.
func (*Thread) Stacktrace ¶
func (t *Thread) Stacktrace(depth int) ([]Stackframe, error)
Stacktrace returns the stack trace for thread. Note the locations in the array are return addresses not call addresses.
func (*Thread) StepInstruction ¶
StepInstruction steps a single instruction.
Executes exactly one instruction and then returns. If the thread is at a breakpoint, we first clear it, execute the instruction, and then replace the breakpoint. Otherwise we simply execute the next instruction.
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 Variable ¶
type Variable struct { Addr uintptr OnlyAddr bool Name string DwarfType dwarf.Type RealType dwarf.Type Kind reflect.Kind Value constant.Value Len int64 Cap int64 // 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 // 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) TypeString ¶
TypeString returns the string representation of the type of this variable.
type WaitStatus ¶
type WaitStatus sys.WaitStatus