Why does GDB debugger constantly freeze Xcode 4? - iphone

This is a really weird bug...
I'm working on an iPhone project using the camera feed and running it through an OpenGL shader to apply effects to it. However, every time I simply create a new GLfloat in the code, the debugger freezes when launched... I can't copy and paste the text because the whole of XCode freezes up, but I've cobbled it together from one of the log files:
GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:56:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-apple-darwin".2#b2a16f854957b341^2#43"Xcode.IDEFoundation.ConsoleAdaptor.Debugger17"tty /dev/ttys000
(gdb)
The phone has not frozen, because I can hit the home button and carry on doing other stuff on it. However, Xcode 4 has completely frozen with a beachball running at 99% CPU, and I have to Force Quit and start it again.
However... The really strange thing is I have an iPhone 3GS, and when I borrow someone's iPhone 4 it compiles and runs fine. When I switch back to the iPhone 3GS, it's fine for the first time only... After that, it freezes constantly again.
Is this possibly something I am doing, or is it yet another XCode 4 bug? I wanted to try switching the debugger to LLDB, but that doesn't appear in my dropdown list in the Scheme window... Even though the Xcode User Guide states that both GDB and LLDB are available:
http://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/Debugging/Debugging.html
Thanks!

I am working on a video processing app as well, and this is exactly the symptoms i am having.
it works in waves.
I don't know what the reason for this is, but i am slowly gathering facts to solve it:
turning off GDB in Scheme settings removes the issue
with GDB ON, "wait for app to launch" seems to solve the issue (need more testing)
after getting into "stable freeze" mode, meaning, beachball on run every single time, Committing to repository removes the issue (??)
restoring device as a new device to latest iOS through iTunes solves the issue
all of the above except turning off GDB only solves the issue temporary - it comes back after few more runs...

Try to have terminal open, AND IN THE FOREGROUND (ON TOP OF XCODE) when the program builds and begins running.
Also, if possible, try downloading xcode 4.1. This seemed to fix this annoying problem for good, AND I can actually use the debugger again !

I had this problem once before and it started happening again all day today. I've tried everything from cleaning the project to restart both my iPad and MacBook Pro and even swapping a different cable.
What worked the two times this has happened:
I cleaned the project, changed the build target, and ran it on the iPhone simulator, iPad simulator. Then returned to the original (main) build target (the actual app) and ran that on the iPhone and iPad simulators. All of those ran correctly, so I finally ran the original app on the iPad device and it worked and has kept working.
Seems like a combination of cleaning the project, changing build targets, and running on the simulator is flushing something out that previously caused XCode and my iPad device to hang and freeze.
Good luck

In my case it was the wrong Code Signing Identity

Minimizing "NSLog" statements within loops helps for applications using OpenGL ES, OpenCV, etc.

Related

"Watchdog has expired" when I debug app with iPhone in Xcode

From yesterday, My iphone couldnot debug any apps.
In xcode, when I choose my iPhone as the debug target, and xcode build the app, link, and run into my phone, several sencond later, the xcode finish running in my iPhone. And the console below show "Watchdog has expired. Remote device was disconnected? Debugging session terminated."
It is iPhone4s, iOS version is 5.0.1, and had jailbreaked, and update Cydia a few days ago.
It could not work on my other MBP yet.
How can I recover it?
This is because of the bug in Cydia update and Jailbreaking.
Hope this helps.
Refer to this post:
App crashes with "Watchdog has expired." message. No stack trace or crash dump
Here is tc.'s answer from that post
"Watchdog has expired." could mean anything. The way the message is
worded suggests that the "local" GDB (running on your Mac) GDB timed
out waiting for data from the "remote" GDB (running on the phone).
Alternatively, "Watchdog has expired" might be from the phone's
console output shortly before it reboots.
What does it display if you disconnect the device while your app is
running? What if you power it off? What if you issue a hard reset
(Sleep+Home for 10 seconds)?
If it's causing the device to reboot, there's something seriously
wrong happening. Your app shouldn't be able to take the phone down,
but sometimes something slips through (IIRC, UIImagePickerController
on some version of 2.x had a problem where either your app would get
killed or the phone would reboot, depending on which kicked in first).
"Large set of bitmaps" sounds like it might be causing CoreAnimation
(or IOSurface or whatever) to run out of video memory.
I would hesitate to do drawing in a background thread unless you're
very careful about thread-safety (to a first approximation,
CoreAnimation is and UIKit isn't except a few functions that were made
"thread-safe" in 4.0).
Hope this helps you.

gdb on iphone device not stopping at breakpoints

