-
Notifications
You must be signed in to change notification settings - Fork 10
The GDBServer for remote debugging
There might be a situation in your life that you really have to debug remotely (you may not want to, but sometimes it is the only way to kill a bug). And remote debugging here means, debugging from a client - the super-powered dev machine where the code is - to a server - a quite restricted machine somewhere else where the binary is.
To achieve that with this extension the way is using GDB and GDBServer.
In the README you can find the following sample.
{
"version": "0.2.0",
"configurations": [
{
"name": "COBOL debugger attach",
"type": "gdb",
"request": "attach",
"target": "${file}",
"targetargs": [],
"cwd": "${workspaceRoot}",
"gdbpath": "gdb",
"cobcpath": "cobc",
"cobcargs": ["-free", "-x"],
"group": [],
"remoteDebugger": "somewhere:6666"
}
]
}
Of course, you don't have direct access to the server you want (if you do, good for you). In that case, you have to follow the restrictions applied to you.
The usual cases are SSH and VPN. It should be straightforward debugging on a VPN, but on an SSH connection can be tricky. The extension is not supporting internally SSH connections yet, but with a couple of short commands, you can achieve it.
First, you have to attach the GDBServer to your remote running process. So, after you connect to the remote server, you should get the desired PID and run the GDBServer. It should be something like: gdbserver :{REMOTE_PORT} --attach {PID}
(REMOTE_PORT
stands for any locally available port and PID
the actual running process id.
Once you have the GDBServer running faraway, you will be able to open an SSH tunnel(AKA magic portal) and the spell words are: ssh -N -L {LOCAL_PORT}:localhost:{REMOTE_PORT} someuser@somewhere
. Here LOCAL_PORT
has to be replaced by any port available in the dev machine and REMOTE_PORT
should be the remote GDBServer specified in the first command.
Finally, after these two simple commands, you have everything necessary to debug the remote running process using the sample launch.json abovementioned. Don't forget to update the remoteDebugger
to localhost:{LOCAL_PORT}
.