proc: Make sure CurrentLoc of G returned by GetG is up to date (#723)

We are already doing this in GoroutinesInfo we should be doing it for
GetG. The main consequence of not doing this is that the CurrentLoc of
DebuggerState.SelectedGoroutine is out of date compared to the location
of the thread running it.
This commit is contained in:
Alessandro Arzilli 2017-02-07 22:44:36 +01:00 committed by Derek Parker
parent 098457e59e
commit 8c96e275d0
2 changed files with 26 additions and 0 deletions

@ -399,6 +399,9 @@ func (thread *Thread) GetG() (g *G, err error) {
g, err = gaddr.parseG()
if err == nil {
g.thread = thread
if loc, err := thread.Location(); err == nil {
g.CurrentLoc = *loc
}
}
return
}

@ -1224,3 +1224,26 @@ func TestClientServer_RestartBreakpointPosition(t *testing.T) {
}
})
}
func TestClientServer_SelectedGoroutineLoc(t *testing.T) {
// CurrentLocation of SelectedGoroutine should reflect what's happening on
// the thread running the goroutine, not the position the goroutine was in
// the last time it was parked.
withTestClient2("testprog", t, func(c service.Client) {
_, err := c.CreateBreakpoint(&api.Breakpoint{FunctionName: "main.main", Line: -11})
assertNoError(err, t, "CreateBreakpoint")
s := <-c.Continue()
assertNoError(s.Err, t, "Continue")
gloc := s.SelectedGoroutine.CurrentLoc
if gloc.PC != s.CurrentThread.PC {
t.Errorf("mismatched PC %#x %#x", gloc.PC, s.CurrentThread.PC)
}
if gloc.File != s.CurrentThread.File || gloc.Line != s.CurrentThread.Line {
t.Errorf("mismatched file:lineno: %s:%d %s:%d", gloc.File, gloc.Line, s.CurrentThread.File, s.CurrentThread.Line)
}
})
}