mirror of
https://github.com/go-delve/delve.git
synced 2025-11-01 12:01:35 +08:00
Respond to basic process commands
This commit is contained in:
37
main.go
37
main.go
@ -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),
|
||||
|
||||
Reference in New Issue
Block a user