Hello! I have a baffling situation happening on two different computers in which Xcode (14.2.0, on MacOS 12.6.1) is not being able to attach a debugger. This is happening for completely-fresh-from-scratch apps, both for MacOS and iOS apps. In both cases, the app eventually launches, but Xcode is not able to debug. Following the error message's suggestion, I looked in Console.app and as best as I can tell the proximate cause for the issue is task_for_pid failing; this message is preceded by a number of errors from com.apple.dt.instruments.dtarbiter:
Code validity check error: Error Domain=NSOSStatusErrorDomain Code=-67050 "(null)"
So my working hypothesis is that something is preventing the application from launching "normally" and so the debugger can't attach as it normally would.
Things I have tried:
- Removing DerivedData, rebuilding
- Making sure that "Developer Mode" is enabled (via
DevToolsSecurity -enable) - Ensuring that the resulting binary has the
com.apple.security.get-task-allowentitlement, and that "Code Signing Inject Base Entitlements" is set to "Yes" - Disabling Gatekeeper system-wide
I have also spent a while looking around with codesign and spctl. To my (admittedly non-expert) eye, codesign's output looks about right:
[~/Library/Developer/Xcode/DerivedData/DirectoryScratch-cpyzkrtfugtxdugtobmjfbotrxrj] % codesign -d -vvv --entitlements :- Build/Products/Debug/ContentView.app/
Executable=/Users/bedricks/Library/Developer/Xcode/DerivedData/DirectoryScratch-cpyzkrtfugtxdugtobmjfbotrxrj/Build/Products/Debug/ContentView.app/Contents/MacOS/ContentView
Identifier=org.bedrick.ContentView
Format=app bundle with Mach-O thin (x86_64)
CodeDirectory v=20500 size=1091 flags=0x10000(runtime) hashes=23+7 location=embedded
Hash type=sha256 size=32
CandidateCDHash sha256=cf6f08586662c29420bf3ab7e673d0614b2c7717
CandidateCDHashFull sha256=cf6f08586662c29420bf3ab7e673d0614b2c771758ec9dce33fa7982fdab2267
Hash choices=sha256
CMSDigest=cf6f08586662c29420bf3ab7e673d0614b2c771758ec9dce33fa7982fdab2267
CMSDigestType=2CDHash=cf6f08586662c29420bf3ab7e673d0614b2c7717
Signature size=4785
Authority=Apple Development: Steven Bedrick (X8L6RQQBAR)
Authority=Apple Worldwide Developer Relations Certification Authority
Authority=Apple Root CA
Signed Time=Jan 9, 2023 at 2:03:55 PM
Info.plist entries=19
TeamIdentifier=2E7A87Y536
Runtime Version=13.1.0
Sealed Resources version=2 rules=13 files=0
Internal requirements count=1 size=188
Warning: Specifying ':' in the path is deprecated and will not work in a future release
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.app-sandbox</key><true/><key>com.apple.security.files.user-selected.read-only</key><true/><key>com.apple.security.get-task-allow</key><true/></dict></plist>
If I ask codesign to --verify my .app bundle, this is what I get:
[~/Library/Developer/Xcode/DerivedData/DirectoryScratch-cpyzkrtfugtxdugtobmjfbotrxrj] % codesign -vvvv -R="notarized" --check-notarization -vvvv Build/Products/Debug/ContentView.app/
Build/Products/Debug/ContentView.app/: valid on disk
Build/Products/Debug/ContentView.app/: satisfies its Designated Requirement
test-requirement: code failed to satisfy specified code requirement(s)
[~/Library/Developer/Xcode/DerivedData/DirectoryScratch-cpyzkrtfugtxdugtobmjfbotrxrj] %
So something does appear to be "up" with the signature/notarization, but I am not sure how to get more information about what the issue might be (turning up the command's verbosity does not give more information). Now, turning to spctl:
[~/Library/Developer/Xcode/DerivedData/DirectoryScratch-cpyzkrtfugtxdugtobmjfbotrxrj] % spctl -a -v --raw Build/Products/Debug/ContentView.app/
Build/Products/Debug/ContentView.app/: rejected
<?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>assessment:authority</key>
<dict>
<key>assessment:authority:flags</key>
<integer>0</integer>
</dict>
<key>assessment:remote</key>
<true/>
<key>assessment:verdict</key>
<false/>
</dict>
</plist>
So Gatekeeper is clearly "unhappy" with this file; I had thought that apps launched via Xcode itself were supposed to bypass Gatekeeper, but maybe that's not true? And in any event, I am able to launch the resulting .app file from the Finder without any issues.
This is happening on two separate computers, so my next thought was that it might be some kind of issue with my Apple ID? But on a third computer my same Apple ID works just fine for signing and running apps for local development. As best as I can tell I've got them all configured the same way in terms of which certificate/team they are using, etc. though it is certainly possible that I messed that up somehow. They're all running the same version of Xcode and MacOS.
One (possibly relevant) difference is that the two non-working machines are managed by my work's IT department, and my user there is part of an ActiveDirectory profile of some kind. The working machine is my own personal laptop. All three machines have Gatekeeper enabled (I tried turning it off system-wide and it did not fix it), and on all three machines my user is part of the "admin" and "_developer" groups, at least according to the groups command. I don't know what-all sort of remote management / security software they may have installed, is it possible that something along those lines could globally prevent task_for_pid attachment?
Any thoughts, advice, debugging ideas, magical shell invocations, etc. would be most welcome. Thank you!