Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!

Clear all

macOS - Install GDB in 2023 (for use with Lazarus Pascal)

2 Posts
1 Users
Famed Member Admin
Joined: 11 years ago
Posts: 2630
Topic starter  

A lot has changed since Apple dropped GDB support in favor of LLDB, and some devs on the Lazarus team have done great effort to make LLDB work, and it does. Especially for Apple Silicon Mac's you'd probably want to use LLDB as it seems GDB does not [yet] support Apple Silicon.

However,... on my Intel Mac Pro (2013 Trashcan, 12 core, 64Gb RAM!) LLDB delays the startup by around 30 seconds when ever I want to do some debugging, and as you can imagine this is quite annoying.
Not to mention some reports I had seen for debugging limitations of LLDB.

So how do we install GDB (doing this Feb 2023, macOS Monterey 12.6.2, with XCode and XCode Commandline tools installed - according to "Brew" it should work with Ventura as well).

1. Install Brew (this takes a bit):

/bin/bash -c "$(curl -fsSL )"


2. Install GDB

Note: if you have an old version of GDB; consider renaming or deleting it.
(in my case with: sudo rm /usr/local/bin/gdb)

brew install gdb

you can confirm it with being available with:

gdb --version

3. Sign GDB

(at the end of this post: how to create yoru self-signed certificate if needed)

- create a plist file (eg. gdb-entitlement.xml) with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">

- determine where GDB is located with the "which" statement:

$ which gdb   

 (the path on your system may be different)

 - sign the GDB binary (in the directory where you just created the gdb-entitlements.xml file):

codesign --entitlements gdb-entitlements.xml -fs "S4F99MAJG8" /usr/local/bin/gdb


- Replace "S4F99MAJG8" with your certificate or gbd-cert if you self-signed a cert.
- Make sure "user/local/bin/gdb" matches the path of your GDB (see the "which" command)

You can verify if signing went OK with:

codesign --verify --verbose /usr/local/bin/gdb




- Do not forget to change your Lazarus settings
- You will probably need to do a Clean Build for your project before GDB works properly with Lazarus.



Optional: Generate a certificate for signing GDB ...

I copied these steps from the Internet for your convenience.
As an app developer I do have my own Apple certificate and have no need for a self-signed CERT.

- Launch Keychain: Applications > Utilities > Keychain Access.
- In Keychains list on the left, right-click on the System item and select Unlock Keychain "System".
- From the toolbar: Keychain Access > Certificate Assistant > Create a Certificate.
- Choose a name (e.g. gdb-cert <- remember this name!).
- Set Identity Type to "Self Signed Root".
- Set Certificate Type to "Code Signing".
- Check the "Let me override defaults" checkbox.

At this point, you can go on with the installation process until you get the "Specify a Location For The Certificate" dialogue box. Here you need to set Keychain to "System". Finally, you can click on the "Create" button.

After these steps, you can see the new certificate under System keychains.
From the contextual menu of the newly created certificate (right-click on it) select the Get info option.
In the dialogue box, expand the Trust item and set Code signing to Always Trust.
Then, from the Keychains list on the left, right-click on the System item and select Lock Keychain "System".
You may have to reboot your system.

Famed Member Admin
Joined: 11 years ago
Posts: 2630
Topic starter  

Tip: if the debugger seems to not always start, change the debugger settings

(in gdb!)

set startup-with-shell off

Or in Lazarus (Lazarus Menu -> Preferences -> Debuuger -> Debugger Backend)

For copy and paste, the text is:

--eval-command="set startup-with-shell off"


Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).