GDB on OS X Mavericks or newer and Xcode 5 or newer

From Free Pascal wiki
Jump to navigationJump to search
Stock-dialog-warning.svg

This article applies to Mac OS X only.

See also: Multiplatform Programming Guide

Overview

This page explains how to build and install gdb on OS X using homebrew or fink.

Since OS X Mavericks 10.9, Xcode 5 no longer installs gdb by default and not globally.

For general notes about installing FPC and Lazarus on OS X see Installing Lazarus on MacOS X.

About using gdb see GDB Debugger Tips.

Homebrew

Install homebrew

Open a Terminal and install homebrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Here is an example output:

mattias@mac:~$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
==> The following directories will be made group writable:
/usr/local/.
/usr/local/bin
/usr/local/lib
/usr/local/share
/usr/local/share/doc
==> The following directories will have their group set to admin:
/usr/local/.
/usr/local/bin
/usr/local/lib
/usr/local/share
/usr/local/share/doc

Press ENTER to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/doc

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/doc
==> Installing the Command Line Tools (expect a GUI popup):
==> /usr/bin/sudo /usr/bin/xcode-select --install
xcode-select: note: install requested for command line developer tools
Press any key when the installation has completed.
==> Downloading and installing Homebrew...
remote: Finding bitmap roots...
remote: Counting objects: 136798, done.
remote: Compressing objects: 100% (45940/45940), done.
remote: Total 136798 (delta 94648), reused 131779 (delta 89816)
Receiving objects: 100% (136798/136798), 25.15 MiB | 738.00 KiB/s, done.
Resolving deltas: 100% (94648/94648), done.
From https://github.com/mxcl/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 55d2970 play/sox conflict
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help

Install gdb

brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb

Here is an example output:

mattias@mac:~$ brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb
######################################################################## 100,0%
==> Installing gdb dependency: readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.2.4.maveri
######################################################################## 100,0%
==> Pouring readline-6.2.4.mavericks.bottle.1.tar.gz
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
/usr/local/Cellar/readline/6.2.4: 31 files, 1,6M
==> Installing gdb
==> Downloading http://ftpmirror.gnu.org/gdb/gdb-7.6.1.tar.bz2
######################################################################## 100,0%
==> ./configure --prefix=/usr/local/Cellar/gdb/7.6.1 --with-system-readline --with-python=
==> make
==> make install
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  http://sourceware.org/gdb/wiki/BuildingOnDarwin
==> Summary
🍺  /usr/local/Cellar/gdb/7.6.1: 27 files, 5,0M, built in 105 seconds

The new gdb does not run yet. You will get the error:

The GDB command:
„-exec-run“ returned the error:
„,msg=„Unable to find Mach task port for process-id 62593:
(os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))““

Follow the instructions in the #Codesigning gdb section to solve this.

Fink

Install Fink

Install fink according to the description here: http://www.finkproject.org/download/index.php?phpLang=de

Install a version of gdb

There is the choice between gdb with modifications of apple and more recent version of gdb without apple mods.

:~$ fink install apple-gdb

:~$ fink install gdb

The first gives you /sw/bin/gdb, the second /sw/bin/fsf-gdb. You can use either of the two, but only after you have code sign them (See below).

Codesigning gdb

You need to create a certificate and sign gdb:

  1. Open application “Keychain Access” (/Applications/Utilities/Keychain Access.app)
  2. Open menu /Keychain Access/Certificate Assistant/Create a Certificate...
  3. Choose a name (gdb-cert in the example), set “Identity Type” to “Self Signed Root”, set “Certificate Type” to “Code Signing” and select the “Let me override defaults”. Click “Continue”.
  4. You might want to extend the predefined 365 days period to 3650 days.
  5. Click several times on “Continue” until you get to the “Specify a Location For The Certificate” screen, then set “Keychain to System”.
  6. If you can't store the certificate in the “System” keychain, create it in the “login” keychain, then export it. You can then import it into the “System” keychain.
  7. In keychains select “System”, and you should find your new certificate. Use the context menu for the certificate, select “Get Info”, open the “Trust” item, and set “Code Signing” to “Always Trust”.
  8. You must quit “Keychain Access” application in order to use the certificate and restart “taskgated” service by killing the current running “taskgated” process. Alternatively you can restart your computer.

Finally you can sign gdb:

  • if installed via Homebrew:
codesign -s gdb-cert /usr/local/bin/gdb
  • if installed via Fink:
codesign -s gdb-cert /sw/bin/gdb

At first use after every reboot you will be asked for an administrator password.