Project for testing remote debugging of C++ code with gdb and gdbserver in VS Code
- a remote host reachable via
sshgdbservershould be installed on the remote host- no root privileges are required on the remote host, plain user rights are enough
- VisualStudio Code installed on the local machine
- the C/C++ extension should be installed
-
my local machine is Linux notebook (Linux Mint 18 Cinnamon Edition), denoted by
local $- the file system of the remote machine has to be mounted on the local machine either using
File -> Connect to Server(type:ssh) from the Nemo file browser or usingsshfs
- the file system of the remote machine has to be mounted on the local machine either using
-
my remote machine is Linux server, denoted by
remote $, on whichgdbserveris available
-
SSH to remote machine and use port forwarding
local $ ssh -L9091:localhost:9091 user@some.server.org -
Clone repo with
remote $ git clone https://github.com/dmrauch/vscode-cpp-remote-debug.git
-
Out-of-source build with debug symbols
remote $ cd vscode-cpp-remote-debug/build/debug remote $ cmake -DCMAKE_BUILD_TYPE=Debug ../../source remote $ make -
Start
gdbserverremote $ cd ../.. # going back into vscode-cpp-remote-debug/ remote $ gdbserver :9091 build/debug/file1
-
Mount the remote file system in the file browser as mentioned above, i.e. either in the Nemo file browser do
File -> Connect to Serveror usesshfs -
Open VisualStudio Code and open the project / repository folder from the mounted location
-
Open and possibly edit the code, set breakpoints somewhere in one or both source code files
folder1/file1.cxxandfolder2/file2.cxx -
Adapt the
.vscode/launch.jsonfile to your needs- In particular you will have to change the
sourceFileMapparameter which needs to contain all information about the mounted remote file system. By hovering the mouse over one of the open code tabs (e.g.file1.cxx) you can read off what should go there in your case.
- In particular you will have to change the
-
Open the debug view, select the
Remote Debugconfiguration and launch the debugger configuration(gdb) Launch Remote Debugging of file1
Happy debugging!
- The
launch.jsonis based on the following, very helpful article: Debugging C/C++ Programs Remotely Using Visual Studio Code and gdbserver. - Big thanks go to @pieandcakes for pointing out the
sourceFileMapproperty in.vscode/launch.json(GitHub#834).
