Unable to Debug macOS Action Extension: "Attach failed" Error

Hello everyone,

I'm encountering an issue while trying to debug a macOS Action Extension. I created a completely fresh project with an Action Extension target. When I select the Action Extension scheme and run it, choosing Finder as the host app (app to launch it in), I receive the following error:

Attach failed: Could not attach to pid : “647”. (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.)

This is in Console.app:

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

I am pretty sure it worked before on my project that I am developing. It stopped working and now it doesn't even work on a fresh new project.

Any ideas? I tried cleaning derived data, restarting my mac, nothing helps.

As per the documentation it should work normally using the Build & Run button.

Just to set a baseline, can you use Debug > Attach to Process to attach to your extension after it’s been launched in the normal way?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I am not even sure I understand how to properly install new versions.

Right now it seems I have a remnant. The extension is shown upon right-click on an item in Finder and is also visible in the Quick Actions selection menu, even though the container app is not installed in the /Applications directory and the build folder is cleaned.

What is the best way to clean everything and making sure I have a clean slate?

To be on the same page it is an extension that just compresses and converts an image. I tried what you said -> I built the app, moved the .app from build to the /Applications directory (to have the latest, not sure if this is the correct approach?), launched it normally via the right click/quick actions and then I tried Debug > Attach to process and selected it from the likely targets. Xcode ran it again and attached the debugger but when I try to use the lldb to po context or just to step over for example it crashes with exit code 9.

@DTS Engineer

Based on a post i found I tried deleting

~/Library/Preferences/com.apple.dt.Xcode.plist
~/Library/Caches/com.apple.dt.Xcode

Which helped in the way that I can now Run the extension like a normal app, just choosing Finder as the host app. It hits the breakpoint but the same issue as above -> crash upon stepping over or upon usage of lldb.

Right now it seems I have a remnant.

Yeah, this is tricky on macOS because app extensions are embedded in apps and apps can be placed anywhere on the system. Sometimes you can fix things using the lsregister tool to tell the system where the app is and the pluginkit tool to manipulate the appex database.

crash upon stepping over or upon usage of lldb.

If you choose Process > Detach, does it crash? And do you get a crash report?


Hmmm, another way I’ve found of dealing with this is to create a dummy ‘appex host’ app target in my appex project. I then target that rather than the Finder. The app is development signed, and thus avoids all the attachment drama associated with the Finder.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Based on this post I used the pluginkit to run

pluginkit -v -m -D -i <extensionBundleId>

and removed the .app from all the paths it found (I had some old one lingering in an accidental .xcarchive).

This allowed me to Run the extension as a normal app, choose Finder as Host and successfully attach. (I suppose this approach can serve as a 'clean slate'?).

However the issue persists -> the debugger (or the extension, not sure which) crashes when I try to po something or show the Variables view.

If you choose Process > Detach, does it crash? And do you get a crash report?

Yes it does. The same crash. It just turns off, debug view dissapears and I get the:

"Couldn't communicate with a helper application."

Not sure if I get a crash report. Don't see anything in the Console.app.

Please bear in mind that this same exact scenario happens in a completely fresh new project with the Apple's boilerplate action extension code. I can run & attach but cannot debug.

Should I try the approach with the dummy appex host? How exactly would I create that target inside the appex project?

Should I try the approach with the dummy appex host?

That’s what I’d do.

How exactly would I create that target inside the appex project?

In the usual way: Choose File > New Target and select the macOS > App target. Then, in the app, add some UI that triggers the system’s action extension support [1].

[1] I haven’t done this for an action extension before, but a long time ago I did it for a share extension by showing an NSSharingServicePicker.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Unable to Debug macOS Action Extension: "Attach failed" Error
 
 
Q