mirror of
https://github.com/go-delve/delve.git
synced 2025-11-01 12:01:35 +08:00
Add documentation
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user