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 http://ardupilot.org/dev/docs/debugging-with-gdb-on-linux.html and I want to share the solution.

> sim_vehicle.py -v ArduCopter -f quad --console --map -D -G

SIM_VEHICLE: Start
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/run_in_terminal_window.sh" "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: Run MavProxy
SIM_VEHICLE: "mavproxy.py" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501" "--out" 
"127.0.0.1:14550" "--out" "127.0.0.1:14551" "--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:127.0.0.1:5760 source_system=255
[Errno 61] Connection refused sleeping
[Errno 22] Invalid argument sleeping
Failed to connect to tcp:127.0.0.1:5760 : [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

Solution:

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 https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb
  • Optional: avoid gdb upgrade with brew pin gdb

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

Hello,

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