proctl

package
v0.0.0-...-123264b Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2015 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package proctl provides functions for attaching to and manipulating a process during the debug session.

Index

Constants

View Source
const (
	STATUS_SLEEPING   = 'S'
	STATUS_RUNNING    = 'R'
	STATUS_TRACE_STOP = 't'
)

Variables

This section is empty.

Functions

func PtraceCont

func PtraceCont(tid, sig int) error

func PtracePeekUser

func PtracePeekUser(tid int, off uintptr) (uintptr, error)

func PtracePokeUser

func PtracePokeUser(tid int, off, addr uintptr) error

func PtraceSingleStep

func PtraceSingleStep(tid int) error

Types

type BreakPoint

type BreakPoint struct {
	FunctionName string
	File         string
	Line         int
	Addr         uint64
	OriginalData []byte
	ID           int
	Temp         bool
}

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

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
	Dwarf         *dwarf.Data
	GoSymTable    *gosym.Table
	FrameEntries  frame.FrameDescriptionEntries
	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) 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) Continue

func (dbp *DebuggedProcess) Continue() error

Resume process.

func (*DebuggedProcess) CurrentPC

func (dbp *DebuggedProcess) CurrentPC() (uint64, error)

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) FindLocation

func (dbp *DebuggedProcess) FindLocation(str string) (uint64, error)

Find a location by string (file+line, function, breakpoint id, addr)

func (*DebuggedProcess) Halt

func (dbp *DebuggedProcess) Halt() (err error)

func (*DebuggedProcess) LoadInformation

func (dbp *DebuggedProcess) LoadInformation() error

Finds the executable from /proc/<pid>/exe and then uses that to parse the following information: * Dwarf .debug_frame section * Dwarf .debug_line section * Go symbol table.

func (*DebuggedProcess) Next

func (dbp *DebuggedProcess) Next() error

Step over function calls.

func (*DebuggedProcess) PrintGoroutinesInfo

func (dbp *DebuggedProcess) PrintGoroutinesInfo() error

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()

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) 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)

Steps through process.

func (*DebuggedProcess) SwitchThread

func (dbp *DebuggedProcess) SwitchThread(tid int) error

Change from current thread to the thread specified by `tid`.

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
}

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 OSProcessDetails

type OSProcessDetails interface{}

Not actually needed for Linux.

type OSSpecificDetails

type OSSpecificDetails interface{}

Not actually used, but necessary to be defined.

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 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 Regs

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

func (*Regs) PC

func (r *Regs) PC() uint64

func (*Regs) SP

func (r *Regs) SP() uint64

func (*Regs) SetPC

func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error

type ThreadContext

type ThreadContext struct {
	Id      int
	Process *DebuggedProcess
	Status  *sys.WaitStatus
	// 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) 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) CurrentPC

func (thread *ThreadContext) CurrentPC() (uint64, error)

Returns the current PC for this thread.

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. Next is implemented on the thread context, however during the course of this function running, it's very likely that the goroutine our M is executing will switch to another M, therefore this function cannot assume all execution will happen on this thread in the traced process.

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) ReturnAddressFromOffset

func (thread *ThreadContext) ReturnAddressFromOffset(offset int64) uint64

Takes an offset from RSP and returns the address of the instruction the currect function is going to return to.

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.

type Variable

type Variable struct {
	Name  string
	Value string
	Type  string
}

Jump to

Keyboard shortcuts

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