Print context after step, next or continue
This commit is contained in:
parent
aefbd8f35a
commit
a3612dd10f
@ -3,8 +3,11 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"debug/gosym"
|
"debug/gosym"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -68,7 +71,12 @@ func nullCommand(p *proctl.DebuggedProcess, ars ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cont(p *proctl.DebuggedProcess, ars ...string) error {
|
func cont(p *proctl.DebuggedProcess, ars ...string) error {
|
||||||
return p.Continue()
|
err := p.Continue()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return printcontext(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func step(p *proctl.DebuggedProcess, args ...string) error {
|
func step(p *proctl.DebuggedProcess, args ...string) error {
|
||||||
@ -77,15 +85,7 @@ func step(p *proctl.DebuggedProcess, args ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
regs, err := p.Registers()
|
return printcontext(p)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
f, l, _ := p.GoSymTable.PCToLine(regs.PC())
|
|
||||||
fmt.Printf("Stopped at: %s:%d\n", f, l)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func next(p *proctl.DebuggedProcess, args ...string) error {
|
func next(p *proctl.DebuggedProcess, args ...string) error {
|
||||||
@ -94,15 +94,7 @@ func next(p *proctl.DebuggedProcess, args ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
regs, err := p.Registers()
|
return printcontext(p)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
f, l, _ := p.GoSymTable.PCToLine(regs.PC())
|
|
||||||
fmt.Printf("Stopped at: %s:%d\n", f, l)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func clear(p *proctl.DebuggedProcess, args ...string) error {
|
func clear(p *proctl.DebuggedProcess, args ...string) error {
|
||||||
@ -164,3 +156,40 @@ func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printcontext(p *proctl.DebuggedProcess) error {
|
||||||
|
var context []string
|
||||||
|
|
||||||
|
regs, err := p.Registers()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
f, l, _ := p.GoSymTable.PCToLine(regs.PC())
|
||||||
|
|
||||||
|
fmt.Printf("Stopped at: %s:%d\n", f, l)
|
||||||
|
file, err := os.Open(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
buf := bufio.NewReader(file)
|
||||||
|
for i := 1; i <= l+5; i++ {
|
||||||
|
line, err := buf.ReadString('\n')
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if i >= (l - 5) {
|
||||||
|
if i == l {
|
||||||
|
line = "=>" + line
|
||||||
|
}
|
||||||
|
context = append(context, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(strings.Join(context, " "))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user