mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-04 06:32:16 +08:00 
			
		
		
		
	service/dap: send terminated event when disconnecting (#2587)
* service/dap: send terminated event when disconnecting If the program terminates while disconnecting, either because it was killed or otherwise, send a terminated event.
This commit is contained in:
		@ -637,6 +637,7 @@ func TestDap(t *testing.T) {
 | 
				
			|||||||
	client := daptest.NewClient(listenAddr)
 | 
						client := daptest.NewClient(listenAddr)
 | 
				
			||||||
	client.DisconnectRequest()
 | 
						client.DisconnectRequest()
 | 
				
			||||||
	client.ExpectDisconnectResponse(t)
 | 
						client.ExpectDisconnectResponse(t)
 | 
				
			||||||
 | 
						client.ExpectTerminatedEvent(t)
 | 
				
			||||||
	if _, err := client.ReadMessage(); err != io.EOF {
 | 
						if _, err := client.ReadMessage(); err != io.EOF {
 | 
				
			||||||
		t.Errorf("got %q, want \"EOF\"\n", err)
 | 
							t.Errorf("got %q, want \"EOF\"\n", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -972,6 +972,10 @@ func (s *Server) onDisconnectRequest(request *dap.DisconnectRequest) {
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		s.send(&dap.DisconnectResponse{Response: *newResponse(request.Request)})
 | 
							s.send(&dap.DisconnectResponse{Response: *newResponse(request.Request)})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// The debugging session has ended, so we send a terminated event.
 | 
				
			||||||
 | 
						s.send(&dap.TerminatedEvent{
 | 
				
			||||||
 | 
							Event: *newEvent("terminated"),
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// stopDebugSession is called from Stop (main goroutine) and
 | 
					// stopDebugSession is called from Stop (main goroutine) and
 | 
				
			||||||
 | 
				
			|||||||
@ -246,6 +246,7 @@ func TestLaunchStopOnEntry(t *testing.T) {
 | 
				
			|||||||
		if dResp.Seq != 0 || dResp.RequestSeq != 13 {
 | 
							if dResp.Seq != 0 || dResp.RequestSeq != 13 {
 | 
				
			||||||
			t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=13", dResp)
 | 
								t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=13", dResp)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							client.ExpectTerminatedEvent(t)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -377,6 +378,7 @@ func TestAttachStopOnEntry(t *testing.T) {
 | 
				
			|||||||
		client.CheckOutputEvent(t, msg)
 | 
							client.CheckOutputEvent(t, msg)
 | 
				
			||||||
		msg = expectMessageFilterStopped(t, client)
 | 
							msg = expectMessageFilterStopped(t, client)
 | 
				
			||||||
		client.CheckDisconnectResponse(t, msg)
 | 
							client.CheckDisconnectResponse(t, msg)
 | 
				
			||||||
 | 
							client.ExpectTerminatedEvent(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// If this call to KeepAlive isn't here there's a chance that stdout will
 | 
							// If this call to KeepAlive isn't here there's a chance that stdout will
 | 
				
			||||||
		// be garbage collected (since it is no longer alive long before this
 | 
							// be garbage collected (since it is no longer alive long before this
 | 
				
			||||||
@ -452,6 +454,7 @@ func TestContinueOnEntry(t *testing.T) {
 | 
				
			|||||||
		if dResp.Seq != 0 || dResp.RequestSeq != 8 {
 | 
							if dResp.Seq != 0 || dResp.RequestSeq != 8 {
 | 
				
			||||||
			t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=8", dResp)
 | 
								t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=8", dResp)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							client.ExpectTerminatedEvent(t)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -591,6 +594,7 @@ func TestPreSetBreakpoint(t *testing.T) {
 | 
				
			|||||||
		client.ExpectOutputEventProcessExited(t, 0)
 | 
							client.ExpectOutputEventProcessExited(t, 0)
 | 
				
			||||||
		client.ExpectOutputEventDetaching(t)
 | 
							client.ExpectOutputEventDetaching(t)
 | 
				
			||||||
		client.ExpectDisconnectResponse(t)
 | 
							client.ExpectDisconnectResponse(t)
 | 
				
			||||||
 | 
							client.ExpectTerminatedEvent(t)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -3854,6 +3858,7 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm
 | 
				
			|||||||
				client.ExpectOutputEventDetachingKill(t)
 | 
									client.ExpectOutputEventDetachingKill(t)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			client.ExpectDisconnectResponse(t)
 | 
								client.ExpectDisconnectResponse(t)
 | 
				
			||||||
 | 
								client.ExpectTerminatedEvent(t)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		client.ContinueRequest(1)
 | 
							client.ContinueRequest(1)
 | 
				
			||||||
@ -3872,6 +3877,7 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm
 | 
				
			|||||||
		client.ExpectOutputEventDetachingKill(t)
 | 
							client.ExpectOutputEventDetachingKill(t)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	client.ExpectDisconnectResponse(t)
 | 
						client.ExpectDisconnectResponse(t)
 | 
				
			||||||
 | 
						client.ExpectTerminatedEvent(t)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// runDebugSession is a helper for executing the standard init and shutdown
 | 
					// runDebugSession is a helper for executing the standard init and shutdown
 | 
				
			||||||
@ -3996,6 +4002,7 @@ func runNoDebugDebugSession(t *testing.T, client *daptest.Client, cmdRequest fun
 | 
				
			|||||||
	client.ExpectTerminatedEvent(t)
 | 
						client.ExpectTerminatedEvent(t)
 | 
				
			||||||
	client.DisconnectRequestWithKillOption(true)
 | 
						client.DisconnectRequestWithKillOption(true)
 | 
				
			||||||
	client.ExpectDisconnectResponse(t)
 | 
						client.ExpectDisconnectResponse(t)
 | 
				
			||||||
 | 
						client.ExpectTerminatedEvent(t)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestLaunchTestRequest(t *testing.T) {
 | 
					func TestLaunchTestRequest(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user