mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 12:59:01 +08:00
Respond to basic process commands
This commit is contained in:
37
main.go
37
main.go
@ -4,9 +4,11 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Dparker1990/dbg/command"
|
"github.com/Dparker1990/dbg/command"
|
||||||
|
"github.com/Dparker1990/dbg/proctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type term struct {
|
type term struct {
|
||||||
@ -14,16 +16,29 @@ type term struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
t := newTerm()
|
||||||
t = newTerm()
|
|
||||||
cmds = command.DebugCommands()
|
if len(os.Args) == 1 {
|
||||||
)
|
printStderrAndDie("You must provide a pid\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
pid, err := strconv.Atoi(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
printStderrAndDie(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgproc, err := proctl.NewDebugProcess(pid)
|
||||||
|
if err != nil {
|
||||||
|
printStderrAndDie("Could not start debugging process:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmds := command.DebugCommands()
|
||||||
|
registerProcessCommands(cmds, dbgproc)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
cmdstr, err := t.promptForInput()
|
cmdstr, err := t.promptForInput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint(os.Stderr, "Prompt for input failed.")
|
printStderrAndDie("Prompt for input failed.\n")
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := cmds.Find(cmdstr)
|
cmd := cmds.Find(cmdstr)
|
||||||
@ -34,6 +49,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printStderrAndDie(args ...interface{}) {
|
||||||
|
fmt.Fprint(os.Stderr, args)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerProcessCommands(cmds *command.Commands, proc *proctl.DebuggedProcess) {
|
||||||
|
cmds.Register("step", proc.Step)
|
||||||
|
cmds.Register("continue", proc.Continue)
|
||||||
|
}
|
||||||
|
|
||||||
func newTerm() *term {
|
func newTerm() *term {
|
||||||
return &term{
|
return &term{
|
||||||
stdin: bufio.NewReader(os.Stdin),
|
stdin: bufio.NewReader(os.Stdin),
|
||||||
|
|||||||
Reference in New Issue
Block a user