How to debug a native application on MacOS

I’m going to answer my own question here since I think I finally figured it out.

I wasn’t signing gdb properly. The steps I had been following on line weren’t up-to-date with the moving target that is MacOS’s security requirements.

The command I had been running:
codesign -fs gdb_codesign $(which gdb)

Doesn’t seem to be enough.

What I needed to do was to create an entitlement XML with text like this:

<?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.debugger</key>
    <true/>
  </dict>
</plist>

And then run this command to codesign gdb:
codesign --entitlements gdb-entitlement.xml -fs gdb_codesign $(which gdb)

Finally, I’m able to get the integrated debugging experience in VSCode on MacOS with my native project.

1 Like