I encountered this error too running XCode 10.2.1 on macOS 10.14.5.
In my case, this didn't have to do with Hardened Runtime, but rather my "Debug Process As" setting.
I had to edit my scheme settings, and instead of debugging the process as me, I had to debug process as root. Not sure why this works, but hope it's helpful.
This problem is most likely related to entitlements. In general, the hardened runtime prevents the debugger from attaching to your process. When you do a Product > Run, Xcode adds an entitlement to your app (
com.apple.security.get-task-allow) that allows the debugger to attach. In other situations — for example, when you do a Product > Archive — that’s not the case.
IMPORTANT This entitlement isn’t added to your
.entitlementsfile, but directly to the app. Use this command to see it:
$ codesign -d --entitlements :- /path/to/your.app
It sounds like Xcode isn’t adding this entitlement for you. One possibility is that you’ve disabled the Code Signing Inject Base Entitlements (
CODE_SIGN_INJECT_BASE_ENTITLEMENTS) build setting.
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
I saw this problem too, with a simple command-line C++ tool. My project(s) have "Automatically manage signing" checked, and I verified
CODE_SIGN_INJECT_BASE_ENTITLEMENTSwas Yes for Debug and Release. I'm on Xcode 10.3, Mac OS 10.14.6.
Debugging the tool worked fine on the machine where I created the project (same Xcode/OSX versions), but checking the project out of git on a different machine, this problem occurred - I hit run but it never hits the entry point of main and the same error is reported (but oddly it hides the console & you have to open it to see it). Like the poster above, running as root works around the issue, but for many reasons I do not want to do that.
Messing with my signing certificate ended up fixing the problem. In Keychain access I noticed my Mac OS Developer certificate was in System Roots but not in login. I dragged it into login. Then in the Xcode project Info settings (showing signing setup), there was an error message saying I needed to remove the current signing certificate in order to pick up the correct one. I clicked okay and the warning went away. Now, for some reason, there are two different copies of my Mac Developer signing certificate in keychain - same ID#, one dated a month ago, another dated today.
The good news is, it seems to be fixed, though there seems to be something a little off with the "Automatically manage signing" setting and keychain's management of certificates - either that or I did something wrong while setting it up (with a different project).
I was able to work around this by setting the "Code Signing Identity" to "Sign to Run Localy" and also changing "Enable Hardend Runtime" to "No". Both of these settings are in the build settings of the target under signing.