iPhone Device Debugging - iphone

Is it possible to actually use the Xcode debugger when running an iPhone app on the device rather than the simulator? i.e., can I have the device stop at breakpoints that I set in my code and step through the code as it runs on the device?
EDIT: I should mention that I am a registered developer with Apple and have a valid certificate. In fact, I can build and run iPhone applications on my device just fine. However, even in Debug mode, my application will not stop on breakpoints or output to the console when I run it on my device. If it helps, my application will function normally in debug mode (e.g., stopping at breakpoints) when I run in the simulator.
EDIT 2: I've tried resetting my phone, completely removing and reinstalling Xcode, creating a new project, changing all the settings mentioned in the answers on this page (as well as others), cleaning and building my project, Build and Debug... If I click Pause, it says "Error from Debugger: Quit". :( Maybe I'll try to debug on this device using Xcode on another computer and see what happens.
EDIT 3: Well, I tried using another computer using a fresh install of Xcode in a new project, and I still can't get device debugging to work. I have a suspicion that it's my iPhone or cable perhaps? I'd like to think that I'm not so incompetent that I've missed something so embarrassingly obvious, but I've double- and triple-checked all of the suggestions mentioned here.
EDIT 4: FINALLY got device debugging to work. I have a feeling that something low-level on my device was causing issues...nothing I did worked on my system. However, I installed Xcode on another system and device debugging on the same device (with the same cable) worked flawlessly. Directly after that, device debugging began working on my original machine, leading me to believe that some strange hardware flag was screwed up and somehow "reset" on the second machine. In any case, it works now... Thanks for all the help. :)
Also, I'm unsure if it's better to leave this question unanswered or pick the most "helpful" answer...

Yes -- just use a device build. You have to get certificates and provision it.
This is a good description:
http://boga.wordpress.com/2008/07/16/debugging-ipod-provision-profilescertificates/

Make sure to start debugging by pressing "Cmd-Y"... and not "Cmd-R" :-)

