Xcode 14 is not getting attached to Simulator in Debug mode - ios

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:
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 ?

I solved the issue by doing the steps below:
SOLUTION 1:
Edit the scheme
Select Run
Select Build Configuration "Debug"
Select "Wait for the executable to be launched"
Close
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].

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.

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
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

Related

Getting frequent Kill:9 Error in Xcode and Terminal

I have recently upgraded the Mac OS to Ventura 13.2.1 and Xcode to 14.2, now once I try to compile any application with Xcode, I am getting Kill:9 related issue for random task/framework in the project. I also get Kill:9 issue sometime on terminal as well.
Listing the errors here:
failed to read asset tags: The command `` terminated with uncaught signal 9. The command had no output.
Driver threw jobFailedWithNonzeroExitCode(9, "") without emitting errors.
Unable to execute command: Killed 9 Clang frontend command failed due to signal.
Please help me to resolve this issue/crash.
Open project in Xcode.
Build the app with Simulator (I tried with iPhone 14 Pro)
Error occurs in the build
Ideally project should have compiled without any error.
It sounds to me that the problem is with the installation of Xcode because when an unprivileged task is attempted, the OS will kill it off (with signal 9).
What I recommend is for you to re-install Xcode.
When you first run the new Xcode, it should prompt you for an administrator password in order to install system related components. Make sure you do this step. Hopefully that should then allow you to compile and run your iOS apps.

Unable to build app for iOS, "unable to write module session file Session.modulevalidation No such file or directory"

yesterday I was working fine with Flutter, now i'm facing this issue and I already search everywhere for a solution but no success.
When I run:
flutter run
The build process starts and when its about to finish the error below is shown:
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Xcode build done. 12.3s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
error: unable to write module session file at '/Users/hencke/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation': fopen(/Users/hencke/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation, wb): No such file or directory (2)
note: Using new build system
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.
Exited (sigterm)
Looks like the process is trying to open this file Session.modulevalidation for writing, but this file really does not exist in that folder. And I don't know what to do.
Things that I already tried:
Reinstalling xcode
flutter clean
Clone my project again in another folder and try to build, but same error
Created a new flutter dummy project and tried to build, still same error
Rebooting machine several times
Give permissions to Staff to the DerivedData and ModuleCache.noindex folders
Deleted the DerivedData within hope that xcode build will recreate all the files needed, but, it created everything again but not that particular file.
So that's it, If any blessed human know how to 'recreate', or reset, clear some cache, I would be very thankful.
Before running your project, check everything is checked when running:
flutter doctor
and also make sure at least a device is connected or open iOS simulator first. You can check if flutter is successfully connected to the device by:
flutter devices
when you make sure that flutter detect your device or the simulator, then run your application by:
flutter run
After hours I finally found the solution as it follows:
Without any hope I opened my flutter project with Xcode, and then tried to build the Runner target from there, same error.
Then, I was browsing the Xcode preferences and something caught my attention, on Locations section I found something about DerivedData location, it was set as Default. So, I changed from Default to Custom location and I set to a new folder on my home directory:
Then immediately Xcode created the entire DerivedData/ModuleCache.noindex folder and with them, the Session.modulevalidation file as well.
Then I closed Xcode and tried flutter run again, and it was successfully build!
I'll let this answer to those who may come here for help.

Xcode 9.2 Simulator Debugging Broken; Could not attach to process id

