From 5f01e72bb8b06a01f554aeb0e3047018c7233a99 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Tue, 22 Aug 2023 22:45:44 -0700 Subject: [PATCH] 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 --- cmd/dlv/cmds/commands.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index fb71f26e..e6af4c62 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -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)