Modify Step() to not print, delegate to command

This commit is contained in:
Derek Parker
2014-05-27 10:51:38 -05:00
parent 821313d6cf
commit 73ddaa2653
2 changed files with 24 additions and 6 deletions

18
main.go
View File

@ -63,8 +63,24 @@ func printStderrAndDie(args ...interface{}) {
}
func registerProcessCommands(cmds *command.Commands, proc *proctl.DebuggedProcess) {
cmds.Register("step", command.CommandFunc(proc.Step))
cmds.Register("continue", command.CommandFunc(proc.Continue))
cmds.Register("step", func(args ...string) error {
err := proc.Step()
if err != nil {
return err
}
regs, err := proc.Registers()
if err != nil {
return err
}
f, l, _ := proc.GoSymTable.PCToLine(regs.PC())
fmt.Printf("Stopped at: %s:%d\n", f, l)
return nil
})
cmds.Register("break", func(args ...string) error {
fname := args[0]
bp, err := proc.Break(fname)

View File

@ -135,7 +135,11 @@ func (dbp *DebuggedProcess) Step() error {
bp, ok := dbp.PCtoBP(regs.PC())
if ok {
dbp.restoreInstruction(regs.PC(), bp.OriginalData)
err = dbp.restoreInstruction(regs.PC(), bp.OriginalData)
if err != nil {
return err
}
}
err = dbp.handleResult(syscall.PtraceSingleStep(dbp.Pid))
@ -143,11 +147,9 @@ func (dbp *DebuggedProcess) Step() error {
return fmt.Errorf("step failed: ", err.Error())
}
f, l, fn := dbp.GoSymTable.PCToLine(regs.PC())
fmt.Printf("Stopped at: %s %s:%d\n", fn.Name, f, l)
// Restore breakpoint
if ok {
_, err = dbp.Break(bp.FunctionName)
_, err := dbp.Break(bp.FunctionName)
if err != nil {
return err
}