Add documentation

This commit is contained in:
Derek Parker
2014-05-21 10:23:14 -05:00
parent 2d8cc08513
commit a67f21fee4
2 changed files with 12 additions and 0 deletions

View File

@ -1,3 +1,5 @@
// Package command implements functions for responding to user
// input and dispatching to appropriate backend commands.
package command
import (
@ -21,6 +23,8 @@ func DebugCommands() *Commands {
return &Commands{cmds}
}
// Register custom commands. Expects cf to be a func of type cmdfunc,
// returning only an error.
func (c *Commands) Register(cmdstr string, cf cmdfunc) {
c.cmds[cmdstr] = cf
}

View File

@ -1,3 +1,5 @@
// Package proctl provides functions for attaching to and manipulating
// a process during the debug session.
package proctl
import (
@ -6,6 +8,8 @@ import (
"syscall"
)
// Struct representing a debugged process. Holds onto pid, register values,
// process struct and process state.
type DebuggedProcess struct {
Pid int
Regs *syscall.PtraceRegs
@ -13,6 +17,7 @@ type DebuggedProcess struct {
ProcessState *os.ProcessState
}
// Returns a new DebuggedProcess struct with sensible defaults.
func NewDebugProcess(pid int) (*DebuggedProcess, error) {
err := syscall.PtraceAttach(pid)
if err != nil {
@ -39,6 +44,7 @@ func NewDebugProcess(pid int) (*DebuggedProcess, error) {
return &debuggedProc, nil
}
// Obtains register values from the debugged process.
func (dbp *DebuggedProcess) Registers() (*syscall.PtraceRegs, error) {
err := syscall.PtraceGetRegs(dbp.Pid, dbp.Regs)
if err != nil {
@ -48,10 +54,12 @@ func (dbp *DebuggedProcess) Registers() (*syscall.PtraceRegs, error) {
return dbp.Regs, nil
}
// Steps through process.
func (dbp *DebuggedProcess) Step() error {
return dbp.HandleResult(syscall.PtraceSingleStep(dbp.Pid))
}
// Continue process until next breakpoint.
func (dbp *DebuggedProcess) Continue() error {
return dbp.HandleResult(syscall.PtraceCont(dbp.Pid, 0))
}