Debugging C/C++ on the robot

This section gives you some hints about debugging methods and gdb usage on the robot.


A first approach when developing NAOqi modules is to build it as a remote module , using the debugger already installed on the host computer.

The second step is cross-compiling this module for the robot using the cross-toolchain.


The followings intends to provide help in case of cross-compilation .

However, the usage of gdb remains most of all the same.

For further information about gdb , please refer to the gdb manual: , or run help inside gdb.

Installing gdb


All the tools used for debugging already installed on the robot or provided by the cross-toolchain do not provide multithread debugging feature. An installation step is required to use this feature. Skip this part if multithread debug is not required.

The gdb version installed on the robot does not permit to show threads information. Download the gdb-9999.tbz2 package and copy it to the /home/nao of the robot.

Assuming the robot IP address is , on the host:

             $ rsync gdb-9999.tbz2 nao@


Then on the robot, uncompress the package,

             $ tar xjf gdb-9999.tbz2


update .gdbinit file,

             $ echo "set auto-load safe-path /" > /home/nao/.gdbinit


and use the freshly installed gdb:

             $ ./usr/bin/gdb naoqi-bin


Starting gdb

There are two ways of debugging some C/C++ binaries on your robot.

You can run the debugger either:

  • locally (i.e. only running gdb on the robot) or
  • remotely (i.e. running gdbserver on the robot and gdb on the host computer).


Those debugging methods explained hereafter imply that the cross-compiled binaries have been sent on the robot before being run .


Cross-compiled binaries must be run on the robot .

Any attempt of execution on another system is a misunderstanding of the cross-compilation.

Such attempts will lead to:

  • in the best case: no execution at all;
  • in the worst case: an execution complaining about weird and incomprehensible warnings or errors.

Running debugger locally on the robot


Make sure you have built the module enabling the debug symbols (this is the default behavior when using the cross-toolchain ).

On the robot, just run:

              $ gdb naoqi-bin


Then, execute any gdb commands you want. For further details, see Using gdb .

Running debugger remotely


Currently, this is only available on Linux host .


All the tools used for debugging are already installed on the robot or provided by the cross-toolchain .

Assuming the host computer, from which you are working, has as IP address, and is the one of the robot:

  1. On the robot:

                    $ gdbserver naoqi-bin [args]

    2345 is the port number to use (this is just an example).

  2. On the host computer:

                    $ ~/.local/share/qi/toolchains/*/*-ctc/cross/bin/i686-aldebaran-linux-gnu-gdb naoqi-bin
    (gdb) set solib-absolute-prefix /path/to/your/build-directory
    (gdb) target remote

Then, execute any gdb commands you want in the debugger running on the host computer. For further details, see Using gdb .

Using gdb

The followings only give some basics about gdb .

For further information about gdb :

Managing breakpoints

              (gdb) break <absolute path of the source file on the host computer>:<line number>



              (gdb) break <absolute path of the source file on the host computer>:<function name>


Once created, a breakpoint id number is automatically associated.

You can then enable or disable any breakpoints by their id numbers:

              (gdb) enable <breakpoint id>
(gdb) disable <breakpoint id>


Execution inside gdb

Start the program passing some arguments:

              (gdb) run <arg1> <arg2>


For naoqi-bin , you might want to set a higher context level (refer to NAOqi man page or the qiLog API from libqi ), to do so:

              (gdb) run -d -c 7


To pause the execution, just press Ctrl-C , then press C to continue.

To quit gdb :

              (gdb) quit


Exploiting breakpoints

Once the program has triggered a breakpoint, it execution is paused.

Then, you can:

  • Display the source code around the breakpoint (this requires the sources at the same location on the robot as they are on the host):

                    (gdb) list
  • Display the backtrace:

                    (gdb) bt
  • Move up and down in the backtrace:

                    (gdb) up
    (gdb) down