vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.43k stars 237 forks source link

Enable graceful shutdown of applications supporting SIGINT/SIGTERM signals when debugging. #969

Open ogapo opened 12 months ago

ogapo commented 12 months ago

Since 2018 VSCode allows the supportsTerminateRequest feature which is described in detail here.

In a nutshell, if a debugger implementation (i.e. codelldb) supports a more graceful kill option, then opting-in to this capability will cause VSCode to send the terminate request rather than killing the process directly. This occurs the first time a user presses the stop button, but subsequent presses will perform the less graceful kill as an escape hatch. It seems the feature is fairly solidly implemented (this was added for Node.js debugger and when I've used it there it works great) the extension just needs to opt-in to receiving the signal and translate it appropriately (in our case probably issuing the LLDB command process signal SIGINT).

They even mention in the above article that this would be a good match for SIGINT.

On Unix-based operating systems, this could easily be achieved by sending the SIGINT signal to the debuggee.

Since an unbound SIGINT handler simply exits the app (which is equivalent to the present day behavior) this would probably be most appropriate to enable by default. That said, it would definitely be handy to have a config setting that lets the user select the signal they want to use (I personally use SIGINT and SIGTERM for slightly different thing and I could see some apps needing the SIGUSR signals too) or to disable it entirely (probably the same as mapping to SIGKILL?).