cmd/dlv: handle ctrl-c during tracing (#3477)

Ensure we send a Halt command to stop the process being traced so that
the deferred Detach can run ensuring proper cleanup upon exit.

Fixes #3228
This commit is contained in:
Derek Parker 2023-08-22 22:45:44 -07:00 committed by GitHub
parent 32b937c953
commit 5f01e72bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -672,6 +672,15 @@ func traceCmd(cmd *cobra.Command, args []string, conf *config.Config) int {
}
client := rpc2.NewClientFromConn(clientConn)
defer client.Detach(true)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT)
go func() {
<-ch
client.Halt()
}()
funcs, err := client.ListFunctions(regexp)
if err != nil {
fmt.Fprintln(os.Stderr, err)