Cannot debug Catalyst App: "Message from debugger: Process attach denied"

Hi all,

I have a rather large iOS app that I enabled to run as a MacOS Catalyst App. I can run the app, but when I set the checkmark "debug executable" in the scheme, running the app fails with the following error message:


"Message from debugger: Process attach denied, possibly because System Integrity Protection is enabled and process does not allow attaching."


I'm using XCode 11.4.1.


In the Console log, you can see the following messages:


2020-05-10 10:56:19.787046 +0200com.apple.dt.lldberrordebugservererror: MachTask::TaskPortForProcessID task_for_pid failed: ::task_for_pid ( target_tport = 0x0103, pid = 28030, &task ) => err = 0x00000005 ((os/kern) failure)
2020-05-10 10:56:19.787133 +0200com.apple.dt.lldbdefaultdebugserver10 +0.010309 sec [6d7f/0307]: error: ::task_for_pid ( target_tport = 0x0103, pid = 28030, &task ) => err = 0x00000005 ((os/kern) failure) err = ::task_for_pid ( target_tport = 0x0103, pid = 28030, &task ) => err = 0x00000005 ((os/kern) failure) (0x0000000
2020-05-10 10:56:19.799117 +0200com.apple.dt.lldberrordebugservererror: MachTask::StartExceptionThread (): task invalid, exception thread start failed.
2020-05-10 10:56:19.799177 +0200com.apple.dt.lldberrordebugservererror: MachProcess::AttachForDebug failed to start exception thread: unable to start the exception thread
2020-05-10 10:56:19.799398 +0200com.apple.dt.lldberrordebugservererror: Attach failed because process does not allow attaching: "unable to start the exception thread".
2020-05-10 10:56:19.799437 +0200com.apple.dt.lldbdefaultdebugservererror: attach failed.
2020-05-10 10:56:19.800153 +0200com.apple.dt.lldbdefaultdebugserver11 +0.013004 sec [6d7f/2903]: error: ::read ( 6, 0x70000b99bb00, 1024 ) => -1 err = Bad file descriptor (0x00000009)
2020-05-10 10:56:19.800499 +0200com.apple.dt.lldbdefaultdebugserverExiting.


If I create a fresh iOS app and enable Catalyst, everything works fine. So I guess it's something with the Build settings or similar.


Thanks,
Markus

Answered by DTS Engineer in 420132022

If I create a fresh iOS app and enable Catalyst, everything works fine. So I guess it's something with the Build settings or similar.

Right. This typically means that your app is missing the get-task-allow entitlement (

get-task-allow
on iOS,
com.apple.security.get-task-allow
on macOS). I’ve seen two causes for this:
  • The Code Signing Inject Base Entitlements (

    CODE_SIGN_INJECT_BASE_ENTITLEMENTS
    ) build setting not being set
  • The Deployment Postprocessing (

    DEPLOYMENT_POSTPROCESSING
    ) build setting being set

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

If I create a fresh iOS app and enable Catalyst, everything works fine. So I guess it's something with the Build settings or similar.

Right. This typically means that your app is missing the get-task-allow entitlement (

get-task-allow
on iOS,
com.apple.security.get-task-allow
on macOS). I’ve seen two causes for this:
  • The Code Signing Inject Base Entitlements (

    CODE_SIGN_INJECT_BASE_ENTITLEMENTS
    ) build setting not being set
  • The Deployment Postprocessing (

    DEPLOYMENT_POSTPROCESSING
    ) build setting being set

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your quick answer. Code Signing Inject Base Entitlements is set, but Deployment Postprocessing was also set. Unsetting it didn't help though.


I used your trick from another post to get the entitlements:


codesign -d --entitlements :- <pid>


and got the output

....

<key>com.apple.security.network.client</key>

<true/>

<key>get-task-allow</key>

<true/>


So it looks like the wrong "get-task-allow" is enabled, the iOS one instead of the MacOS one?

So it looks like the wrong "get-task-allow" is enabled, the iOS one instead of the macOS one?

Right. I just created a simple test app here in my office and the Mac build definitely gets

com.apple.security.get-task-allow
. Given that you don’t see the problem with a new project, I presume that this will be the same at your end.

It’s seems likely that your main project has a lurking build setting that triggers this problem. I don’t have any other suggestions as to what that might be, but I can explain how I tracked this down the last time:

  1. Create a new branch in your source control system for the purposes of this test.

  2. Take your existing project and remove all the code and resources from it (other than a minimal

    main
    function).
  3. Build it; it should build really quickly (-:

  4. Confirm that it still reproduces the problem.

  5. Commit this version of your project.

  6. Compare its build settings to your new project and unify the most obvious discrepancies.

  7. Repeat steps 3 through 6 until the problem goes away.

  8. Look at your latest commit to see what you actually changed. If you changed multiple things, redo the above for once for each of those changes.

  9. Switch back to your main branch and apply that change.

  10. Profit!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your instructions! Strange, when I was about to get started with them, I tried one more time and it worked! I swear it didn't work the day before and I did a clean build folder to make sure. In the end, it was the Deployment Postprocessing setting. Sorry for your extra time and thanks again.

Cannot debug Catalyst App: "Message from debugger: Process attach denied"
 
 
Q