Monday, 13 February 2017

GDB vs macOS Sierra

We probably feel downhearted if we need to use the debugger to find out what's wrong with our Ada code.

Under those circumstances, we feel even more frustrated if the debugger doesn't work!

This is exactly what has happened with gdb and increased security in macOS Sierra.

For some time now, we've had to code-sign gdb. With Sierra, Apple have changed System Integrity Protection in such a way that the default setting prevents gdb from starting a subprocess (i.e. starting the program to be debugged).

To add to the problems, Apple have altered the way that the debugger has to interact with the exec'd program.

There's discussion on the Sourceware Bugzilla (bug 20266), and on the AdaCore blog.

I've rebuilt GDB GPL 2016 to include the changes required.

  1. Download gdb-gpl-2016-sierra.tar.gz.
  2. Unpack it (giving gdb).
  3. Copy gdb to $prefix/bin (e.g. /opt/gnat-gpl-2016/bin, /opt/gcc-6.1.0/bin; this gdb will work with either compiler).
  4. Code-sign gdb (don't bother to restart the computer yet).
    1. Reboot your system into recovery mode: at the bong, keep Command-R pressed until the Apple logo appears;
    2. Select Terminal from the Utilities menu;
    3. Type csrutil enable --without debug;
    4. Reboot.
  5. Edit ~/.gdbinit to include the line
    set startup-with-shell off

Now you should be good to go! (at any rate, with Sierra 10.12.3, Darwin 16.4.0).

No comments:

Post a Comment