Sep 18

Now that GDB-Server is installed on the FB it is time to see if the Hello_World application can be debugged on my development PC over the network to the FB.

On the Axis developer site there is mentioning of special make commands to compile the target code in such a way that debug information is added to the executable. Since I want to make use of my own make file in order to fully understand how this works the make file must be changed to include more compiler flags. Open Geany, load the HelloWorld project and change the make file as listed below (only the CFLAGS definition changes):

COMPILER = /usr/local/cris/bin/gcc-cris
CFLAGS = -g -fno-omit-frame-pointer -O0 -mlinux -o
SOURCES = main.c MyUnit.c
TARGET = Hello_World
DESTINATION = root@FOXBoard:/mnt/flash/bin/HelloWorld

# top-level rule to create the program, executed by default if no params are provided
all: compile

# Called by pressing the Compile or Build button in Geanny
compile: $(SOURCES)

build: compile


Press the execute button in Geany so that the HelloWorld application is compiled with the new settings and copied to the FB. Using a SSH, navigate to /mnt/flash/bin/HelloWorld and execute ./Hello_World to verify if the application works.

In a different terminal, check what IP address is used by the development PC, in my case This needs to be used on the FB in GDB-Server so it knows to whom to listen. In the folder /mnt/flash/bin/HelloWorld on the FB enter the command gdbserver Hello_World, as a response the a process is started for Hello_World and GDB-Server will use port 1234 to listen if sends commands.

In a terminal on the development PC, navigate to /usr/local/gdb-cris and enter the command ./gdb-cris /home/jan/FOXBoard/HelloWorld/Hello_World, this will start GDB and the prompt will change into (gdb). Enter the command target remote FOXBoard:1234, some warnings are given that GDB is not able to debug shared libraries but for now let’s ignore those since in the terminal for the FB a message will appears Remote debugging from host so it seems that communication between host and target has been made.

In order to set a breakpoint on the first line of the main () function, enter the command break main in GDB-Server. The response shows it could set the breakpoint in main.c on line 6, so far so good. Enter the command help running will give a list of possible commands to step through the program. One of them is continue that runs until a breakpoint is encountered. Entering this command shows some errors that /lib/ can not be found, seems that this is the shared library that triggered the previous warning. GDB stops at line 6 showing the source line. Next command is step that executes one line of code. In the FB terminal the Hello world message appears. Use the step command repeatly to step line by line through the code until GDB states the program exited normally and GDB-Server states that the Child exited with retcode 0.

Not bad!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.