Debugging Embedded Linux with GDBserver and Insight (gdb GUI)

Although it it sometimes possible to debug applications using GDB (The GNU Debugger) on the target boards, there is often not enough memory available to run GDB on embedded systems running Linux.

To work around this issue, you can use gdbserver to perform remote debugging.

Installing and running gdbserver on the target board

First of all you need to install gdbserver on the target board. Assuming you use a Debian based distribution:


If you distribution, does not have binary repository, you can download gdb source code and cross-compile gdbserver.

Once gdbserver is installed, (cross-)compile your application in debug mode and start gdbserver as follows:


Where target_ip and target_port are respectively the IP address of the board and the chosen TCP port, and prog_dbg, the program under test compile in debug mode (CFLAGS=-g).

Remote Debugging with GDB

If you are familiar with gdb and prefer to use the command line, you can use gdb for ARM. I’ll use a build machine using Debian Squeeze as an example.

Make sure you are using EmDebian pakages URL in /etc/apt/sources.list:

#
# — Emdebian cross toolchains
#
deb http://www.emdebian.org/debian/ squeeze main

Then install gdb for ARM:
There may be an error during installation:
In that case, you can force gdb installation as follows:
then run arm-linux-gnueabi-gdb without argument, and connect to the target board:


where target_ip and target_ip are the IP address and port stipulated in gdbserver command line.

After that, you can use gdb to debug the program normally. Simply type cont to run the program. For other commands type help or consult gdb manpage.

Installing and using Insight (GDB User Interface) for remote debugging

Many people, don’t like to use the command line and prefer to use a graphical interface, especially since it makes it easy to add breakpoints and see both the assembly and source code.
There is no binary packages for Insight in Debian/Ubuntu, so it has to be cross-compiled.
First, download and extract the source code:


Then configure, build and install it to run on Intel x86 and support ARM targets:


Now run arm-linux-gnueabi-insight without arguments.

Set the path where your ARM library are located. Click on View->Console to start the gdb console and type:


where /usr/arm-linux-gnueabi is the sysroot path. The arm libraries are in /usr/arm-linux-gnueabi/lib directory in my case. This path depends on the cross-toolchain you use. I’m using EmDebian.

If you don’t set the sysroot, you’ll end up with dynamic library errors as you run the program. For example:

warning: .dynamic section for “/lib/libpthread.so.0” is not at the expected address (wrong library or version mismatch?)

Click load your debug program by clicking File->Open, it will automatically load the source files and set a breakpoint in the main. You can also set your own breakpoints in the source (Red square in the screenshot below).

GDB Insight Source and Breakpoint.
Insight Source & Assembler Windows

Click on Run->Connect to target and the Target Selection Windows should pop-up. Select GDBserver/TCP in the Target drop-down menu and enter the IP and port to connect to your board.

GDB Insight for ARM select target board
Insight Target Selection Window

Click on OK. That’s it. You can now browse the code to add breakpoints, monitor variable….
To run the program, select Run->Run or Click on the “blue running man” icon.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX Rockchip RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
1 Comment
oldest
newest
Juan Alberto Aranda Alvarez
Juan Alberto Aranda Alvarez
11 years ago

This is a great article. Thanks a lot.

Boardcon Rockchip RK3588S SBC with 8K, WiFI 6, 4G LTE, NVME SSD, HDMI 2.1...