Examining iOS Crash Report with EXC_BAD_ACCESS (SIGSEGV) and ARM Thread State (64-bit)

I recently posted an update to my app on the App Store. Testing did not result in crashes, but I noticed that when it was released to the App Store, one script crashed my application in my 5 seconds. This script does not crash at design time. I got a message from a user stating that it also crashed in one scenario for 5 of them, which is the same as what I was doing.

I am in an intermediate stage of iOS development and this is my first experience of diagnosing a crash report.

Update: scroll down to the bottom of the questions for more updates on issues

Inside Xcode, I have the following crash report for my application on my 5s:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000060
Triggered by Thread:  0

Thread 0 Crashed:
0   CoreData                        0x00000001822f8af4 _propertyAtIndexForEntityDescription + 24
1   CoreData                        0x00000001822f0330 snapshot_get_value_as_object + 304
2   Foundation                      0x0000000183080a78 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 288
3   Foundation                      0x00000001831613cc -[NSSortDescriptor compareObject:toObject:] + 140
4   CoreData                        0x0000000182305d9c +[NSFetchedResultsController(PrivateMethods) _insertIndexForObject:inArray:lowIdx:highIdx:sortDescriptors:] + 284
5   CoreData                        0x00000001823dd808 -[NSFetchedResultsController(PrivateMethods) _createNewSectionForObject:] + 492
6   CoreData                        0x0000000182305b58 -[NSFetchedResultsController(PrivateMethods) _postprocessInsertedObjects:] + 528
7   CoreData                        0x00000001823025f8 -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 2036
8   CoreFoundation                  0x000000018259b760 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 16
9   CoreFoundation                  0x00000001824e82b0 _CFXNotificationPost + 2060
10  Foundation                      0x000000018307a744 -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
11  CoreData                        0x0000000182301dd8 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 84
12  CoreData                        0x0000000182301d58 -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 360
13  CoreData                        0x0000000182300348 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 2224
14  CoreData                        0x00000001822ff264 -[NSManagedObjectContext save:] + 152
15  Lopey                       0x000000010004da3c -[LopeyAddEntryViewController save:] (LopeyAddEntryViewController.m:828)
16  UIKit                           0x00000001855e50ac -[UIApplication sendAction:to:from:forEvent:] + 96
17  UIKit                           0x00000001855e50ac -[UIApplication sendAction:to:from:forEvent:] + 96
18  UIKit                           0x00000001855e5040 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 20
19  UIKit                           0x00000001855ce51c -[UIControl _sendActionsForEvents:withEvent:] + 372
20  UIKit                           0x00000001855e4a40 -[UIControl touchesEnded:withEvent:] + 580
21  UIKit                           0x00000001855e46d4 -[UIWindow _sendTouchesForEvent:] + 688
22  UIKit                           0x00000001855df36c -[UIWindow sendEvent:] + 1168
23  UIKit                           0x00000001855b0b4c -[UIApplication sendEvent:] + 252
24  UIKit                           0x00000001855aec3c _UIApplicationHandleEventQueue + 8496
25  CoreFoundation                  0x00000001825a77f0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
26  CoreFoundation                  0x00000001825a6b4c __CFRunLoopDoSources0 + 252
27  CoreFoundation                  0x00000001825a4de4 __CFRunLoopRun + 628
28  CoreFoundation                  0x00000001824e5dcc CFRunLoopRunSpecific + 448
29  GraphicsServices                0x00000001881cdc08 GSEventRunModal + 164
30  UIKit                           0x0000000185616fc0 UIApplicationMain + 1152
31  Lopey                       0x000000010005a40c main (main.m:16)
32  libdyld.dylib                   0x000000018f0e3a9c start + 0

      

