提交 b35072f3 编写于 作者: D Derek Parker

Respond to basic process commands

上级 8f5190cb
...@@ -4,9 +4,11 @@ import ( ...@@ -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 { ...@@ -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() { ...@@ -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),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册