Page 1 of 1
Forum

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!



Share:
Notifications
Clear all

[Solved] macOS - Lazarus - Install GDB as debugger through HomeBrew

2 Posts
1 Users
0 Reactions
1,154 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2727
Topic starter  

I keep running in to LLDB issues, so I figure; why not give good old GDB another try.
Building from source was a little much and HowBrew alreayd provides version 13.x at the time of this writing.

Note: I do assume that you have an official developer certificate from Apple (something like "Developer ID Application: John Doe (X5G11N0FH1)").
You can of course generate your own certificate (so called "self signed") but since I have to pay for mine yearly so I can provide free signed and notarized software here, I figured I'd rather use that.

 

So this is how I go this to work:

1) Install homebrew if needed:

/bin/bash -c "$(curl -fsSL  https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh )"

2) Install GDB (v13.x):

brew install gdb

3) Create an entitlements file.

I called it "gdb-entitlements.xml" and just placed it in the dir I'm working in (in my case in ~ ).

Content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.debugger</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
</dict>
</plist>

4) Codesign with your own certificate:

Note: replace <YOUR CERTIFICATE NAME> with the full name as shown in Keychain in the section "Name" next to field "Common Name", something like "Developer ID Application: John Doe (X5G11N0FH1)".

codesign --entitlements gdb-entitlement.xml -fs "<YOUR CERTIFICATE NAME>" $(which gdb)

5) Optionally verify signing if needed with:

codesign -vv $(which gdb)

Now in Lazarus, go to "Lazarus" - "Preferences" - "IDE Options" - "Debugger" - "Debugger backend" and set it to standard GNU Debugger, path "/usr/local/bin/gdb".

Note:

  • When debugging you may need to to a Clean Up and Build for your project as it may still contain invalid debug info.
  • You may need to set debugger on project level as well, in case you have changed that in the past to a non-default debugger.
  • For your project make sure Options -> Compiler Options -> Debugging -> "Type of debug info" is set to "Automatic" in case you had set that to something else in the past.
  • I had to restart Lazarus once for some reason before the debugger kicked in correctly.
    Somehow it gave an error. After restarting Lazarus GDB worked just fine.
  • I tested this on Monterey (Intel Mac).

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2727
Topic starter  

NOTE:

Even though GDB is said to support Apple Silicon, the GDB setup through Brew does not support Apple Silicon (yet).

gdb: The x86_64 architecture is required for this software.
Error: gdb: An unsatisfied requirement failed this build.

   
ReplyQuote
Share: