Documentation ¶
Overview ¶
proctl is a low-level package that provides methods to manipulate the process we are debugging, and methods to read and write from the virtual memory of the process.
proctl implements the core features of this debugger, including all process manipulation (step, next, continue, halt) as well as providing methods to evaluate variables and read them from the virtual memory of the process we are debugging.
Index ¶
- Constants
- 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 DebuggedProcess
- func (dbp *DebuggedProcess) Break(addr uint64) (*BreakPoint, error)
- func (dbp *DebuggedProcess) BreakByLocation(loc string) (*BreakPoint, error)
- func (dbp *DebuggedProcess) BreakpointExists(addr uint64) bool
- func (dbp *DebuggedProcess) CallFn(name string, fn func() error) error
- func (dbp *DebuggedProcess) Clear(addr uint64) (*BreakPoint, error)
- func (dbp *DebuggedProcess) ClearByLocation(loc string) (*BreakPoint, error)
- func (dbp *DebuggedProcess) Continue() error
- func (dbp *DebuggedProcess) CurrentBreakpoint() *BreakPoint
- func (dbp *DebuggedProcess) DwarfReader() *reader.Reader
- func (dbp *DebuggedProcess) EvalSymbol(name string) (*Variable, error)
- func (dbp *DebuggedProcess) Exited() bool
- func (dbp *DebuggedProcess) FindBreakpoint(pc uint64) (*BreakPoint, bool)
- func (dbp *DebuggedProcess) FindLocation(str string) (uint64, error)
- func (dbp *DebuggedProcess) Funcs() []gosym.Func
- func (dbp *DebuggedProcess) GoroutinesInfo() ([]*G, error)
- func (dbp *DebuggedProcess) Halt() (err error)
- func (dbp *DebuggedProcess) LoadInformation(path string) error
- func (dbp *DebuggedProcess) Next() error
- func (dbp *DebuggedProcess) PC() (uint64, error)
- func (dbp *DebuggedProcess) PCToLine(pc uint64) (string, int, *gosym.Func)
- func (dbp *DebuggedProcess) Registers() (Registers, error)
- func (dbp *DebuggedProcess) RequestManualStop() error
- func (dbp *DebuggedProcess) Running() bool
- func (dbp *DebuggedProcess) Sources() map[string]*gosym.Obj
- func (dbp *DebuggedProcess) Status() *sys.WaitStatus
- func (dbp *DebuggedProcess) Step() (err error)
- func (dbp *DebuggedProcess) SwitchThread(tid int) error
- func (dbp *DebuggedProcess) TempBreak(addr uint64) (*BreakPoint, error)
- type G
- type GoroutineExitingError
- type InvalidAddressError
- type M
- type ManualStopError
- type NoBreakPointError
- type NoGError
- type NullAddrError
- type OSProcessDetails
- type OSSpecificDetails
- type ProcessExitedError
- type Registers
- type Regs
- type ThreadContext
- func (thread *ThreadContext) AllM() ([]*M, error)
- func (thread *ThreadContext) Break(addr uint64) (*BreakPoint, error)
- func (thread *ThreadContext) CallFn(name string, fn func() error) error
- func (thread *ThreadContext) Clear(addr uint64) (*BreakPoint, error)
- func (thread *ThreadContext) Continue() error
- func (thread *ThreadContext) EvalSymbol(name string) (*Variable, error)
- func (thread *ThreadContext) FunctionArguments() ([]*Variable, error)
- func (t *ThreadContext) Halt() error
- func (thread *ThreadContext) LocalVariables() ([]*Variable, error)
- func (thread *ThreadContext) Next() (err error)
- func (thread *ThreadContext) PC() (uint64, error)
- func (thread *ThreadContext) PackageVariables() ([]*Variable, error)
- func (thread *ThreadContext) Registers() (Registers, error)
- func (thread *ThreadContext) ReturnAddress() (uint64, error)
- func (thread *ThreadContext) SetPC(pc uint64) error
- func (thread *ThreadContext) Step() (err error)
- func (thread *ThreadContext) TempBreak(addr uint64) (*BreakPoint, error)
- type Variable
Constants ¶
const ( STATUS_SLEEPING = 'S' STATUS_RUNNING = 'R' STATUS_TRACE_STOP = 't' )
const ( ChanRecv = "chan receive" ChanSend = "chan send" )
Variables ¶
This section is empty.
Functions ¶
func PtraceCont ¶
func PtraceDetach ¶
func PtracePokeUser ¶
func PtraceSingleStep ¶
Types ¶
type AMD64 ¶
type AMD64 struct {
// contains filtered or unexported fields
}
func (*AMD64) BreakpointInstruction ¶
func (*AMD64) BreakpointSize ¶
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). // contains filtered or unexported fields }
Represents a single 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 *ThreadContext) (*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
}
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 DebuggedProcess ¶
type DebuggedProcess struct { Pid int Process *os.Process HWBreakPoints [4]*BreakPoint BreakPoints map[uint64]*BreakPoint Threads map[int]*ThreadContext CurrentThread *ThreadContext // contains filtered or unexported fields }
Struct representing a debugged process. Holds onto pid, register values, process struct and process state.
func Attach ¶
func Attach(pid int) (*DebuggedProcess, error)
Attach to an existing process with the given PID.
func Launch ¶
func Launch(cmd []string) (*DebuggedProcess, error)
Create and begin 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 (*DebuggedProcess) Break ¶
func (dbp *DebuggedProcess) Break(addr uint64) (*BreakPoint, error)
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.
Depending on hardware support, Delve will choose to either set a hardware or software breakpoint. Essentially, if the hardware supports it, and there are free debug registers, Delve will set a hardware breakpoint. Otherwise we fall back to software breakpoints, which are a bit more work for us.
func (*DebuggedProcess) BreakByLocation ¶
func (dbp *DebuggedProcess) BreakByLocation(loc string) (*BreakPoint, error)
Sets a breakpoint by location string (function, file+line, address)
func (*DebuggedProcess) BreakpointExists ¶
func (dbp *DebuggedProcess) BreakpointExists(addr uint64) bool
Returns whether or not a breakpoint has been set for the given address.
func (*DebuggedProcess) CallFn ¶
func (dbp *DebuggedProcess) CallFn(name string, fn func() error) error
func (*DebuggedProcess) Clear ¶
func (dbp *DebuggedProcess) Clear(addr uint64) (*BreakPoint, error)
Clears a breakpoint in the current thread.
func (*DebuggedProcess) ClearByLocation ¶
func (dbp *DebuggedProcess) ClearByLocation(loc string) (*BreakPoint, error)
Clears a breakpoint by location (function, file+line, address, breakpoint id)
func (*DebuggedProcess) CurrentBreakpoint ¶
func (dbp *DebuggedProcess) CurrentBreakpoint() *BreakPoint
Returns the PC of the current thread.
func (*DebuggedProcess) DwarfReader ¶
func (dbp *DebuggedProcess) DwarfReader() *reader.Reader
Returns a reader for the dwarf data
func (*DebuggedProcess) EvalSymbol ¶
func (dbp *DebuggedProcess) EvalSymbol(name string) (*Variable, error)
Returns the value of the named symbol.
func (*DebuggedProcess) Exited ¶
func (dbp *DebuggedProcess) Exited() bool
Returns whether or not Delve thinks the debugged process has exited.
func (*DebuggedProcess) FindBreakpoint ¶
func (dbp *DebuggedProcess) FindBreakpoint(pc uint64) (*BreakPoint, bool)
Finds the breakpoint for the given pc.
func (*DebuggedProcess) FindLocation ¶
func (dbp *DebuggedProcess) FindLocation(str string) (uint64, error)
Find a location by string (file+line, function, breakpoint id, addr)
func (*DebuggedProcess) Funcs ¶
func (dbp *DebuggedProcess) Funcs() []gosym.Func
Returns list of functions present in the debugged program.
func (*DebuggedProcess) GoroutinesInfo ¶
func (dbp *DebuggedProcess) GoroutinesInfo() ([]*G, error)
Returns an array of G structures representing the information Delve cares about from the internal runtime G structure.
func (*DebuggedProcess) LoadInformation ¶
func (dbp *DebuggedProcess) LoadInformation(path string) error
Finds the executable and then uses it to parse the following information: * Dwarf .debug_frame section * Dwarf .debug_line section * Go symbol table.
func (*DebuggedProcess) PC ¶
func (dbp *DebuggedProcess) PC() (uint64, error)
Returns the PC of the current thread.
func (*DebuggedProcess) Registers ¶
func (dbp *DebuggedProcess) Registers() (Registers, error)
Obtains register values from what Delve considers to be the current thread of the traced process.
func (*DebuggedProcess) RequestManualStop ¶
func (dbp *DebuggedProcess) RequestManualStop() error
Sends out a request that the debugged process halt execution. Sends SIGSTOP to all threads.
func (*DebuggedProcess) Running ¶
func (dbp *DebuggedProcess) Running() bool
Returns whether or not Delve thinks the debugged process is currently executing.
func (*DebuggedProcess) Sources ¶
func (dbp *DebuggedProcess) Sources() map[string]*gosym.Obj
Returns list of source files that comprise the debugged binary.
func (*DebuggedProcess) Status ¶
func (dbp *DebuggedProcess) Status() *sys.WaitStatus
Returns the status of the current main thread context.
func (*DebuggedProcess) Step ¶
func (dbp *DebuggedProcess) Step() (err error)
Single step, will execute a single instruction.
func (*DebuggedProcess) SwitchThread ¶
func (dbp *DebuggedProcess) SwitchThread(tid int) error
Change from current thread to the thread specified by `tid`.
func (*DebuggedProcess) TempBreak ¶
func (dbp *DebuggedProcess) TempBreak(addr uint64) (*BreakPoint, error)
Sets a temp breakpoint, for the 'next' command.
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. // Information on goroutine location. File string Line int Func *gosym.Func }
Represents a runtime G (goroutine) structure (at least the fields that Delve is interested in).
func (*G) ChanRecvBlocked ¶
Returns whether the goroutine is blocked on a channel read operation.
type GoroutineExitingError ¶
type GoroutineExitingError struct {
// contains filtered or unexported fields
}
Go routine is 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 M ¶
type M struct {
// contains filtered or unexported fields
}
Represents a runtime M (OS thread) structure.
type ManualStopError ¶
type ManualStopError struct{}
A ManualStopError happens when the user triggers a manual stop via SIGERM.
func (ManualStopError) Error ¶
func (mse ManualStopError) Error() string
type NoBreakPointError ¶
type NoBreakPointError struct {
// contains filtered or unexported fields
}
Error thrown when trying to clear a breakpoint that does not exist.
func (NoBreakPointError) Error ¶
func (nbp NoBreakPointError) Error() string
type NullAddrError ¶
type NullAddrError struct{}
func (NullAddrError) Error ¶
func (n NullAddrError) Error() string
type OSSpecificDetails ¶
type OSSpecificDetails struct {
// contains filtered or unexported fields
}
Not actually used, but necessary to be defined.
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 SetPC(*ThreadContext, uint64) error }
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 ThreadContext ¶
type ThreadContext struct { Id int Process *DebuggedProcess Status *sys.WaitStatus CurrentBreakpoint *BreakPoint // contains filtered or unexported fields }
ThreadContext represents a single thread in the traced process Id represents the thread id, Process holds a reference to the DebuggedProcess struct that contains info on the process as a whole, and Status represents the last result of a `wait` call on this thread.
func (*ThreadContext) AllM ¶
func (thread *ThreadContext) AllM() ([]*M, error)
Parses and returns select info on the internal M data structures used by the Go scheduler.
func (*ThreadContext) Break ¶
func (thread *ThreadContext) Break(addr uint64) (*BreakPoint, error)
Set breakpoint using this thread.
func (*ThreadContext) CallFn ¶
func (thread *ThreadContext) CallFn(name string, fn func() error) error
Call a function named `name`. This is currently _NOT_ safe.
func (*ThreadContext) Clear ¶
func (thread *ThreadContext) Clear(addr uint64) (*BreakPoint, error)
Clear breakpoint using this thread.
func (*ThreadContext) Continue ¶
func (thread *ThreadContext) Continue() error
Continue the execution of this thread. This method takes software breakpoints into consideration and ensures that we step over any breakpoints. It will restore the instruction, step, and then restore the breakpoint and continue.
func (*ThreadContext) EvalSymbol ¶
func (thread *ThreadContext) EvalSymbol(name string) (*Variable, error)
Returns the value of the named symbol.
func (*ThreadContext) FunctionArguments ¶
func (thread *ThreadContext) FunctionArguments() ([]*Variable, error)
FunctionArguments returns the name, value, and type of all current function arguments.
func (*ThreadContext) Halt ¶
func (t *ThreadContext) Halt() error
func (*ThreadContext) LocalVariables ¶
func (thread *ThreadContext) LocalVariables() ([]*Variable, error)
LocalVariables returns all local variables from the current function scope.
func (*ThreadContext) Next ¶
func (thread *ThreadContext) Next() (err error)
Step to next source line.
Next will step over functions, and will follow through to the return address of a function.
This functionality is implemented by finding all possible next lines and setting a breakpoint at them. Once we've set a breakpoint at each potential line, we continue the thread.
func (*ThreadContext) PC ¶
func (thread *ThreadContext) PC() (uint64, error)
Returns the current PC for this thread.
func (*ThreadContext) PackageVariables ¶
func (thread *ThreadContext) PackageVariables() ([]*Variable, error)
PackageVariables returns the name, value, and type of all package variables in the application.
func (*ThreadContext) Registers ¶
func (thread *ThreadContext) Registers() (Registers, error)
Obtains register values from the debugged process.
func (*ThreadContext) ReturnAddress ¶
func (thread *ThreadContext) ReturnAddress() (uint64, error)
Takes an offset from RSP and returns the address of the instruction the currect function is going to return to.
func (*ThreadContext) SetPC ¶
func (thread *ThreadContext) SetPC(pc uint64) error
Sets the PC for this thread.
func (*ThreadContext) Step ¶
func (thread *ThreadContext) Step() (err error)
Single steps this thread a single instruction, ensuring that we correctly handle the likely case that we are at a breakpoint.
func (*ThreadContext) TempBreak ¶
func (thread *ThreadContext) TempBreak(addr uint64) (*BreakPoint, error)
Set breakpoint using this thread.