iOS Application crashes in release version on device

1

I am facing a strange issue, and have already spent quite a lot of time on this.

A crash occurs in my application, specifically in release build, on the device.

The crashlog is:

Incident Identifier: 1879D689-B225-4586-8E8E-D4D9DB392ABB
CrashReporter Key:   c432ffa8a13433b330d0fc03863778260c00be45
Hardware Model:      iPhone5,3
Process:             CSR Proximity [5696]
Path:                /var/mobile/Applications/4C6CDC7D-E594-4976-923B-0A62B68C0053/CSR Proximity.app/CSR Proximity
Identifier:          com.csr.proximity.app.beacon
Version:             37_release (1.2.0_i)
Code Type:           ARM (Native)
Parent Process:      launchd [1]

Date/Time:           2015-01-09 19:46:08.903 +0530
OS Version:          iOS 7.1.2 (11D257)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: EXC_ARM_DA_ALIGN at 0x03a3d4fe
Triggered by Thread:  13

Thread 0:
0   libsystem_kernel.dylib          0x3930ca50 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3930c848 mach_msg + 36
2   CoreFoundation                  0x2e59a5e4 __CFRunLoopServiceMachPort + 152
3   CoreFoundation                  0x2e598d4a __CFRunLoopRun + 858
4   CoreFoundation                  0x2e503724 CFRunLoopRunSpecific + 520
5   CoreFoundation                  0x2e503506 CFRunLoopRunInMode + 102
6   GraphicsServices                0x334726ce GSEventRunModal + 134
7   UIKit                           0x30e6486c UIApplicationMain + 1132
8   CSR Proximity                   0x0000a042 main (main.m:17)
9   libdyld.dylib                   0x39268ab4 start + 0

Thread 1:
0   libsystem_kernel.dylib          0x3930c804 kevent64 + 24
1   libdispatch.dylib               0x3925b050 _dispatch_mgr_invoke + 228
2   libdispatch.dylib               0x392552de _dispatch_mgr_thread + 34

Thread 2:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 3:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 4:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 5:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 6:
0   CoreData                        0x2e359cc2 +[_PFRoutines newMutableSetFromCollection:byRemovingItems:] + 846
1   CoreData                        0x2e3591a4 -[NSSQLCore recordToManyUpdatesForObject:withOperation:] + 1408
2   CoreData                        0x2e3589f0 -[NSSQLCore recordUpdateForObject:] + 92
3   CoreData                        0x2e357234 -[NSSQLCore recordChangesInContext:] + 576
4   CoreData                        0x2e354640 -[NSSQLCore saveChanges:] + 704
5   CoreData                        0x2e322c9a -[NSSQLCore executeRequest:withContext:error:] + 462
6   CoreData                        0x2e322588 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 2972
7   CoreData                        0x2e343f44 -[NSManagedObjectContext save:] + 820
8   CSR Proximity                   0x000a239e -[CPSController sendProximityUpdateNotification:] (CPSController.m:1542)
9   CSR Proximity                   0x0009d988 -[CPSController placesWithCompletionBle::] (CPSController.m:1017)
10  CSR Proximity                   0x0009ecd0 -[CPSController updateDataStoreProximitiesForBeacons::] (CPSController.m:1069)
11  CSR Proximity                   0x0009f3ec -[CPSController handleCurrentBeacons:collectEntities:] (CPSController.m:1124)
12  CSR Proximity                   0x0009f1e0 -[CPSController handleCurrentBeacons:deleted:] (CPSController.m:1104)
13  CSR Proximity                   0x001349e4 -[BleThreadPayLoad process] (BleThreadPayLoad.m:996)
14  CSR Proximity                   0x00133904 -[BleThreadPayLoad threadRunLoop] (BleThreadPayLoad.m:509)
15  CSR Proximity                   0x001339aa -[BleThreadPayLoad main] (BleThreadPayLoad.m:531)
16  Foundation                      0x2efb9a0a __NSThread__main__ + 1058
17  libsystem_pthread.dylib         0x39386956 _pthread_body + 138
18  libsystem_pthread.dylib         0x393868c6 _pthread_start + 98
19  libsystem_pthread.dylib         0x39384ae4 thread_start + 4

