当我终止调试时,vscode-go调试器向delve-dap发送什么操作系统信号?

huangapple go评论67阅读模式
英文:

What OS signal does the vscode-go debugger send to delve-dap when I terminate debugging

问题

我想在终止 vscode 的 golang 调试器时捕获操作系统信号并执行一些退出任务。

我有以下代码:

sigalChan := make(chan os.Signal, 1)
signal.Notify(sigalChan, syscall.SIGINT, syscall.SIGTERM)
<-sigalChan
doSomeJobs()

但它不起作用。有人可以告诉我如何解决吗?也许信号类型不是 SIGINT 或 SIGTERM?

英文:

I want to capture the OS signal and do some exit jobs when I terminate the vscode golang debugger.

I have code as below:

sigalChan := make(chan os.Signal, 1)
signal.Notify(sigalChan, syscall.SIGINT, syscall.SIGTERM)
&lt;-sigalChan
doSomeJobs()

but it doesn't work. Anyone can tell me how to figure it out? Maybe the signal type is not SIGINT or SIGTERM?

答案1

得分: 9

我找到了一个解决方案。只需在launch.json中将"console"设置为"integratedTerminal",以使delve服务器前台运行,然后我就可以使用"ctrl+c"来终止调试过程,并且信号可以在我的程序中接收到。

{
    // launch.json
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/main.go",
            "console": "integratedTerminal"
        }
    ]
}
英文:

I find out a solution. Just set "console" to "integratedTerminal" in launch.json to make delve server foreground, then I can use "ctrl+c" to terminate the debugging process, and signal can be received in my program.

{
    // launch.json
    &quot;version&quot;: &quot;0.2.0&quot;,
    &quot;configurations&quot;: [
        {
            &quot;name&quot;: &quot;Launch&quot;,
            &quot;type&quot;: &quot;go&quot;,
            &quot;request&quot;: &quot;launch&quot;,
            &quot;mode&quot;: &quot;auto&quot;,
            &quot;program&quot;: &quot;${workspaceFolder}/main.go&quot;,
            &quot;console&quot;: &quot;integratedTerminal&quot;
        }
    ]
}

huangapple
  • 本文由 发表于 2022年3月24日 20:39:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/71602708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定