Debugging with GDB on Pixhawk

This page describes how to setup GDB on Linux to debug issues with a PX4 or Pixhawk. The specific commands were tested on Ubuntu 13.10. GDB can also be set-up on Windows but there is an issue passing the Ctrl-C command to GDB which makes it difficult to use effectively.

Warning

This page has not be maintained from some time, if something is wrong please contact us on Gitter/ArduPilot.

Introduction

GDB (the GNU Debugger) “allows you to see what is going on `inside’ another program while it executes or what another program was doing at the moment it crashed.” which can be useful when investigating very low-level failures with the Pixhawk (it cannot be used with the APM1/APM2)

This guide assumes that you have already successfully built the firmware on your machine following the instructions for Windows, Mac or Linux.

A BlackMagic probe is also required. They can be purchased in the US from Transition Robotics, Tag-Connect or 1 Bit Squared or in NewZealand from Greenstage.

Connecting the probe to the Pixhawk

../_images/DebuggingWithGDB_PixhawkBlackMagicProbe.jpg

The BlackMagic probe should be connected to the Pixhawk’s JTAG connector using the grey 10wire cable that came with the probe. Note that most Pixhawk come with no headers soldered onto the JTAG connector because it interferes with the case.

Installing GDB

If using Ubuntu, GDB is likely already installed on your machine and it will likely work although we recommend using the version available for download here http://firmware.ardupilot.org/Tools/STM32-tools

The gcc-arm-none-eabi*-linux.tar.bz2 file contains both the recommended compiler and the recommended version of gdb.

After installation you should find you have a tool called arm-none-eabi-gdb.

Starting GDB and running some commands

GDB requires both the firmware file that’s been uploaded to the board (i.e. arducopter.apj) which can normally be found in Copter, Plane or APMRover2 directory and the firmware.elf file that can be found in the build directory.

Change to your firmware directory and type the following:

arm-none-eabi-gdb build/fmuv3/bin/arducopter

../_images/DebuggingWithGDB-startGBD.png

Some useful commands:

r – restarts the process

b function-name – i.e. b setup – sets a breakpoint at the start of the “setup” function. Note a class name can be prepended such as b AC_AttitudeControl::init

Ctrl-C – stops the code from executing so you can set breakpoints, etc

continue – continues the code from wherever it was stopped

show interrupted-thread – shows address where execution has stopped (see below)

info line * <address> – shows c++ line for a given address (i.e. from show interrupted-thread)

disassemble <address> – converts given address into assembler code

exit – exits from the GDB

../_images/GDB_commands2.jpg