Debugging C/C++ Programs Remotely Using Visual Studio Code and gdbserver
Spencer Elliott
74

Thanks for this tutorial!

Found a way to use the mentioned preLaunchTask to start the gdbserver. This is how the launch.json looks like:

{
 “version”: “0.1.0”,
 “tasks”: [
 {
 “taskName”: “startGdbServer”,
 “command”: “dummy”, // Seems to be a bug of vscode. Command must be set to some value although it is overwritten in the os specific section.
 “isBackground”: false,
 “suppressTaskName”: true,
 “linux”:{
 “command”: “gnome-terminal”,
 “args”: [“-x”, “sshpass”, “-p”, “password”, “ssh”, “user@remote”, “gdbserver :9091 ./myprogramm”]
 }
 }
 ],
 “isShellCommand”: false,
 “showOutput”: “always”,
 “echoCommand”: true
}

As you can see this is a solution for Linux. For macOS some adaptions are needed. See http://code.visualstudio.com/docs/editor/tasks.

Executing the command in a separate terminal process is done because VSCodes debugger will not start before the preLaunchTask has returned.

If this is not a test environment where the password of the remote server is not secret. Using sshpass should be avoided of course.