Search code examples
iphoneiphone-sdk-3.0crashios-simulatorexc-bad-access

EXC_BAD_ACCESS on device, but fine on Simulator


I have a scroll view app which runs fine on the simulator, however, when installed on the device, it gives me an EXC_BAD_ACCESS when I attempt to scroll one page. I have ran it through "Instruments with Allocations and Leaks", but nothing is leaked and no zombies are messaged... I'm just curious what could cause such a difference in simulator vs device? Any ways to debug this, since my symbolicated crash log (partial below), doesn't seem to be very symbolicated.

Exception Type:  EXC_BAD_ACCESS (SIGBUS)  
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000f  
Crashed Thread:  0

Thread 0 Crashed:  
0   libobjc.A.dylib        0x0000286e objc_msgSend + 18  
1   MyApp                  0x00004fee 0x1000 + 16366  
2   UIKit                  0x000668f4 -[UIViewController view] + 104  
3   MyApp                  0x00009716 0x1000 + 34582  
4   MyApp                  0x0000960c 0x1000 + 34316  
5   UIKit                  0x0001426c -[UIScrollView setContentOffset:] + 344  

Thanks


Solution

  • Your code in the simulator could have the bug, but isn't triggering EXC_BAD_ACCESS by just the luck that a pointer that you dereference is not in unmapped memory. A pointer could be bad, and accessed, but not detected -- it's still a bug.

    You have already checked to see that no Zombies are messaged, which would have been my first suggestion.

    The next thing to do is Enable Guard Malloc -- and then read this

    http://developer.apple.com/iphone/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html

    You can only do this in the simulator -- your goal is to use the extra-sensitive heap to make the bug throw EXC_BAD_ACCESS in the simulator.

    In the article:

    1. Look at how to set the variables in GDB
    2. Read the "Detecting Heap Corruption" section