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
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -21,6 +23,8 @@ func DebugCommands() *Commands {
|
|||||||
return &Commands{cmds}
|
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) {
|
func (c *Commands) Register(cmdstr string, cf cmdfunc) {
|
||||||
c.cmds[cmdstr] = cf
|
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
|
package proctl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -6,6 +8,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Struct representing a debugged process. Holds onto pid, register values,
|
||||||
|
// process struct and process state.
|
||||||
type DebuggedProcess struct {
|
type DebuggedProcess struct {
|
||||||
Pid int
|
Pid int
|
||||||
Regs *syscall.PtraceRegs
|
Regs *syscall.PtraceRegs
|
||||||
@ -13,6 +17,7 @@ type DebuggedProcess struct {
|
|||||||
ProcessState *os.ProcessState
|
ProcessState *os.ProcessState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a new DebuggedProcess struct with sensible defaults.
|
||||||
func NewDebugProcess(pid int) (*DebuggedProcess, error) {
|
func NewDebugProcess(pid int) (*DebuggedProcess, error) {
|
||||||
err := syscall.PtraceAttach(pid)
|
err := syscall.PtraceAttach(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -39,6 +44,7 @@ func NewDebugProcess(pid int) (*DebuggedProcess, error) {
|
|||||||
return &debuggedProc, nil
|
return &debuggedProc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtains register values from the debugged process.
|
||||||
func (dbp *DebuggedProcess) Registers() (*syscall.PtraceRegs, error) {
|
func (dbp *DebuggedProcess) Registers() (*syscall.PtraceRegs, error) {
|
||||||
err := syscall.PtraceGetRegs(dbp.Pid, dbp.Regs)
|
err := syscall.PtraceGetRegs(dbp.Pid, dbp.Regs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,10 +54,12 @@ func (dbp *DebuggedProcess) Registers() (*syscall.PtraceRegs, error) {
|
|||||||
return dbp.Regs, nil
|
return dbp.Regs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Steps through process.
|
||||||
func (dbp *DebuggedProcess) Step() error {
|
func (dbp *DebuggedProcess) Step() error {
|
||||||
return dbp.HandleResult(syscall.PtraceSingleStep(dbp.Pid))
|
return dbp.HandleResult(syscall.PtraceSingleStep(dbp.Pid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Continue process until next breakpoint.
|
||||||
func (dbp *DebuggedProcess) Continue() error {
|
func (dbp *DebuggedProcess) Continue() error {
|
||||||
return dbp.HandleResult(syscall.PtraceCont(dbp.Pid, 0))
|
return dbp.HandleResult(syscall.PtraceCont(dbp.Pid, 0))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user