You may try last trick in case nothing can help.
If your application launched successful on your device from XCode but did not stop at breakpoints - try press "pause" button after start in debug mode. If you will see application paused properly (do not react to user's action) add new breakpoint then press "run" to continue application execution. In some cases it may helps to stop at new breakpoint.

Yes, just set your project to build for the Device.

If you need to setup debugging for jailbroken iPhone (up to 2.2.1) (not pay 99 to Apple yet) follow next steps:
Install MobileInstallationPatch for your iPhone via Cydia (use Search Tab)
Switch off PROVISIONING_PROFILE at XCode: Go to /Developer/Platforms/iPhoneOS.platform/Info.plist, add next keys:
<key>PROVISIONING_PROFILE_ALLOWED</key>
<string>NO</string>
<key>PROVISIONING_PROFILE_REQUIRED</key>
<string>NO</string>
You may also add these keys to any
project particularly at XCode, Project
Build Settings, User-Defined
variables.
Add key to your project Info.plist at XCode
SignerIdentity = Apple iPhone OS Application Signing
Don't forget to install and add to your project settings self-signing certificate from Apple
http://developer.apple.com/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html#//apple_ref/doc/uid/TP40005929-CH4-SW2
"Build and Go", you can connect iPhone and start debugging.
Important! You may need to install and launch at least one legal app (any free one) from App Store first (before "Build and Go" step). Otherwise your application will be successfully installed by XCode to your device but may not be launched. Try this troubleshoot first in case of problem with app launching.

Yes. Debugger and performance tools work fine on the device. That's where I do most of my debugging.

Xcode>preferences>debugging uncheck load symbols lazily
fixed the breakpoints not holding in device problem for me.

Related

Finished Running on iPhone

I am trying to test my app on an iPhone 4S. When I build and run from Xcode, the project is successfully compiled but after that Xcode says:
Finished running MyApp.app on MyiPhone
The app perfectly work on the simulator and the provisioning profile works correctly (I tried to load an empty app and it works).
If I try to manually load the app I get this message:
The Info.plist for application at
/Users/*/Documents/App/AppName/DerivedData/AppName/Build/Products/Release-iphoneos/AppName.app
specifies a CFBundleExecutable of AppName, which does not exist.
Where is the problem?
The connection that XCode creates with the device is rather fragile, and can easily be corrupted if anything goes amiss in the debugging test, most commonly if the developer stops a build, while it is being moved to the device.
I have a routine of things I go through, when this occurs. If one doesn't work, I go further down the list.
Check your signing certificates
: This error can occur if you mess around with the certificates too much. Make sure your current scheme uses the Debug signing when making a debug build, and check in your application settings if the current debug signing certificate is a debug certificate. (Not AppStore, AdHoc or Enterprise).
Reestablish connection with the device
: Look under devices in your Organizer. Check if the device you are using is present and marked with a green bullet. If orange or grey, reconnect the device with the USB. For precaution, wait a couple of seconds from taking the cable out before you insert it. It should make no difference if you eject the cable from your mac, or the part connecting your iDevice.
Reactivate development on the iDevice
: Being unaware why this happends, some devices revert to a non-development stage from time to time. Clicking the "Enable development" under Organizer > Devices seems to clear this off.
Flushing XCode device connections
: Something that often is needed, you can simply shut down XCode (and to be safe, close the iPhone simulator as well) and start it up anew. Deleting the debug application present on the iDevice is also a good idea.
Restart your iDevice
: Tedious as it might seem, restarting your iDevice is sometimes needed, since the pipe held on the device might be corrupted.
Restarting your developer machine
: If everything else fails, a restart of your mac is often required. I have never experienced this error without having it fixed by now.
I hope this checklist will help you through.
Try cleaning the project.
SHIFT+CMD+K
Found the same bug in XCode 9 while running the project on iPhone 5s. Clean the project and it will work.
Clean.
Build.
Run.
It's work for me.
I had similar issue. When I run program on iPad2 it compiles and installs app on device, wait for some time, and display an alert. Then I followed steps below
1) Removed that application from device.
2) Disconnected iPad and tried again.
Then it successfully run in device. If this not resolved your issue, do
Rename your application to some thing else and try to run. It will run. Lastly you can make an "ipa" file with Ad Hod distribution and can test on device.
Looks like you are trying to run a release product on the device. You are probably signing it with production key. Run it as debug.
Maybe I'm totally off with this guess but the last time I got the same message was when I had some required hardware capabilities set in the Info.plist which the target device didn't comply with. (E.g. requiring a camera and trying to run the app on an iPad1.)
I've just finished chasing down a similar problem.
An app that worked on the device (iPad 1) and on the simulator stopped loading on the iPad but continued to function as before on the simulator. When "run" with the device as target, it compiles and then goes immediately to "Finished Running...".
I did all the usual bits - removed the app from the device, ran Product/Clean, removed derived data, shut computer and device down cold, but with no luck. Other development apps loaded and ran fine.
This app uses GameKit. When I removed the gameKit requirement from Info.plist, the app loaded and ran correctly on the device again - including the GameKit functionality (no kidding). When I added gameKit back in, it failed again. When I added the gameKit requirement to other apps, they failed to load to the device as well. It appears that something has happened to the gameKit setting on the device, although gameKit is there and functions as always. I'm suspicious that this one has to do with the state of the sandbox.
I've got to make a few changes to get the app running on the iPhone and I'll test that as well. I'll repost if I sort it out.
Si it seems that XCode build, ran and finished but the app failed to be deployed and was not even copied to the device.
In fact, there should be something in the XCode project that is broken. This is easily corrupted. The best move is to build a new project from scratch. Don't forget to add armv6 support if needed.
It works well for me!
Check the device log
It may occur, that you are using a provisioning profile, which does not allow one of the entitlements, listed for your target.
For example
entitlement 'entitlement-name' has value not permitted by provisioning profile 'Your Profile Name'
For me, the usual culprit is that I have an app store build already on my device.
Different/same version numbers might make things worse. I haven't looked into it too deeply since deleting the version that is already on my device usually fixes the issue.

iPhone Simulator Can't Be Lauched?

When I press Run on Xcode with other tasks already running, the following message appears:
Simulator in Use.
The Simulator can't be launched because it is already in use.
I checked with some friends and when they press run, Xcode automatically stop the tasks running and run the app you want. How can I configure this here?
Thanks in advance,
Quit the simulator and try again. if not working quit the Xcode and try again.
If you have two projects open in Xcode and one is running on the simulator, you can't run the other. Go through each project window and see if any are running, and if they are, press the "Stop" button on the top left:
In most cases Josh answer solves this problem. But just now happened to me to have only one project in Xcode and trying to clean and built it did nothing.
For me (this time) the solution was to:
Right click the simulator from dock and click Quit.
I did the same for Xcode (right click on Xcode in Dock and clicked Quit).
After that just re-open Xcode and voila!
It works!!!
If the issue is you have multiple projects open and running into Simulator conflicts, someone created a little Automator script that closes the current simulator and starts the next one. Kind of a work around but might work for you.
Check out the detailed answer here.
The over attached debugger syndrome
This happens to me when I switch simulator type (ios version or device type) without pressing the stop button (application was still running on it). To fix this, switch back to the old one (if you remember witch it was :P), run then stop the application, switch to the desired simulator configuration, run, tadaaaa: the error is gone.
This can also happen if you have two projects and one is running, and you try to run the other one. The solution is to stop the other one before starting the desired one.
This ca also happen if you had some kind of crazy bug and the simulator is unresponsive, in this case the debugger remains attached, crying over it's beloved simulator. You have to close the xcode simulator and sometimes restart for this one.
I have the latest xcode version at this time and got fustrated for a while. Now I'm free from restarting the simulator, xcode, coputer, router, going to sleep and waking up the next morning... :D
Hope this helps you guys apple has a lot of weird unclassified exceptions in xcode. They could least say that the debugger is still atached to something in the memory, we are programers not ordinary users, the more errors you give us the better we understand how to avoid them.
My personal favorite si when xcode puts absolute paths to your newly added famework that go nuts triing to find out why it doesn't work on an other computer (The project in wonderland syndrome).
(and rant rant rant irony rant.. you get the idea)
Quit the xcode and simulator ,and try to restart your mac
Quit the simulator and try again.
Your mac might be opening iPhone Simulator automatically, In order to stop this you can run Terminal, OSX's version of command prompt, by navigating to ~/Applications/Terminal.app
from there you can run these commands.
top -u This command shows the mac's processes, and some information about them, from there you can see whether iPhone Simulator might be open.
sudo killall iPhone\ Simulator Deconstructing this command for you, sudo puts you into superuser mode, by having you enter your login password, killall : This command kills all processes by the name specified. iPhone\ Simulator: This being the name of the app, and in order to have a space requires the \ (space) before the second word. By running this command you will kill all processes called iPhone Simulator.
If this doesn't help, then try rebooting.
If rebooting doesn't help try re-installing XCode.
If re-installing XCode doesn't help, then try re-installing your Operating System entirely.
Good Luck!
There are three solutions for this issue:
Right click the simulator on the Doc, quit and then re-run the application from the Xcode.
If this did not work, then -
Save your code, Right click the Xcode, restart the Xcode with your project and then run again. Remember to select simulator instead of device in the target.
If this also did not work, then,
Force Close - Simulator/Xcode - Restart your mac and then run Xcode again.
Most likely - the first step would be enough!!!
To get the simulator to stop whatever is running you need to check off the box "Do not show this message again".
Example:
And then click the box.
And then you can run the simulator even if a program had already been running.
I've been having this issue as well, but for me the problem doesn't have to do with XCode or Simulator.
The problem was in my code. A process was making the CPU run at 100%, and fixing the bug in my code fixed the simulator problem.
Force Quit both, iOS Simulator and Xcode, then reopen Xcode and run project.
Two Possibilities.
1)just quit the simulator,and run the application you want to run
2)just stop the application that using the simulator and run the application you want to run
Try these steps in increasing order of persistence of the problem:
Quit the Simulator.
Clean the project, Reset Simulator, Delete 'Derived Data'.
If nothing works, Force Quit Xcode and Simulator from the Mac Menu.
Force Quitting Xcode seems to always work for me.
It was one sticky Xcode bug indeed. Now it's solved, happy coding!

error from debugger: the program being debugged is not being run

i have run my application in device but application is crashed and print following message
error from debugger: the program being debugged is not being run.
so please tell me what to do?
my application gonna launch properly but not not debugging first time (gonna crash) than from second time i start application work proper without crashing
my application install in device. we can`t debug in device...
The first thing i do when i get that is a Clean All usually solves that. If you don't see the Clean All button right click your Xcode toolbar, customize, and drag the Clean All button to your toolbar from there.
-Check that the provisioning profile installed on your device haven't expired (would see a red dot in the organizer - Window->Organizer).
-Try restarting XCode.
Do you mean device? If so then it could mean the device is not launching the application correctly. Make sure your developer profile and everything in the build settings is correctly set. This may sound obvious but also make sure the device is unlocked and open.

No more gdb in XCode console when build for iPhone simulator

Usually I use gdb backtrace to debug my application, but recently I can no longer do it when testing on iPhone simulator. The blue gdb word stops being displayed on console, and nothing happens when I type "bt" or "backtrace". I can still build and debug properly on the device though.
My XCode version is 3.2.3. Is there any way to manually activate the gdb (more importantly the backtrace)?
As Jack points out, the Pause button will manually activate gdb & the back trace, which is what you asked. You may have a bad install -- it happens, sometimes, try deleting your /Developer folder & re-installing. XCode 3.2.3 and the debugger work just fine, I use it several times a day.
In particular, CMD-Y is "build & run with debugger", whereas CMD-R is just "build & run" (no debugger, by default), so make sure you're using CMD-Y.
Aside: An issue I keep running into is, after the app quits, the red-stop-sign icon doesn't recognize that the app has finished, so I have to "stop" it again. I believe this is due to iOS-4's keeping apps running in the background.
If the program is hanging, which is what this sounds like. You can press the 'Pause' button on the Debugger Console or in the Debugger window to interrupt the app and see where it is currently executing.
Also, check and make sure your home folder .gdbinit file is in good order. Move it aside if it exists and see if the problem goes away.
Don't know if this is the exact same situation, but it may help. My iPhone was at firmware 4.0.2, but my Xcode SDK was for firmware 4.0.1. Normally Xcode would complain that I would need to upgrade to a newer Xcode that supported 4.0.2, this time it didn't.
Was banging my head why breakpoints could be set but the debugger did not stop at my breakpoint (the breakpoints were orange - signalling that symbols were not loaded). I decided to reboot my iPhone and now Xcode showed the warning (when it didn't before). Upgrading to Xcode for 4.0.2 fixed my problem of course. So perhaps your Xcode is not updated for newer firmware?
Had similar issue, but can't remember the exact circumstances. Turned out the Base SDK (in the project info build tab) was set to the device and not the simulator. Bit of a shot in the dark, but probably worthwhile verifying.

Error Installing iPhone App on Device

I set up all my certificates and keys today and am trying to run my project on my iPhone.
I'm encountering this strange error:
Your mobile device has encountered an unexpected error (0xE800003A) during the install phase: Verifying application
Poking around the Apple Developer forums, I've attempted to set new certificates and provisioning profiles as well as editing Info.plist, but no matter what I do I can't seem to run the app on my device.
The only think I can currently think of is that my project name in Xcode differs slightly from my development provisioning profile (it uses a question mark), but I've named it according to Apple's conventions: com.mycompany.myapp, so I'm unsure if that's the problem.
Any ideas?
Edit: I've hard restarted the phone, rebooted Xcode, cleaed my targets, set up a new wildcard App ID and respective provisioning profile and still nothing. Any other ideas?
It turned out that I had 2 certs in keychain that were simultaneously overwriting each other! I hope this helps people in the future.
You should create a wildcard app ID; com.mycompany.*. That may help.
I've encountered this on many occasions. What i do is clean all targets, shut down xcode, and hard reboot my phone.
This is a different error than the more common problem of getting the cert wrong...
Restore the phone (using the XCode Organizer to reload the latest OS), to be safe do not restore from backup when you sync with iTunes the first time (it'll still keep your number when you sync even if you don't use the backup). I've had to do this a very few times, the last one was when it was in the middle of deployment when I unhooked the phone from the cable (had to answer a call).
Try the reboot (of the phone) first, hooking it up with XCode off. But if that does not solve things, restore is the way.
The console tab in the XCode Organizer sometimes gives helpful hints as to what happens during the install phase. In one case my problem was my app already existing on the phone. I deleted my app and the install succeeded.
Regardless, it looks like a lot of error messages are bundled into this one cryptic message and to really diagnose what is going on, I found the Console tab very useful...
One other thing to try is reinstalling the iPhone SDK. I ran into an error like this when I first got my developer key and this was the only way around.
Just want to say to everyone, when you go to edit Targets-> be sure to set "configuration" in the top left corner to "All Configurations" or the correct config you are building for (Debug or Release). You might think you have things set correctly but it will be for the wrong configuration.
I've seen that error on a correctly provisioned device that has had success installing apps from XCode before, and I've had luck restarting the device and trying again. Maybe that will help.
Try running in Release mode instead of Debug. I have a working project with this problem. No idea what the issue was, but running it in Release mode works, but Debug mode produces the error code.
I have a support ticket open with Apple dev support for the same problem, and (FWIW) I'll post their recommendations if and when they can get my toolchain working.
Try this: (source: http://ephemera.lifewithalacrity.com/iphone_development/)
Even though this is supposedly only for Distribution builds, it helped me to be able to install my Debug version on my iPhone again, after it mysteriously broke yesterday.
"just triple check that all the code signing in your project properties are clear or default"
Note, this is the PROJECT properties as opposed to the TARGET properties. I set my Code Signing Provisioning Profile back to the default and removed the Code Signing Identity string.