Search code examples
xcodemacosdebuggingmacos-monterey

Why Xcode can not attach to some programs?


i had to reinstall my MacBook Pro. I have installed the newest macOS & Xcode version so

macOS Monterey 12.0.1 (21A559) and Version 13.1 (13A1030d)

I'm programming Audio plugins so to test my plugins I'm normally running a DAW (Digital Audio Workstation) in my case I'm working the most of the time with Ableton or Bitwig.

So if I start the debuging process, I get the follow error: Could not attach to pid XXXXXX attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)

If I have an eye to the console.app the the following lines:

[LaunchAttach] (3277) about to task_for_pid(2930)

error: [LaunchAttach] MachTask::TaskPortForProcessID task_for_pid(2930) failed: ::task_for_pid ( target_tport = 0x0203, pid = 2930, &task ) => err = 0x00000005 ((os/kern) failure)

macOSTaskPolicy: (com.apple.debugserver) may not get the task control port of (BitwigStudio) (pid: 2930): (BitwigStudio) is hardened, (BitwigStudio) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger(com.apple.debugserver) is not a declared read-only debugger

1 +0.000000 sec [0ccd/0103]: error: ::task_for_pid ( target_tport = 0x0203, pid = 2930, &task ) => err = 0x00000005 ((os/kern) failure) err = ::task_for_pid ( target_tport = 0x0203, pid = 2930, &task ) => err = 0x00000005 ((os/kern) failure) (0x00000005)

I have done some research and found this: Stackoverflow link about What does get-task-allow do

get-task-allow, when signed into an application, allows other processes (like the debugger) to attach to your app. Distribution profiles require that this value be turned off, while development profiles require this value to be turned on (otherwise Xcode would never be able to launch and attach to your app).

So there is nothing I can do to debug my programs with that software. Is that correct? :(


Solution

  • You can debug but you have to set the "Code Signing Inject Base Entitlements" to "Yes" for debugging

    enter image description here

    And then you have to add a provisioning profile. Go to developer.apple.com then select "Certificates, IDs & Profiles" to create a provisioning profile for the bundle ID you are testing.