4

I'm using VS Code to write and debug a C++ program binding to libfuse.

Unfortunately, if you kill a libfuse process with SIGKILL, you then have to use sudo umount -f <mountpoint> before you can start the program again. It's a minor nuisance if I have to do this every time I want to stop or restart debugging, especially as I shouldn't have to authenticate to do such a regular task (the sudo is somehow necessary despite the mount occurring as my user).

While I think this is mainly FUSE's fault (it should gracefully recover from a process being ungracefully killed and unmount automatically instead of leaving the directory saying Transport endpoint is not connected), I also think there should be a way to customise VS Code (or any IDE) to run some clean-up when you want to stop debugging.

I've found that entering -exec signal SIGTERM in the Debug Console will gracefully unmount the directory correctly, stop the process and tell VS Code it's no longer debugging (status bar changes back from orange to blue). But I can't seem to find a way to automate this. I've tried using a .gdbinit file, with some inspiration from this question:

handle SIGTERM nostop

# This doesn't work as hook-quit isn't run when quitting via MI mode, which VS Code uses...
define hook-quit
    signal SIGTERM
end

But as noted in the linked question, GDB ignores quit hooks when in MI mode, and VS Code uses MI mode.

The ideal solution for me would be if I could put something in a .vscode configuration file telling it to send -exec signal SIGTERM when I click the stop or restart buttons (and then wait for whatever notification it's getting that debugging has stopped, before restarting if applicable) but I imagine there probably isn't an option for that.

Even if the buttons can't be customised, I'd be happy with the ability to have a keybinding that would just send -exec signal SIGTERM to the Debug Console without me having to open said console and enter the command, though the Command Palette doesn't show anything useful here (nothing that looks like it will send a specified Debug Console command), so I don't expect there's a bindable command for that either.

Does anyone have any suggestions? Or would these belong as feature requests over on the VS Code github? Any way to get GDB to respect its quit hook in MI mode, or to get FUSE to gracefully handle its process being killed would be appreciated too.

starball
  • 20,030
  • 7
  • 43
  • 238
Keiji
  • 880
  • 5
  • 12

1 Answers1

0

I believe you can achieve what you are looking for with the preLaunchTask and postDebugTask attributes of a launch configuration.

See the docs:

  • preLaunchTask - to launch a task before the start of a debug session, set this attribute to the label of a task specified in tasks.json (in the workspace's .vscode folder). Or, this can be set to ${defaultBuildTask} to use your default build task.

  • postDebugTask - to launch a task at the very end of a debug session, set this attribute to the name of a task specified in tasks.json (in the workspace's .vscode folder).

So for your specific scenario, I'm pretty sure you can just create a task that runs your command- something along the lines of the following:

{
   "label": "unmount FUSE",
   "type": "shell",
   "command": "sudo umount -f ...",
}

and then use that in your postDebugTask task. If you need to do multiple things, you can wrap them in a shell script or something, or use compound tasks.

starball
  • 20,030
  • 7
  • 43
  • 238