Thread 7 name:  com.apple.NSURLConnectionLoader
Thread 7:
0   libsystem_kernel.dylib          0x3930ca50 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3930c848 mach_msg + 36
2   CoreFoundation                  0x2e59a5e4 __CFRunLoopServiceMachPort + 152
3   CoreFoundation                  0x2e598d04 __CFRunLoopRun + 788
4   CoreFoundation                  0x2e503724 CFRunLoopRunSpecific + 520
5   CoreFoundation                  0x2e503506 CFRunLoopRunInMode + 102
6   Foundation                      0x2ef4423c +[NSURLConnection(Loader) _resourceLoadLoop:] + 316
7   Foundation                      0x2efb9a0a __NSThread__main__ + 1058
8   libsystem_pthread.dylib         0x39386956 _pthread_body + 138
9   libsystem_pthread.dylib         0x393868c6 _pthread_start + 98
10  libsystem_pthread.dylib         0x39384ae4 thread_start + 4

Thread 8:
0   libsystem_kernel.dylib          0x3930ca50 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3930c848 mach_msg + 36
2   CoreFoundation                  0x2e59a5e4 __CFRunLoopServiceMachPort + 152
3   CoreFoundation                  0x2e598d04 __CFRunLoopRun + 788
4   CoreFoundation                  0x2e503724 CFRunLoopRunSpecific + 520
5   CoreFoundation                  0x2e503506 CFRunLoopRunInMode + 102
6   Foundation                      0x2eef7492 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7   CSR Proximity                   0x000fa41a -[CPSAutoFetchController threadRunLoop:] (CPSAutoFetchController.m:333)
8   Foundation                      0x2efb9a0a __NSThread__main__ + 1058
9   libsystem_pthread.dylib         0x39386956 _pthread_body + 138
10  libsystem_pthread.dylib         0x393868c6 _pthread_start + 98
11  libsystem_pthread.dylib         0x39384ae4 thread_start + 4

Thread 9:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 10:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 11 name:  com.apple.CFSocket.private
Thread 11:
0   libsystem_kernel.dylib          0x3931f434 __select + 20
1   CoreFoundation                  0x2e59e4de __CFSocketManager + 482
2   libsystem_pthread.dylib         0x39386956 _pthread_body + 138
3   libsystem_pthread.dylib         0x393868c6 _pthread_start + 98
4   libsystem_pthread.dylib         0x39384ae4 thread_start + 4

Thread 12:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 13 Crashed:
0   CSR Proximity                   0x0010fff4 checkSimpleEvent (lts_sdk_eval.c:560)
1   CSR Proximity                   0x001108b8 checkEvent (lts_sdk_eval.c:964)
2   CSR Proximity                   0x0011068c checkComplexEvent (lts_sdk_eval.c:1009)
3   CSR Proximity                   0x001108a2 checkEvent (lts_sdk_eval.c:971)
4   CSR Proximity                   0x00110962 Evaluate (lts_sdk_eval.c:1106)
5   CSR Proximity                   0x0010f0a2 -[CPSEventManager evaluate:] (CPSEventManager.m:170)
6   CoreFoundation                  0x2e5d3410 __invoking___ + 64
7   CoreFoundation                  0x2e51d962 -[NSInvocation invoke] + 282
8   Foundation                      0x2efa6d04 -[NSInvocationOperation main] + 108
9   Foundation                      0x2ef04870 -[__NSOperationInternal _start:] + 768
10  Foundation                      0x2efa8740 __NSOQSchedule_f + 56
11  libdispatch.dylib               0x39258cb8 _dispatch_queue_drain + 484
12  libdispatch.dylib               0x39255c6a _dispatch_queue_invoke + 38
13  libdispatch.dylib               0x392595ee _dispatch_root_queue_drain + 74
14  libdispatch.dylib               0x392598d8 _dispatch_worker_thread2 + 52
15  libsystem_pthread.dylib         0x39384c14 _pthread_wqthread + 296
16  libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 14:
0   libsystem_kernel.dylib          0x3931fc70 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x39384c1e _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x39384ad8 start_wqthread + 4

Thread 13 crashed with ARM Thread State (32-bit):
    r0: 0x03a3d4fe    r1: 0x00000000      r2: 0x14f46000      r3: 0x00000002
    r4: 0x00000007    r5: 0x14f27085      r6: 0x03a3d4ee      r7: 0x03a3d6e0
    r8: 0x03a3d675    r9: 0x00000fff     r10: 0x14f27084     r11: 0x00000006
    ip: 0x3b275118    sp: 0x03a3c464      lr: 0x0010ffdb      pc: 0x0010fff4
  cpsr: 0x00000030

I understand that there is some issue related to byte alignment. But don't have any idea about what I need to do.

The crash location code snippet is a valid value function call to :

static LtsEventStatus isBeaconInsideZoneAndDwellTime( const LtsBeaconProximityEvent* eventData,
    const LtsBeaconProximity  reportData, tSIRF_UINT8 isReverse, tSIRF_BOOL* found, tSIRF_UINT8 index)

Any help would be appreciated.

Thanks

