Debugging Ardupilot on Mac OSX

I had a problem trying to debug with GDB on Mac OSX (10.12 Sierra or later) using the wiki instructions for linux and I want to share the solution.

> -v ArduCopter -f quad --console --map -D -G

SIM_VEHICLE: Killing tasks
SIM_VEHICLE: Starting up at -35.363261,149.165230,584,353 (CMAC)
SIM_VEHICLE: Using defaults from (/ardupilot/tools/autotest/default_params/copter.parm)
SIM_VEHICLE: Run ArduCopter (gdb)
SIM_VEHICLE: "/ardupilot/tools/autotest/" "ArduCopter (gdb)" "gdb" "-x" 
"/var/folders/yr/459cs03n63g185cf1bp_3xvc0000gn/T/tmp9GvBmX" "--args" 
"/ardupilot/build/sitl/bin/arducopter" "-S" "-I0" "--home" "-35.363261,149.165230,584,353" "--model" "+" "-- 
speedup" "1" "--defaults" “/ardupilot/tools/autotest/default_params/copter.parm"
SIM_VEHICLE: "" "--master" "tcp:" "--sitl" "" "--out" 
"" "--out" "" "--map" "--console"
RiTW: Starting ArduCopter (gdb) : gdb -x /var/folders/yr/459cs03n63g185cf1bp_3xvc0000gn/T/tmp9GvBmX -- 
args /ardupilot/build/sitl/bin/arducopter -S -I0 --home -35.363261,149.165230,584,353 --model + --speedup 1 - 
-defaults /ardupilot/tools/autotest/default_params/copter.parm

RiTW: Window access not found, logging to /tmp/ArduCopter (gdb).log
Connect tcp: source_system=255
[Errno 61] Connection refused sleeping
[Errno 22] Invalid argument sleeping
Failed to connect to tcp: : [Errno 22] Invalid argument

SIM_VEHICLE: MAVProxy exited
SIM_VEHICLE: Killing tasks

The /tmp/ArduCopter (gdb).log contains a bunch of warnings and this error:

/var/folders/yr/459cs03n63g185cf1bp_3xvc0000gn/T/tmpfJ80yd:1: Error in sourced command file:
During startup program terminated with signal ?, Unknown signal.
(gdb) Exception condition detected on fd 0
error detected on stdin

Same error running arducopter directly with gdb --args build/sitl/bin/arducopter -M x


First the gdb installation on mac needs these steps, make sure to have done all (if you have not installed it already, read to the bottom because you need a specific version):

  • gdb installed via brew brew install gdb
  • generate a certificate with keychain:
    • Keychain Access > Certificate Assistant > Create a Certificate
    • choose a name e.g. “gdb-cert”
    • set Identity Type to Self Signed Root
    • set Certificate Type to Code Signing
    • check Let me override defaults
    • specify certificate location to system
    • reboot
  • sign gdb with codesign -s gdb-cert /usr/local/Cellar/gdb/8.0.1/bin/gdb (change the certificate name and the gdb version folder as needed)
  • create a ~/.gdbinit file to set startup-with-shell off with this command echo "set startup-with-shell off" >> ~/.gdbinit

Then I found that the latest gdb version has a problem and downgrading to 8.0.1 solves it.

To downgrade:

  • brew unlink gdb
  • brew install
  • Optional: avoid gdb upgrade with brew pin gdb

Probably GUI tools like Eclipse debugging or gdbgui are useful, any suggestions on other tools?


Thanks for sharing a solution ! Could you add it on the wiki?