Remote debugging with GDB and GDBServer on Alpine and Visual Studio Code

gdb and gdbserver can be used in combination to provide debugging capabilities over the network.  gdbserver is run on the machine you want to debug.  gdb is run on the machine you want to debug from, usually your local machine.
More here.
Before we get started, we need some software.  Alpine 3.8 will be the gdbserver.

NFS

We will be using nfs (Network File System) to mount a remote directory and have it look like a local directory.  We will cd to the nfs mounted directory which contains the program we want to debug before we launch gdb.  This way the program and symbols will match.  gdb will be running on your local client, but it will be launched when in a directory on the gdbserver's system.
More than you wanted to know about nfs.
To set up nfs, you will need nfs software on your server and your client.
SERVER (Your Alpine machine)
- Add nfs support:
% apk add nfs-utils
- Edit /etc/exports, add the following.  This will share the "/root" directory.  If you want to share your whole machine replace "/root" with "/".
/root *(rw,no_root_squash,sync)
- Start nfs service:
% service nfs start
- Check if nfs is running:
% rpcinfo -p
CLIENT (Any linux machine)
- Check if server is sharing:
% showmount -e server.name.or.IP
- Create mount point directory:
% sudo mkdir /mnt/alpine
- Mount it:
% mount -t nfs server.name.or.IP:/root /mnt/alpine
For example:  % mount -t nfs 192.168.56.103:/ /mnt/alpine
- To unmount:
% umount /mnt/alpine

Install GDB and GDBSERVER

On Alpine 3.8 you can install gdb and gdbserver with the following command:
% apk add gdb
If you ever want to build gdb and gdbserver from source, follow this guide.

Run GDB and GDBSERVER

Refer to this page.

VS CODE

You can lauch gdbserver on the Alpine machine as shown above.  Add the following block of code to your launch.json to have VSC connect to the gdbserver.  Update the following as needed.
{
"name": "(gdb_remote) Launch transcoder WITH JSON",
"type": "cppdbg",
"request": "launch",
"program": "/mnt/alpine/home/mcancilla/src/transcoder/transcoder",
"miDebuggerServerAddress": "192.168.56.103:1234",
"args": [],
"stopAtEntry": true,
"cwd": "/mnt/alpine/home/mcancilla/src/transcoder",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "gdb"
},
"windows": {
"MIMode": "gdb"
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},

Comments

Popular posts from this blog

FFMPEG Deinterlacing Modes

Build FFMPEG for Windows Using Visual Studio Toolchain