未验证 提交 6a85f349 编写于 作者: A Alessandro Arzilli 提交者: GitHub

debugger: report error when switching goroutine is impossible (#2424)

Due to variable shadowing the SwitchGoroutine command never failed.
上级 ea9541b8
......@@ -1023,14 +1023,16 @@ func stoppedGoroutineID(state *api.DebuggerState) (id int) {
func (s *Server) doStepCommand(command string, threadId int) {
// Use SwitchGoroutine to change the current goroutine.
state, err := s.debugger.Command(&api.DebuggerCommand{Name: api.SwitchGoroutine, GoroutineID: threadId}, nil)
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.SwitchGoroutine, GoroutineID: threadId}, nil)
if err != nil {
s.log.Errorf("Error switching goroutines while stepping: %e", err)
s.log.Errorf("Error switching goroutines while stepping: %v", err)
// If we encounter an error, we will have to send a stopped event
// since we already sent the step response.
stopped := &dap.StoppedEvent{Event: *newEvent("stopped")}
stopped.Body.AllThreadsStopped = true
if state != nil {
if state, err := s.debugger.State(false); err != nil {
s.log.Errorf("Error retrieving state: %e", err)
} else {
stopped.Body.ThreadId = stoppedGoroutineID(state)
}
stopped.Body.Reason = "error"
......
......@@ -2202,9 +2202,12 @@ func TestNextAndStep(t *testing.T) {
client.ExpectStepInResponse(t)
expectStop("main.inlineThis", 5)
client.NextRequest(-10000 /*this is ignored*/)
client.NextRequest(-1000)
client.ExpectNextResponse(t)
expectStop("main.inlineThis", 6)
if se := client.ExpectStoppedEvent(t); se.Body.Reason != "error" || se.Body.Text != "unknown goroutine -1000" {
t.Errorf("got %#v, want Reaspon=\"error\", Text=\"unknown goroutine -1000\"", se)
}
handleStop(t, client, 1, "main.inlineThis", 5)
},
disconnect: false,
}})
......
......@@ -1095,7 +1095,8 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
withBreakpointInfo = false
case api.SwitchGoroutine:
d.log.Debugf("switching to goroutine %d", command.GoroutineID)
g, err := proc.FindGoroutine(d.target, command.GoroutineID)
var g *proc.G
g, err = proc.FindGoroutine(d.target, command.GoroutineID)
if err == nil {
err = d.target.SwitchGoroutine(g)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册