I also have a little below:

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x0000000000000001   x5: 0x0000000000000074   x6: 0x0000000000000074   x7: 0x0000000000000000
    x8: 0x0000000000000060   x9: 0x0000000000000020  x10: 0x0000000100124540  x11: 0x000000100000001f
   x12: 0x00000001001245a0  x13: 0x0000000178242d60  x14: 0x0000000000000034  x15: 0x0000000004060401
   x16: 0x000000018a1c96e6  x17: 0x000000018234e2d4  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x000000017043b580  x21: 0x0000000000000011  x22: 0x000000017043c1e0  x23: 0x0000000000000006
   x24: 0x000000018265d35b  x25: 0x000000018f715000  x26: 0x000000018f715000  x27: 0x0000000000000002
   x28: 0x00000001780dbd60  fp: 0x000000016fdfc850   lr: 0x00000001822f0334
    sp: 0x000000016fdfc840   pc: 0x00000001822f8af4 cpsr: 0x60000000

      

As you can see from the logs, I am using Core Data

with NSFetchedResultsController

. I have UITableViewController

one that is populated as a result of the user clicking a button in UINavigationBar

, adding some records to multiple, UITextField

and clicking Save. It was in this that he crashed. However, I must mention that it doesn't crash every time. In fact, before the crash, I added 45 records in succession, and after that I added 100, without crashing. This only happened once.

The point in the application where it crashes is when I click the Save button (which rejects the value ViewController

and reverts to UITableView

). With that in mind, this is either the actual "save" NSManagedObjectContext

or it is the loading of the UITableView. My money comes first, but I'm not sure.

Here's my code for NSManagedObjectContext

in App Delegate

:

- (NSManagedObjectContext *)managedObjectContext
{
    if (_managedObjectContext != nil) {
        return _managedObjectContext;
    }

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];

    if (coordinator != nil) {
        NSManagedObjectContext* moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
        moc.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy;

        [moc setPersistentStoreCoordinator: coordinator];

        _managedObjectContext = moc;
    }

    return _managedObjectContext;
}

      

Here's my method Save

in App Delegate

:

- (void)saveContext
{
    NSError *error = nil;
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    if (managedObjectContext != nil) {
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
            // Replace this implementation with code to handle the error appropriately.
            // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            //NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
    }
}

      

As mentioned, I'm pretty new to development and this is the first time I've seen a crash log that needs to be investigated. Any direction on this would be really appreciated. Is it also something to do with the 64 bit processor in the 5s? (Perhaps this explains why I can't reproduce it elsewhere?).

Update 1

My app is iOS 7 only. My 5s is iOS 7 only and I tested my app on iOS 8 but on 4s and didn't experience similar crashes. Also, I tested the iPad Mini as well, so this is an iPhone 5 only issue.

Update 2

Shows the code that saves the new objects below. It may look complicated, but essentially a name, event, etc. Based on auto-completion, which is based on what objects are already in Core Data, etc.

- (IBAction)save:(id)sender
{
    NSManagedObjectContext *context = [self managedObjectContext];

    // Insert a new transaction
    Transaction *transaction = [NSEntityDescription insertNewObjectForEntityForName:@"Transaction" inManagedObjectContext:context];
    Item *itemType = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:context];

    itemType.amount = self.itemTextField.text;
    transaction.item = itemType;
    transaction.wasReceived = @(self.isReceivedSegment.selectedSegmentIndex == 0);

    Person *enteredPerson = (Person *)[Person personWithName:self.nameTextField.text inManagedObjectContext:context];
    transaction.whoBy = enteredPerson;

    Occasion *enteredOccasion = (Occasion *)[Occasion occasionWithTitle:self.occasionTextField.text inManagedObjectContext:context];
    transaction.occasion = enteredOccasion;

    Subevent *enteredSubevent = (Subevent *)[Subevent subeventWithTitle:self.subeventTextField.text inManagedObjectContext:context];
    transaction.subevent = enteredSubevent;

    NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [cal components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit
                                          fromDate:self.datePicker.date];
    [components setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
    NSDate *selectedDate = [cal dateFromComponents:components];

    Date *date = (Date *)[Date occasionWithDate:selectedDate inManagedObjectContext:context];
    transaction.dates = date;

    NSError *error = nil;
    if (![context save:&error])
    {
        // Error
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}

      

Inside UITableViewController, my fetchedResultsController is below:

- (NSFetchedResultsController *)fetchedResultsController
{
    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    if (_fetchedResultsController != nil)
    {
        return _fetchedResultsController;
    }
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Transaction" inManagedObjectContext:managedObjectContext];
    fetchRequest.entity = entity;

    // I am implementing a search here so we can either search by name or event with the prediate filtering out the information.
    if ([self.timelineSearchBar.text length] > 0) {
        NSPredicate *predName = [NSPredicate predicateWithFormat:@"whoBy.name CONTAINS[c] %@", self.timelineSearchBar.text];
        NSPredicate *predOccasion = [NSPredicate predicateWithFormat:@"occasion.title CONTAINS[c] %@", self.timelineSearchBar.text];

        // Adding in another predicate for searching by subevent
        NSPredicate *predSubOccasion = [NSPredicate predicateWithFormat:@"subevent.title CONTAINS[c] %@", self.timelineSearchBar.text];

        // creating the orCompoundPredicate for the two conditions
        NSPredicate *compPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[predName, predOccasion, predSubOccasion]];

        [fetchRequest setPredicate:compPredicate];
    }
    // Sorting by date and by name.
    NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"dates.dateOfEvent" ascending:NO];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"whoBy.name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];

    fetchRequest.sortDescriptors = @[sort, sortDescriptor];

    fetchRequest.fetchBatchSize = 20;
    NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"sectionDateFormatter" cacheName:nil];
    self.fetchedResultsController = theFetchedResultsController;
    _fetchedResultsController.delegate = self;
    return _fetchedResultsController;
}

      

