Simulation Debugging
As the simulation is running on the host machine, all the desktop development tools are available.
CLANG Address Sanitizer (Mac OS, Linux)
The Clang address sanitizer can help to find alignment (bus) errors and other memory faults like segmentation faults. The command below sets the right compile options.
Valgrind
or
To use valgrind during the SITL simulation:
Launch Gazebo Classic SITL Without Debugger
By default SITL is launched without a debugger attached when using any simulator backend:
For Gazebo Classic (only) you can also start the simulator with a debugger attached. Note however, that you must provide the vehicle type in the simulator target, as shown below:
This will start the debugger and launch the SITL application with Gazebo and the Iris simulator. In order to break into the debugger shell and halt the execution, hit CTRL-C
:
In order to not have the DriverFrameworks scheduling interfere with the debugging session SIGCONT
should be masked in LLDB and GDB:
Or in the case of GDB:
After that the lldb or gdb shells behave like normal sessions, please refer to the LLDB / GDB documentation.
The last parameter, the <viewer_model_debugger> triplet, is actually passed to make in the build directory, so
is equivalent with
A full list of the available make targets in the build directory can be obtained with:
Attaching GDB to running SITL
You can also start your simulation, and then attach gdb
:
In one terminal screen enter the command to start your simulation:
As the script runs, note the SITL COMMAND: output text located right above the large "PX4" text. It will list the location of your px4 bin file for later use.
Open another terminal and type:
You will want to note the PID of the process named "PX4"
(In this example it is 14149)
Then type in the same window
For example,
Now, you can attach to the PX4 instance by entering the PID noted in step 2.
You should now have a GDB interface to debug with.
Compiler optimization
It is possible to suppress compiler optimization for given executables and/or modules (as added by cmake with add_executable
or add_library
) when configuring for posix_sitl_*
. This can be handy when it is necessary to step through code with a debugger or print variables that would otherwise be optimized out.
To do so, set the environment variable PX4_NO_OPTIMIZATION
to be a semi-colon separated list of regular expressions that match the targets that need to be compiled without optimization. This environment variable is ignored when the configuration isn't posix_sitl_*
.
For example,
would suppress optimization of the targets: platforms__posix__px4_layer, modules__systemlib, modules__uORB, examples__px4_simple_app, modules__uORB__uORB_tests and px4.
The targets that can be matched with these regular expressions can be printed with the command:
Last updated