How to debug iPhone applications - iphone

how can i debug applications for iPhone in Objective-C, XCode
i mean ok, XCode and debug mode is fine, but when my application crashes on
BAD_ACCES (or smth. smilliar) i just get the trace to assembly
when iam debugging C++ and lets say want to access an invalid pointer, i get a trace right to the line of code where everything crashed... here i just get a trace to many internal functions in assembly, so i dont have a clue what and where went wrong
probably some release / retain problem, but how can i find out?
thank you

Here we go with the full answer:
I've had a look at your app and I think there is a problem with the combination of the UINavigationController and asynchronous http loading in two places. Enabling the zombies did reveal those two errer. The first on I was able to reproduce, the seconds one popped up several times and then not any more.
*** -[DetailViewController respondsToSelector:]: message sent to deallocated instance 0x56d6030
*** -[SearchViewController respondsToSelector:]: message sent to deallocated instance 0x56daa10
I've just throttled my bandwidth to see if those errors are connected to http requests. Look at [Throttling Bandwidth On A Mac][1] to set up a slow connection. I set it to 5KBytes/sec.
The first error occurs if you go very quickyl down to the details and then two levels up again and as a last action to trigger the error: click on search. The stacktrace shows a
#2 0x004545b8 in -[UIWebView webView:decidePolicyForMIMEType:request:frame:decisionListener:]
and there are some threads open, so looking at the dropdown, there is a webThread. Showing that thread reveals something going on with the webview loading the detailPages url. This hints that the webiew actually finished loading in a seperate thread and wasn't able to connect back to the webview itself [DetailViewController respondsToSelector:]. This can be easily proofed: remove the loading of the request for the webview: I wasn't able to reproduce the error.
Solution problem 1
The problem is easily fixed, as the webview is not released in the dealloc. Setting delegates to nil of objects is also recommended, but not needed in this case.
- (void)dealloc {
webView.delegate = nil;
[webView release];
}
The second error
The stackTrace shows a
CLLocationManager onClientEventLocation:
Solution error
Same as error 1, set the delegate to nil and release the locationManager.
When your app crashes you cann open up the debugger in the left hand window you can see the stacktrace. You can double click any line which will jump to correct position in your code(if the called method is of yours).
Goto Project->Edit Active Executable->Arguments Tab
Add the Variable in the lower window by clicking on +
Name:NSZombieEnabled
Value:YES
This tries to resolve memory addresses to class names for bad excess errors.
To find out about memory leaks, open Run->Run with performance tool->Leaks. This will open up instruments which is a brillant tool to find leaks.

Are you using XCode 3? If so, I would highly advise upgrading to XCode 4. The debugger in XCode 4 is brilliant in comparison. It let's you step back through the code and see exactly what caused the crash.

Related

LLdb error in Swift - How to fix it?

I get a lldb error in Swift an don't know why. The code beneath worked fine but since yesterday the code causes an error.
Here's the error:
Do you know why I get this error?
Such errors are hard to fix when you are not providing much information.
Option 1: Build Folder
clean the Build Folder Command+Option+Shift+K.
Option 2: Derived Data
delete the Derived Data folder from
/Users/YourUsername/Library/Developer/Xcode
Option 3: CocoaPods
if you have a workspace with a pods project try this.
In Terminal:
cd /Your/Project/File/location
pod deintegrate
pod update
Option 4: Through the code
You are going to have to go through your code, setting breakpoints and pinpointing what exactly is causing the error.
In your picture you trimmed too much on the RHS. Where it says "Thread 1:" there will have been text to the right of that which explains why the debugger stopped.
Most likely it said EXC_BAD_ACCESS with an address. That stop reason means somebody tried to read or write to an invalid address - one that hasn't been allocated, or been allocated & freed. If the address is 0x0 or somewhere near there, it probably means somebody is passing a NULL pointer where one is not expected. If it is some higher address, that probably means the object you passed in or some ivar of same was bad (i.e. wasn't properly initialized or had been freed.)
Mentos's option 4 is likely in your future. Again, if the crash was an bad access, it's likely something is wrong with the videoInput you are passing to addInput.
Note also, Xcode has a feature that compresses stack traces to show you only your code and frames near it. That's why you only see the frame where you pass videoInput to AVCaptureSession, and the crashing frame. The far left one of the three little widgets in the Filter section of the threads view will turn that off and show you all the frames. You can sometimes glean a little more information about what is going on from the full stack trace.

