Debug

The server can run in debug mode including breakpoints and all the other stuff you know from debugging. To do so you need to compile the software in debug mode (see Build the server software). Copy the executable to the ZC706 like you normally would.

Next it is needed to prepare some things. Install the following package on your host system:

sudo apt install gdb-multiarch

Then SSH into the ZC706 and install the following package:

sudo apt install gdbserver

Now run the server software on the ZC706 in debug mode from within the directory where the executable is located:

sudo gdbserver :2345 ./akr2daq3

This will start the server software in debug mode and wait for a connection from the host system. Now you can attach your debugger to the server software. To do so run the following command on your host system:

gdb-multiarch

Then in the shell of the debugger run the following commands (assuming the device is called nexmess):

target remote nexmess.local:2345
continue

Now the debugger is connected and you can set breakpoints and do all the other stuff you know from debugging. Have fun!

I’m just kidding. Of course you don’t want to debug in the terminal. You want to use your VS Code [1]. Therefore create a .vscode directory within the project directory and create a launch.json file within it. The following code snippet shows a working example to debug the server software (again assuming the device is called nexmess).

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/build/app/akr2daq3",
            "miDebuggerServerAddress": "nexmess.local:2345",
            "miDebuggerPath": "gdb-multiarch",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "linux": {
              "MIMode": "gdb"
            },
            "osx": {
              "MIMode": "gdb"
            },
            "windows": {
              "MIMode": "gdb"
            },
            "setupCommands": [
                {
                    "description": "Ignore singal SIGINT, SIGABRT and SIGPIPE",
                    "text": "handle SIGINT SIGABRT SIGPIPE nostop pass",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

With this you can simply press play in VS Code and the debugger will attach to the server software. All break points and other stuff will work from within VS Code.

You will still have to start the server manually on the ZC706 using the previously shown command:

sudo gdbserver :2345 ./akr2daq3

Bibliography