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 https://raw.githubusercontent.com/Homebrew/install/master/install.sh )"
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:
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"
- 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.