I am trying to debug an iOS app in Xcode. My scheme is with the Build Configuration in Debug. When I run the application, the Debug panel opens but when the application opens in the simulator or on the device, the panel closes and does not allow me to debug.
What are the conditions that must be met in order to debug an application in Xcode?
My Xcode version is 11.3.1.
My macOS version is 10.15.2.
Update 1
I put image of my configurations:
When I try to attach the debug to simulator by "Attach to Process by PID or Name..." I have the following error:
The scheme you are running must be enabled for Debugging. This is the default but it might have been changed, by accident, or during experimentation.
Here is a correct example, enabling debug.
Ensure you have set some breakpoints.
Furthermore, it might be that your preference settings are incorrect for debugging.
The following settings need to be checked in Xcode > Preferences; Behaviour Tab.
Note two checked items for the Running Pauses left panel selection:
Note that when Xcode is installed, upon first use it will prompt for Developer Access to your system requiring a password for the Administrator privileged account (normally your own account has such privilege).
In order for debug attach to work, Developer Mode must be enabled. This can be checked:
# DevToolsSecurity -verbose -status
Getting rights definition for: system.privilege.taskport.debug
Current rights definition dictionary:
"k-of-n" : 1
"class" : "rule"
"created" : 582290628
"version" : 0
"modified" : 589046609
"comment" : "For use by Apple. WARNING: administrators are advised
not to modify this right."
"rule" : { "is-admin", "is-developer", "authenticate-developer" }
Developer mode is currently enabled.
To enable developer mode if it is not enabled, use
# sudo DevToolsSecurity -enable
Put breakpoints to your code whatever you want to debug by clicking the number of line.
Hope it helps...
Related
When I running an application shared extension from XCode run button and then trying to share files, XCode shows the below error frequently. Anyone have any idea whats causing it?
Error: "cannot attach to process due to System Integrity Protection"
System Integrity Protection(SIP) aka rootless is a new security feature in OS X 10.11. By default it disables even the administrator to access/modify the root. Follow these steps to disable SIP:
Restart your Mac.
Before OS X starts up, hold down Command-R and keep it held down until you see an Apple icon and a progress bar. Release. This boots
you into Recovery.
From the Utilities menu, select Terminal.
At the prompt type exactly the following and then press Return:
csrutil disable
Terminal should display a message that SIP was disabled.
From the menu, select Restart.
You can re-enable SIP by following the above steps, but using csrutil enable instead.
In some cases, if you are trying to connect to a "system provided" executable (for example, Terminal.app) there is a workaround by making a copy of such executable. The copy will be checked by SIP as "user installed" instead of "system provided".
For an example, see
"Launching the Terminal app from Xcode on OS X with System Integrity Protection"
Sometimes I also get this error on Xcode while trying to run an app on simulator. Usually I only run the app again, and at most I restart the simulator, and it solves the problem.
Be aware of the security risks you're incurring on disabling SIP (System Integrity Protection):
https://support.apple.com/en-us/HT204899
I am used to creating a Release schema for OSX applications, whereby I switch build mode to Release, and set the debugger to None. This removes the breakpoint info from the app and optimises it.
Although I can set the Release mode for the IOS applications, there is no way to set the debugger to None. And, it occurs that in the Release mode the breakpoints are still honored by XCode 5.5.1, which tells me that the debug info is still compiled into the app.
How can I make sure that my IOS app is as pristine as possible, and does not have debug info, and does not fire the breakpoints in Xcode, while running on the device?
Thanks.
EDIT: Solution is to set "Generate Debug Symbols" to No in Release build.
Having breakpoints enabled (or not) doesn't change the size of your code. Your Release scheme should be setting "Optimization Level" -Os, "Symbols Hidden by Default" to Yes and "Strip Debug Symbols During Copy" to Yes. All of these are default options in new projects, so you really shouldn't have to change anything.
Even in a release build, breakpoints will still function because the symbolic information is stored separately from the built product.
I think your confused on breakpoints vs debugging symbols. Your release build by default should remove debugging symbols from the final product. However that doesn't stop you from attaching a debugger to it. You can hook a debugger up to any app you want (mostly true), however if the debugging symbols are striped then all you'll be able to see is the assembly instructions. This is what you see when you try to step into Apples frameworks from your own code.
I am working on an iOS app and I have noticed a bug that is only reproducible when the app is built in release mode. The only way I have found to run a release mode app that I have built is by building an archive, signing it with my debug profile, and doing an ad-hoc deployment to my device. Using this method however I can't attach with a debugger, and I'm not even sure if I could attach it if it would work well after the release build had run the optimizer on the code.
Does anyone know of a good way to debug an issue that is only reproducible when an app is build in release mode?
Normally Debug builds have optimisation disabled (-O0) to make debugging easier, whereas Release builds have optimisation enabled (-O3 or -Os), which makes the code run much faster, but also makes debugging harder (but not impossible). You can just go into the build settings in Xcode in the Debug configuration and temporarily turn up the optimisation level - this will keep all the other debug goodies (symbols etc) but hopefully also flush out the Release mode bug. (Don't forget to reset the optimisation level to -O0 in the Debug configuration when you're done!)
Go to "Project" command in an Xcode application menu and chose "Edit Scheme"(Shortcut: ⌘< )
Select "Run Project name" in left pane
In right pane, under "Info" tab change "Build Configuration" to "Release"
You can not run an app in release mode while have having debugging turned on. That is not intended.
When running an app in release mode you have to find a different way to observe the behaviour of your app (e.g. using alerts).
Additionally you will have to trust the distribution profile on your device. Xcode will notify and guide you with an alert message on the first run.
To debug an iOS application in release mode modify the settings:
Build Settings -> Deployment -> Deployment Post Processing -> Release -> set value as "NO"
Set 'Deployment Post Processing: Release' value as 'No'
I had to briefly turn on automatic signing in order to accomplish this. You aren't able to build directly on device with an iOS Distribution certificate (you need an iOS Development certificate) and you can't release to the App Store with an iOS Development certificate (you need an iOS Distribution certificate).
My debug mode was configured to use an iOS Development certificate to build directly on device. My release mode was configured to use an iOS Distribution certificate to allow the app to be installed on all devices. In order to run in release mode on device I switched to automatic code signing briefly to test. Once I was done testing, I used git to revert to the previous Xcode configuration.
Not the most elegant way, but it got the job done.
I have an issue I am troubleshooting which occurs very infrequently and doesn't seem to happen when I have things running under Xcode.
Is it possible to run an app normally (i.e. from Springboard) until my issue occurs, and then attach a debugger at that point?
I would prefer to do this without jailbreaking if possible.
Attach your device connected your Mac
Debug > Attach to Process by PID or Name
In the dialog sheet, enter the name of your App as it appears in the Debug navigator when started via Xcode (e.g. Target's name not bundle-id).
If the app is already running, the debugger will attach to the running process. If it isn't running, it will wait for the app to launch and then attach.
I'll leave this here since neither of the other 2 answers gave me quite enough detail without a little bit of a struggle.
Run your app in the simulator and take note of the name in the Debug navigator
Plug in your device and don't forget to select your device as the target
Debug > Attach to Process > By Process Identifier (PID) or Name
Enter the name from step 1 and attach. That should be all you have to do.
In Xcode 5.0.1 and 6 it's the menu bar items:
Debug > Attach to Process > By Process Identifier (PID) or Name...
In Xcode 7 it's just:
Debug > Attach to Process by PID or Name...
I was able to debug the app by adding a breakpoint on the AppCoordinator file init() method on the super.init() line.
I was able to turn off the wifi/internet and then by pass the developer verification.
I'm starting to use Instruments-Leaks with an iPhone 3G. When I try to run the app with Instruments on the iPhone I obtain
Target failed to run: Remote exception encountered: 'Failed to get task for pid 280'
Ideas?
The only time I succeed in running the app with instruments it run very slow, I couldn't test it.
What are the steps to run the app on the device searching for leaks?
The solution for me was to make sure that my Profile scheme was using the "debug" and not "release" build configuration.
In Xcode 4 select Product/Edit Scheme from the top menu
then click on the "profile" button on the left.
On the "info" pane you will see a setting for Build Configuration- set that to "debug"
This error is also thrown if you are trying to test your app on a device with a distribution profile selected. Make sure you have the correct code-sign settings for development.
You CAN profile the release build on the device. What you have to do is build the release build with a developer certificate. See here.
Instruments basically does its work by becoming the debugger for the app. If you can't run Xcode's debugger against it, then you can't run Instruments against it.
Mostly, entitlements need to be set to allow debugging.
Sometimes after using XCode to debug apps, I find I can't use Instruments until I reboot the device.
Unlike XCode, Instruments can be confused between two apps with the same name, but different bundle IDs. (Or perhaps same name and similar bundle IDs.) When I have multiple versions of an app on a device, I often have to delete the extra to get Instruments to connect to the correct app. If you have one debug build and one release build, this could be the problem.
So, delete any duplicates of your app and restart the device. (You could change the display name for release and debug build configurations.)