英文:
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)
<-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
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"console": "integratedTerminal"
}
]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论