Exception on app startup in device,works fine in simulator

The application works fine on the simulator but breaks in start up in device as in the figure
I tried some of the solution in SO but It doesnt work out.What may be the reason ?How can i find it? How to resolve it
For clarity
Tried : Changing the view controller the viewcontroller. view did load and all functions are working fine after that when the view tries to appear on the screen the crash appears
UPDATE : Now getting the error logged as
*** -[Not A Type retain]: message sent to deallocated instance 0x208c9610
I had the same issue before. This is not a crash. Please remove all your break points and run it again.
This is a Breakpoint error ..... It normally occurs when you add a breakpoint to an app running in the device. If you add the breakpoints before the app has been built and run it again.... The crash will not occur.
Even I couldn't figure out why this crash should occur in the first place but it does.
OK found out the problem.I am using an external library which does not implement ARC so it has to be flagged.all files except 2 are not flagged as -fno-objc-arc and hence the issue.

application crashes when back button is clicked and No exceptions shown - Beginner

My application crashes when i click on the navigation controller back button , it doesn't show any exception or any.
I don't have any clue, or could give you more detail about the crash, since there's no exception or any details printed on the screen.
I think its due to a memory leak, but then i am not sure. have anyone come across this before
Any clues?
Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb comsole:
(gdb) info malloc-history 0x543216
Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.
First, memory leaks don't cause crashes, over releases can.
Second, look at the console, either there is crash information or there was no crash.
when your App "crashes" OS writes it to a crashreport. Look at ~/Library/Logs/DiagnosticReports/ folder and Look for most recent crash report of your app there. Post that info from crash report here if you dont understand it.

My app crash on exit after upgrading to iOS 4.0 sdk. How to fix this?

Everytime I quit the app in the simulator.
The console display this error message:
*** -[NSThread _nq:]: message sent to deallocated instance 0x6d770e0
Looks the app try to access an deallocated instance.
But I cannot find it anyhow, even using the instrument.
I can't find the line of code that cause the problem.
p.s. I have already tried any ways that I know to debug this problem. but no success yet.
I enabled NSZombie and use instrument to help me to find out the error. But the error report did not point to any of my own code. I have no idea why this happen.
Double click on your executable in the left pane in XCode, go to the arguments tab, add a new one named NSZombiesEnabled and set its value to YES. This will set all deallocated instance to an NSZombie and you'll be able to tell what type is being deallocated.
NOTE: THis must be turned off after or your app will never release memory!
Fixed, this problem is that I access interface objects not in the main thread. you can do so by [self performSelectorOnMainThread....].

NSZombieEnabled doesn't report the type of object causing an EXC_BAD_ACCESS error

I have a crash that is happening deep within UIKit for some reason; an EXC_BAD_ACCESS error is happening something like 8 calls deep into a dismissModalViewController call. I tried enabling NSZombieEnabled for my executable, but the console log prints the same error regardless of whether or not zombies are turned on and i don't know which object is causing the issue. Is there something i'm missing that i need to do to get the console to print the correct information?
Read about using Zombies here.
Run this in gdb. When you get the EXC_BAD_ACCESS look at the stack at that point (use gdb's where command or run the Xcode GUI debugger). If you are still having issues, post the stack in your original question.
Also zombies will only help you if you're dealing with NSObjects. If you're using low level malloc/free routines zombies buy you nothing for those allocations.
One thing I learned last weekend when NSZombieEnabled didn't seem to be working at all - make sure you're not passing in a non-object to some code.
In my case, I was returning an NSString as just "string" instead of #"string". That meant I was overwriting an NSString object with the c-string. When I later tried to write a new value in that object I was getting a BAD_ACCESS. NSZombie's couldn't help b/c it was not an object I was trying to overwrite, but that c-string.
As an aside, treat all warnings as errors in XCode - wish I could make them show up in RED in the IDE GUI - they are easy to miss sometimes.
Sounds like something is over-released in your Modal View Controller. Start by commenting out newish lines until it stops breaking.