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.

Answered by DTS Engineer in 796611022

Yes please.

And I’d appreciate you posting you bug number, just for the record.

Share and Enjoy

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

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"

I sincerely apologise for the delay, was stuck on other projects.

The approach you suggested is not exactly solving my problem because I am creating a Finder (Quick Action) extension. Therefore I need to be able to debug it in Finder.

As I mentioned, it's not even working in a fresh Apple boilerplate project. I tried the new Xcode beta, but the issue persists, so it's likely not an Xcode bug?

I also tried to run

sudo DevToolsSecurity -enable

but that did not help.

I fail to see what has changed since I was able to normally debug before. Some config? Something in my development profile (I didn't change anything). Not really sure. It it an lldb issue? Given that I am able to attach, step over a few times, but more 'heavy' stuff like po or stepping in/out, resuming execution crashes?

I fail to see what has changed since I was able to normally debug before.

Roughly how long ago was that?

Also, is there any chance you had SIP disabled previously? See Disabling and Enabling System Integrity Protection.

IMPORTANT I’m not recommended that you disable SIP, just that it might explain why you’re seeing this change in behaviour.

Share and Enjoy

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

The project started in February 2024.

I could (and now I can again) attach a debugger and print to console, which is good enough since I can just use print() statements everywhere.

I never touched SIP.

Thinking back about it, the debugger probably always crashed after po or a few step overs. It's possible the proper debugging has never worked and it has not changed during the lifetime of this project. Might be worth reporting as a bug?

Might be worth reporting as a bug?

Probably.

When reporting a bug like this, it’s best to try and reproduce it with a small test project. If you can, that’d make an ideal bug report.

Failing that, if you’re willing to share your code then that’d also make an actionable bug.

Failing that, things get trickier. It’s possible to file a bug using just the Xcode Sysdiagnose for macOS instructions, from our Bug Reporting > Profiles and Logs page, but such bug reports are much harder to investigate.

For a bunch more hints and tips on filing bugs, see Bug Reporting: How and Why?

Share and Enjoy

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

I already managed to reproduce it with just the starting boilerplate, with no code change.

Should I use the Feedback Assistant?

Yes please.

And I’d appreciate you posting you bug number, just for the record.

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