Hope this is helpful!

Update 3

I wanted to try to reproduce the problem. The steps to play for the first time included updating from a previous version of the app. I had a version of the app store on my device before the update, and when the update was released, I updated to that, created a new entry and that it crashed. I was running an old version of my app and upgrading to this new version in Xcode, and when the app was updated and ready to go, I added a new entry and with an exception breakpoint, it crashed to transaction.dates = date

; the method of preservation, above, in updating 2. breakpoint reported: Thread 1: EXC_BAD_ACCESS (code=1,address=0x60)

.

I followed the steps again, without a breakpoint, and stopped at the same line of code with the same error.

Update 4

This crash only occurs if I update the app to the latest version and immediately add a new entry. If, however, I start the app again before adding a new entry, the device does not crash.

Update 5

With some additional testing, I found that this crash is the result of updating this new version on the iPhone 5 and iPad Air. The app doesn't crash on any other device. With this latest version of the app, I brought iCloud sync. In App Delegate

I have the code below that will be run when the user wants to select iCloud in the update tutorial. It is with this scenario that the application crashes.

- (void)initialMigrationOfLocalDataToiCloud
{    
    NSURL *storeURL = [self.persistentStoreCoordinator.persistentStores.lastObject URL];

    NSPersistentStore *currentStore = self.persistentStoreCoordinator.persistentStores.lastObject;

    NSURL *cloudURL = [self grabCloudPath:@"CloudLogs"];
    NSString *cloudStoreTitle = @"LopeyCloud";

    NSDictionary *options = @{NSPersistentStoreUbiquitousContentURLKey: cloudURL,
                              NSPersistentStoreUbiquitousContentNameKey: cloudStoreTitle,                               NSMigratePersistentStoresAutomaticallyOption : @YES,
                              NSInferMappingModelAutomaticallyOption : @YES};

    [self.persistentStoreCoordinator migratePersistentStore:currentStore toURL:storeURL options:options withType:NSSQLiteStoreType error:nil];

}

      

I have an easy migration there because the user can update from a previous version etc.

In case of a breakpoint exception (and even without it), the application will crash with the code transaction.dates = date;

in the method Save

according to Update 2 . I am not allowed to jump out of code or do anything about it. Walking through the debugger, I can't see what the value is transaction.dates

, but it's date

not zero. Even if I don't set a breakpoint, the application will break on the same line of code here.

Hope this makes sense.

+3


source to share





All Articles