7

While debugging any iOS application, Xcode builds and run successfully, also launches a simulator but it is not able to attach debugger from Xcode 14 to Simulator iOS app.

It throws an error in Xcode:

enter image description here

Xcode console says:

Could not attach to pid : “75997” Domain: IDEDebugSessionErrorDomain Code: 3 Failure Reason: 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.) User Info: { DVTRadarComponentKey = 855031; IDERunOperationFailingWorker = DBGLLDBLauncher; RawUnderlyingErrorMessage = "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.)"; }

Tried with re-installing Xcode and Command line tools, but issue persists.

Steps:

  • Build and run app with Debug executables true
  • Simulator gets launched
  • Error on Xcode and it gets disconnected from simulator

Is there a possibility that it can be blocked by any other app, if so how to identify ?

Mrunal
  • 13,982
  • 6
  • 52
  • 96

4 Answers4

2

I solved the issue by doing the steps below:

SOLUTION 1:

  1. Edit the scheme
  2. Select Run
  3. Select Build Configuration "Debug"
  4. Select "Wait for the executable to be launched"
  5. Close
  6. Run the app

see the screenshot here

You will receive an error message when you run the app again. Close the app. Edit the scheme again and change "Wait for the executable to be launched" to "Automatically".

Now your simulator will work as expected.

SOLUTION 2:

Delete your app folder in Derived Data /Users/[your username]/Library/Developer/Xcode/DerivedData/ Search your app name folders and delete them.

SOLUTION 3:

Open the terminal and run:

sudo DevToolsSecurity -enable

This command enables the Developer Mode. After running the command you will receive this message: [Developer mode is now enabled].

Wilson
  • 386
  • 3
  • 4
  • Tried all these, none of those helped. Additionally I have tried installing Xcode 14.1 (previously I had v14) but still seeing same issue. Even normal hello world application doesn't work with Debug mode. – Mrunal Nov 11 '22 at 12:16
  • 3
    I did all these things, and after updating my Xcode 14 to 14.1 (14B47b) my simulator started to freeze as well. The issue is: I run my app for the first time on simulator. When I try to re-install the app by clicking on CMD + R, or clicking on Xcode Stop button, it looks like the Xcode doesn't send the command to stop the debug task on simulator and doesn't close the app. So the app is stuck on simulator. The only way to solve this issue in my Mac Pro M1, is closing/or restart the simulator every time I have to install the app. – Wilson Nov 18 '22 at 19:19
  • @Wilson I have the same problem, have you found a way to fix it? – Sigit Dec 20 '22 at 15:17
  • 2
    Hi @SigitHardianto, I updated my Xcode to 14.2(14C18) and I keep having the same issue. – Wilson Dec 22 '22 at 19:13
  • 1
    @Wilson exactly. Issue still persists. Did anyone get the solution? – if-else-switch Dec 28 '22 at 12:57
  • 1
    Same issue here - XCode 14.2, OSX Ventura. I have tried all of the above suggestions and nothing works. For a smaller, different project, it works fine. But for my largest (and most important) one, it fails every time. This is a recent development, it only started happening after the latest OSX update (13.3). – Wyllys Apr 02 '23 at 14:58
  • Hi Guys. I updated my MacBook M1 to Ventura 13.3, and uninstalled my XCode removing all Xcode files, caches, etc. The Xcode 14.3 (14E222b) was installed, and the issue has been gone for the first three app installations on simulator. After that, the issue persists. Every time I've compiled the app by clicking on Xcode "run" button or "Command + R" the simulator does not close the applications and I have to close the simulator manually. And does not matter if I run the app on tvOS, iPhone, or iPad simulator. The issue occurs in all simulators. I guess it is an issue with Xcode and big projects. – Wilson Apr 05 '23 at 16:58
  • I opened an Apple support ticket and I am waiting for a response. – Wilson Apr 05 '23 at 17:32
1

Sometimes it's happen, when you are trying to build too fast after a build has started.

First of all, quit your current simulator, delete derived data and clean the project, wait until whole processing is complete. Then do some changes / editing if required (as we clean all data) and try running on a different simulator.

Check certificates in key-chain access, if you found any untrusted certificates in key-chain access remove it.

Also if you are using beta version just make sure it is downloaded from Apple official website.

Khyati Modi
  • 630
  • 1
  • 9
  • 19
1

Came here to share my (strange) solution if anybody crosses the same problem with no answers working. In my case, no solution from this nor other SO answers to similar questions worked (cleaning, rebuilding project, updating, clearing derived data..)

My setup is:

Macbook M1 2022 + Xcode Version 14.2 (14C18)

This Xcode version could not attach to any of my apps (fresh new or previously developed) on different simulators (11, 12, 14) with iOS versions 13.7 - 16.2.

Editing scheme solution from answer above was not working also so I ended up in leaving scheme as:

Build configuration: Release
Debug executable Deselected(!)
Launch Automatically

edit scheme window

And magically debugging app in Xcode started working even though it's release version with debug option deselected.. Selecting Debug executable again makes Xcode not possible in attaching to app process


Just to clarify: above steps actually makes app to run as in DEBUG mode - Xcode attaches to pid, I can do console logs and breakpoints. This Xcode version behaves opposite than options selected

scheme_with_console_logs

deevee
  • 1,550
  • 15
  • 21
  • In this case your app is not running in debug mode, which mean you cannot have any breakpoints or console logs. – Mrunal Jan 18 '23 at 10:39
  • @Mrunal no, the opposite - with above scheme config app is debuggable, i can do console logs and breakpoints, xcode attaches to it's pid, that's why I shared this answer. Please checkout added screenshot with scheme config and console logs in background printing just fine – deevee Jan 18 '23 at 12:46
  • Yep. I can confirm. For some strange reason, it works as described. My env: M1 Xcode 14, Ventura – Ozx Mar 03 '23 at 05:13
  • Mine is intel based machine and it creates problem with one of my biggest project for rest others it works fine. – Mrunal Apr 05 '23 at 15:14
0

There was on security software installed in machine which was blocking this simulator to attach.

To get more information, when we receive that alert we should check in Console.app for our Simulator app process id and notice issues/errors.

After uninstalling that app, this issue is resolved and able to attach app through debug mode.

Mrunal
  • 13,982
  • 6
  • 52
  • 96