Adding more details [caller snippet]

LtsServerConfigureLocal *cfg = GetConfiguration();
    LtsEventAttribute *attr;
    LtsEventStatus flag = LTS_FALSE;
    int beaconIndx = 0;
    tSIRF_UINT8 reverse;
    tSIRF_BOOL found;
    LtsEventResults* eventsResult;
    LtsProximalBeacons beacons = values->proximalBeacons;

    CCSE_INFO("BeaconFence: Index : %d, values count: %d\n", index, values->proximalBeacons.nValues);

    CCSE_INFO("BeaconFence 1");

    if( event->values.internal.value >= cfg->nAttributesCnt ) {
        CCSE_ERROR("Invalid LtsProximalBeacons index %d\n", event->values.internal.value );
        return LTS_FALSE; // error
    }
    CCSE_INFO("BeaconFence 2: %d", event->values.internal.value);
    attr = & cfg->attributes[ event->values.internal.value ];

    found = FALSE;
    reverse = 0x0F & ((event->values.internal.attributes & LTS_MASK_REVERSE)? 1: 0);
    CCSE_INFO("BeaconFence 3");

    //multiple beacons data
    for( ; beaconIndx < beacons.nValues ; beaconIndx++)
    {
        CCSE_INFO("BeaconFence 41");

        const LtsBeaconProximityEvent* eventData = NULL;
        const LtsBeaconProximity  *reportData = NULL;
        eventData = &attr->attribute.beaconProximity;
        CCSE_INFO("BeaconFence 411, eventData: %p, ", eventData );

        CCSE_INFO("BeaconFence 412, reportData:%p, beaconIndx: %p ",&beacons.values[beaconIndx], &beaconIndx );

        LtsBeaconProximity beacon = (eventData->proximalBeacon);
        reportData = &beacons.values[beaconIndx];
       // CCSE_INFO("eventData: nBeaconId: %d address of beaconid: %p, zone: %d, dwellTime: %f", beacon.beaconId, beacon.beaconId[5], beacon.zone, beacon.dwellTime);

        CCSE_INFO("Beacon Fence 413");

        CCSE_INFO("reportData: nBeaconId: %d beaconid: %s, dwellTime: %f, zone: %d, ", reportData->nBeaconId, reportData->beaconId, reportData->dwellTime, reportData->zone);



//        flag = isBeaconInsideZoneAndDwellTime( & attr->attribute.beaconProximity, beacons.values[beaconIndx], reverse, &found, index);
        flag = isBeaconInsideZoneAndDwellTime( eventData, beacons.values[beaconIndx], reverse, &found, index);

        CCSE_INFO("BeaconFence 42");
        if(found)
            break;
    }

The problem is the log "BeaconFence 42" is never printed at all. The code crashes while calling isBeaconInsideZoneAndDwellTime. In the console logs, we get sigbus 10

ios
crash
release-mode
sigbus
asked on Stack Overflow Jan 9, 2015 by Robin • edited Jan 12, 2015 by Robin

2 Answers

1

The EXC_ARM_DA_ALIGN would indicate that your code is trying to use a variable which is not aligned correctly inside isBeaconInsideZoneAndDwellTime.

From your comment on passing by value rather than address, this would imply that the code inside isBeaconInsideZoneAndDwellTime has a different view on the layout of the LtsBeaconProximity structure from the code calling it. When passing by value the bytes are copied, so the code inside isBeaconInsideZoneAndDwellTime is working on its version of LtsBeaconProximity structure layout. Assuming alignment issues exist, in this case you would see bad values in the structure rather than a SIGBUS. However you might be getting away with it if the bad values are 0 say or in an area not used. When passing by address, the code inside isBeaconInsideZoneAndDwellTime is using offsets and types based on its understanding of LtsbeaconProximity structure layout but using offsets onto the calling codes understanding of that structure. Here the use of a variable triggers the alignment issue as the two must be mismatched.

I would add some debug in the calling code to print out the offsets of the structure contents relative to the start address and the sizes. Then paste the same code into isBeaconInsideZoneAndDwellTime. If the code is misaligned, you will see different offsets.

An easy starting point is to print out sizeof(LtsbeaconProximity) in inside and outside the function. If different then you know its an issue.

If you can show us the structure for LtsbeaconProximity that would help us help I think.

answered on Stack Overflow Jan 16, 2015 by Rory McKinnel
0

Well, I have no clue why it got fixed. But I have tried it on quite a few ARM architectures and iOS devices, and it seems the crash has gone away after I pass the second argument by reference.

answered on Stack Overflow Jan 23, 2015 by Robin

User contributions licensed under CC BY-SA 3.0