Xcode 9.2 debugging on an iOS Simulator has completely broken for me.
I worked on this for hours and tried a ton of suggestions short of completely wiping my hard drive and starting out with a fresh operating system install. I ended up filing a bug with Apple. Posting here in case anyone has encountered this problem and has any suggestions.
Summary:
When try to build and run in debug mode with a debug executable. The simulator only opens the application to a white screen and then Xcode pops up an error:
Could not attach to pid: "<a process id>"
Ensure "<app>" is not already running, and "<user>" has permission to debug it.
Steps to Reproduce:
Make any project and try to run on any simulator.
Expected Results:
Debugger successfully attaches to debugger.
Actual Results:
Debugger is never able to attach to the iOS simulator process/app for debugging.
Debugger CAN attach and build and run successfully on a physical device.
Version/Build:
- Xcode Version 9.2 (9C40b)
- macOS Sierra 10.12.6
- Any iOS project
- Any iOS simulator
Other notes:
- Xcode 9.2 was working fine until this problem randomly started. The error initially said:
Failed to initiate service connection to simulator
DTServiceHubClient failed to bless service hub for
simulator iPhone 8 Plus <simulator identifier>
- After rebooting computer, the error shifted to "Could not attached to pid..."
I tried dozens of suggested solutions short of completely wiping my computer including:
Resetting device contents and settings on simulators
Create a new device (even different device and OS combinations)
Try different Xcode projects, even simple one-off single view applications
Looking at the etc/hosts file and verifying localhost can be pinged
Restarting computer multiple times
Deleting out derived data (multiple times)
Let it build and run without attaching debugger, then try to attach debugger by "attach to process id"
Completely uninstalling Xcode and all simulators, and reinstalling.
Removing any invalid certificates in keychain
It turns out our security software was blocking the debugger. Running sudo sysdiagnose helped me find a log entry showing that it was being blocked. The software is Cb Defense (Carbon Black Defense). Apparently the only workaround is for your security team to whitelist by a hash, and that hash could change in the future.
There is a bug in Xcode 9.0-9.2 that causes this issue to appear after running for a while. If you log out and back in it should resolve it for you.

The request was denied by service delegate (SBMainWorkspace) on iOS 10.0+ simulator & FBSOpenApplicationErrorDomain error 1 on iOS 9.3 simulator. Why?

When trying to run any of the projects that I usually run I'm getting the following errors for different simulators:
The request was denied by service delegate (SBMainWorkspace) for reason: unspecified on iOS 10.0+ simulator
The operation could not be completed (FBSOpenApplicationErrorDomain error 1) on iOS 9.3 simulator.
This issue began when I tried installing a previous version of Xcode 8.2.1 from what I had been using (8.3). I couldn't build any projects in the 8.2.1, but I could still build in 8.3. I named the 8.2.1 a different name in order to be able to run them side by side. This was something I had done before. However, I needed 8.2.1 for a project and so I deleted both and then reinstalled just 8.2.1 according to this post: How to Completely Uninstall Xcode and Clear All Settings.
I've checked the scheme settings in Product > Scheme > Edit scheme > Run > Environment Variables and I've made sure there are no empty environment variables checked. I don't have any environment variables at all now.
I've reset content and settings on the simulators.
I've created a new simulator of a different iOS version. Originally I was just trying on 9.3 and 10.3. I then downloaded the 10.0 and 10.2 and still have the same issue occurring.
I consistently clean my project before running, both (shift + cmd + K) and (shift + alt/option + cmd + K).
I've rebooted my system. I've done everything I can think of. The issue still prevails. What am I missing?!
FBSOpenApplicationErrorDomain error 1, "unspecified" is a catch-all error code for something going wrong during launch that wasn't covered by another error code. There are a couple possible causes for this error code, and it is unfortunate that they do not get displayed in the UI.
I suggest you look in the simulated device's system log to uncover the real cause for the failure. Run this to see all the logs from CoreSimulatorBridge as that logs the full error when it gets it:
xcrun simctl spawn booted log show --info --debug --predicate 'processImagePath contains "CoreSimulatorBridge"'
If that isn't descriptive enough, you might want to also look at the logs for SpringBoard or assertiond, or just use --start and --end to see all the logs for the relevant time range.

debugging xcode 4: says it's running application on device, but nothing actually happens

I can't debug my application on my device with xcode 4. The application builds, links and signs and installs on the device but when xcode 4 says "running on Dev iPad 2" nothing happens on the device.
I've quit and restarted xcode, and restarted the Mac. No difference.
The only warning it gives me is "warning: no debug symbols in executable (-arch armv7)". I'm not sure if that's related to my problem.
If I start the application manually on the device, it works.
I created a small test app. It compiled and ran on the device with no problem.
What could be causing this in my application?
I found this could be fixed by deleting the app from the device, and also deleting the provisioning profile from the device as well.
Check the name of your executable in Build Settings - specifically, make sure that Debug and Release versions have the same name. It may be trying to run an executable that isn't there.
Check the Build settings: Strip Linked Product. In my case I had to set this setting to No. After that the warning was gone.

Resources