Debugging a Custom Driver
Applications compiled with the g++ compiler using the –g option include the necessary debugging information in the executable and can thus be debugged using the GNU Project Debugger (gdb). Although the SmartServer includes a pre-installed copy of the compiler (g++), gdb isn’t preinstalled on the SmartServer. To use gdb to debug a custom driver, follow these steps:
Ensure your SmartServer has Internet access.
Using a console application like PuTTY, navigate to the /usr/bin/ directory and enter ‘sudo apt update
’. The Advanced Package Tool will download package information from configured sources so it knows which packages are available for upgrade and where to retrieve them.
After running ‘sudo apt update
’, install the GNU Project Debugger by running ‘sudo apt install –y gdb
’ from the console.
Once this completes, you can verify the installation of gdb by checking the version information from the console by typing ‘gdb --version
’. You will see version information in response, similar to what is shown below.
Installing the GNU Project Debugger also installs the associated gdbserver application, which provides options for debugging applications remotely as well.
With gdb installed on the SmartServer, you can debug an application like the example custom driver by starting it up under gdb control using ‘sudo gdb ./example
’ as shown below.
You may see an error referencing ‘libcrypto’, which is highlighted above. The error is benign and you can ignore it. You can also prevent this reported error (and others such as designed interruptions) by using the command ‘handle SIGILL nostop noprint’ within gdb just before you run (r) or continue (c) a managed driver application like ‘./example’. Although gdb is a command line debugger, it is a full-featured debugging tool. You can set breakpoints, inspect variables, start and stop program execution, single step, and so on. There is an extensive list of available commands you can use within gdb to manage the debugging of your application. Since these commands are readily documented online from many sources, including from GNU.org itself, these are not documented here, however you can find this information online from sources like https://sourceware.org/gdb/download/onlinedocs/gdb.pdf
As mentioned above, installing the GNU Project Debugger installs not only the command line debugger (gdb), it also installs the gdbserver application on the SmartServer IoT. gdbserver makes it possible to remotely connect to and debug an application running on the SmartServer from another development system such as a Windows-based computer. The setup for remote debugging is dependent on whether this development host is Linux or Windows based, and may differ depending on the OS version. For example, on a Windows-based computer this generally requires installing and configuring several tools in addition to the Microsoft C/C++ extension in Visual Studio Code as well as Mingw-w64 described in Compiling a Custom Driver. Some of the additional required tools may include the Native Debug Extension in Visual Studio Code as well as OpenSSH (installed with GIT), which is used to create an SSH key pair from the computer to be installed onto the SmartServer.