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

Respond to basic process commands

上级 8f5190cb
......@@ -4,9 +4,11 @@ import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"github.com/Dparker1990/dbg/command"
"github.com/Dparker1990/dbg/proctl"
)
type term struct {
......@@ -14,16 +16,29 @@ type term struct {
}
func main() {
var (
t = newTerm()
cmds = command.DebugCommands()
)
t := newTerm()
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 {
cmdstr, err := t.promptForInput()
if err != nil {
fmt.Fprint(os.Stderr, "Prompt for input failed.")
os.Exit(1)
printStderrAndDie("Prompt for input failed.\n")
}
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 {
return &term{
stdin: bufio.NewReader(os.Stdin),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册