iOS 应用程序在设备上的发布版本中崩溃

iOS Application crashes in release version on device

我遇到了一个奇怪的问题,并且已经在这上面花了很多时间。

我的应用程序在设备上发生崩溃,特别是在发布版本中。

崩溃日志是:

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

我了解到存在一些与字节对齐相关的问题。但是不知道我需要做什么。

崩溃位置代码片段是对 :

的有效值函数调用
static LtsEventStatus isBeaconInsideZoneAndDwellTime( const LtsBeaconProximityEvent* eventData,
    const LtsBeaconProximity  reportData, tSIRF_UINT8 isReverse, tSIRF_BOOL* found, tSIRF_UINT8 index)

如有任何帮助,我们将不胜感激。

谢谢

添加更多详细信息[调用者代码段]

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;
    }

问题是日志 "BeaconFence 42" 根本没有打印出来。代码在调用 isBeaconInsideZoneAndDwellTime 时崩溃。在控制台日志中,我们得到 sigbus 10

EXC_ARM_DA_ALIGN 表示您的代码正在尝试使用未在 isBeaconInsideZoneAndDwellTime 中正确对齐的变量。

根据您对按值而非地址传递的评论,这意味着 isBeaconInsideZoneAndDwellTime 中的代码与调用它的代码对 LtsBeaconProximity 结构的布局有不同的看法。当按值传递时,字节被复制,因此 isBeaconInsideZoneAndDwellTime 中的代码正在处理其版本的 LtsBeaconProximity 结构布局。假设存在对齐问题,在这种情况下,您会在结构中看到错误的值,而不是 SIGBUS。但是,如果坏值是 0 或在未使用的区域中,您可能会侥幸逃脱。当按地址传递时,isBeaconInsideZoneAndDwellTime 中的代码根据其对 LtsbeaconProximity 结构布局的理解使用偏移量和类型,但在调用代码上使用对该结构的理解的偏移量。这里使用变量会触发对齐问题,因为两者必须不匹配。

我会在调用代码中添加一些调试,以打印出结构内容相对于起始地址和大小的偏移量。然后将相同的代码粘贴到 isBeaconInsideZoneAndDwellTime 中。如果代码未对齐,您将看到不同的偏移量。

一个简单的起点是在函数内外打印出 sizeof(LtsbeaconProximity)。如果不同,那么您就知道这是一个问题。

如果您能向我们展示 LtsbeaconProximity 的结构,我想这会对我们有所帮助。

好吧,我不知道为什么它得到修复。但是我已经在相当多的 ARM 架构和 iOS 设备上进行了尝试,在我通过引用传递第二个参数后,崩溃似乎已经消失了。