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

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

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

问题

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

我有以下代码:

  1. sigalChan := make(chan os.Signal, 1)
  2. signal.Notify(sigalChan, syscall.SIGINT, syscall.SIGTERM)
  3. <-sigalChan
  4. 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:

  1. sigalChan := make(chan os.Signal, 1)
  2. signal.Notify(sigalChan, syscall.SIGINT, syscall.SIGTERM)
  3. &lt;-sigalChan
  4. 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"来终止调试过程,并且信号可以在我的程序中接收到。

  1. {
  2. // launch.json
  3. "version": "0.2.0",
  4. "configurations": [
  5. {
  6. "name": "Launch",
  7. "type": "go",
  8. "request": "launch",
  9. "mode": "auto",
  10. "program": "${workspaceFolder}/main.go",
  11. "console": "integratedTerminal"
  12. }
  13. ]
  14. }
英文:

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.

  1. {
  2. // launch.json
  3. &quot;version&quot;: &quot;0.2.0&quot;,
  4. &quot;configurations&quot;: [
  5. {
  6. &quot;name&quot;: &quot;Launch&quot;,
  7. &quot;type&quot;: &quot;go&quot;,
  8. &quot;request&quot;: &quot;launch&quot;,
  9. &quot;mode&quot;: &quot;auto&quot;,
  10. &quot;program&quot;: &quot;${workspaceFolder}/main.go&quot;,
  11. &quot;console&quot;: &quot;integratedTerminal&quot;
  12. }
  13. ]
  14. }

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:

确定