terminal,service: auto-continue during next and step (#448)

* proc: bugfix: StepInto can not function when temp bps exist

* terminal,service: auto-continue during next and step

Make dlv call continue automatically when a breakpoint is hit on a
different goroutine during a next or step operation.
Added API hooks to implement the other solution to this problem (cancel
the next/step operation if a different breakpoint is hit).

Fixes #387
This commit is contained in:
Alessandro Arzilli
2016-04-25 01:20:02 +02:00
committed by Derek Parker
parent a7a0cc75e1
commit c4e01da5ca
10 changed files with 146 additions and 8 deletions

View File

@ -71,6 +71,7 @@ func (ft *FakeTerminal) AssertExecError(cmdstr, tgterr string) {
}
func withTestTerminal(name string, t testing.TB, fn func(*FakeTerminal)) {
os.Setenv("TERM", "dumb")
listener, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("couldn't start listener: %s\n", err)
@ -398,3 +399,54 @@ func TestOnPrefixLocals(t *testing.T) {
}
})
}
func countOccourences(s string, needle string) int {
count := 0
for {
idx := strings.Index(s, needle)
if idx < 0 {
break
}
count++
s = s[idx+len(needle):]
}
return count
}
func TestIssue387(t *testing.T) {
// a breakpoint triggering during a 'next' operation will interrupt it
withTestTerminal("issue387", t, func(term *FakeTerminal) {
breakpointHitCount := 0
term.MustExec("break dostuff")
for {
outstr, err := term.Exec("continue")
breakpointHitCount += countOccourences(outstr, "issue387.go:8")
t.Log(outstr)
if err != nil {
if strings.Index(err.Error(), "exited") < 0 {
t.Fatalf("Unexpected error executing 'continue': %v", err)
}
break
}
pos := 9
for {
outstr = term.MustExec("next")
breakpointHitCount += countOccourences(outstr, "issue387.go:8")
t.Log(outstr)
if countOccourences(outstr, fmt.Sprintf("issue387.go:%d", pos)) == 0 {
t.Fatalf("did not continue to expected position %d", pos)
}
pos++
if pos > 11 {
break
}
}
}
if breakpointHitCount != 10 {
t.Fatalf("Breakpoint hit wrong number of times, expected 10 got %d", breakpointHitCount)
}
})
}