I am debugging and iPhone app without a symbol table. The device is jailbroken and I am attaching gdb locally on the device by passing the pid (starting the app in gdb doesn't seem to work on iOS 5). None of the breakpoints I set are getting triggered. I set the breakpoints at offsets I have from a class-dump, but I presume they are not getting hit because of ASLR in iOS 5.
I tried removing the MH_PIE flag using the script from here http://src.chromium.org/viewvc/chrome/trunk/src/build/mac/change_mach_o_flags.py?view=markup and otool shows that was done correctly. However, after the change the application no longer launches.
Am I setting the breakpoints wrong or is this because of ASLR? If it's the randomization then how do I effectively disable it on the device?
If all you're looking to do is debug the app with GDB, then disabling ASLR via the MH_PIE flag is just fine. Since that program patches the binary, you will need to resign the app. Using a program called ldid (from the package called "Link Identity Editor" in Cydia), you can pseudo-codesign the app.
root# cd /var/mobile/Applications/*/Example.app/
root# mach_flags --no-pie Example
root# ldid -s Example
root# gdb
(gdb) attach -waitfor Example
Then just tap the app's icon. The app will appear to hang. From this point, go back to GDB and it should be loaded. Now, just set your breakpoints with b *0x<address> and you can ignore ASLR altogether as it is disabled.
I've just gotten stuck with this as well. There's no easy fix that I can find, the best workaround I've found so far is to use include assert.h and use it throughout.
Update:
You're right. I was thinking in the case of having one's own source. However, gdb on iOS jail broken devices has this known issue of not hitting breakpoints. I have discussed the matter with those who originally brought gdb to Cydia, and they have recommended I attempt to work out the issue myself. Without any free time for that, I have given up for now.
This is a warning to anyone trying to debug via gdb on jail broken iOS, to either look into the issue yourself or give up. It should not be expected to work, and using asserts is the next best thing, if you are working on your own source and not attempting to reverse engineer someone else's app.
I was not trying to answer the question at hand and so I do indeed deserve the downvote. But the information should get out there regardless.

Xcode 4.2 not debugging properly

I've imported an iPhone app that I have developed for iOS and am now maintaining it. I've came across a couple of bugs when trying to add to the iPhone's calendar, which I'm happy to try and sort out myself with a bit of debugging.
One problem is that when I go to run the application on the iPhone simulator, it seems to run an older version of the app than the one I am running. I've removed and added another button since then and the old button is still showing when I run it in the simulator. However, when I compile and run this on a device, it loads the correct version and displays the correct version number in the 'about' view.
But... my main problem is that it doesn't seem to debug on the device properly. The app actually works fine except for the calendar problems, but if I put a few breakpoints in so I can see exactly where this is going wrong, it just doesn't seem to step through! The app pauses, and Xcode says the app has paused! I can press step over and continue execution etc and it appears to work, but I can't see it stepping over the code, nor can I hover over variables to see their values.
I've tried reinstalling Xcode multiple times (I did have a problem installing an older version, so I had to wait until the next version was available before Xcode would install).
The stress is: Today is my last day at work, and I'd really like to get this app ready for iOS 5 before I leave.
Has anyone seen these symptoms before? Is there a debug setting that I've missed? Or is it a corrupted installation?
I wish I could help people a bit with more information, but I don't even know where to start looking here. Any code I can post? any settings? (not too familiar with this, I'm a .NET guy usually).
Thanks!
Sorry you're going through a tough moment there Connell; as you said you're not too familiar with all this, I'm laying down a few steps which might help you out. Some are pretty basic, yes, but I've resolved to these steps myself several times when I've encountered similar scenarios;
If you're testing on the simulator, do a 'Reset Content and Settings' from the 'iOS Simulator' main menu. This will remove all old data and settings and give you a clean start.
Do a 'Clean All Targets' from the Build menu. Then go to your physical project folder and delete the Build folder from it altogether before starting to build again.
Restart both XCode and the Simulator (and your Mac too if possible)
Make sure the mode is set to Debug and not Release or Distribution
Even on the device, remove the old app before putting the new one in, and restart it for good measure.
Delete all Provisioning Profiles from the device and install just the one you need.
On the code;
I've noted that the app appears to 'pause' like this a couple of times when I had accidentally created an infinite loop in the code. Double check to see whether there's something which may cause this.
Unless you haven't already done so, throw an NSLog or two in there to see if its really not being executed beyond the breakpoint.
I've had the exact same problem with a project that I started on xcode 3 and then switched to xcode 4. What fixed it for me was changing the compiler in the project settings.
The default compiler up to xcode 3 was gcc, while the default compiler on xcode 4 is LLVM gcc.
Now, I don't know exactly what's the issue that gdb could have with LLVM gcc, but switching the compiler back to gcc in my project settings and doing a clean build fixed my debugging issues.
Might be worth a try.
Have you checked which debugger is being used GDB or LLDB? Select Edit Scheme from the Product menu, and see what the Debugger setting is under the Debug scheme. You could try switching between GDB, LLDB, and None and running in between.

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.

iPhone Device Debugging

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.