应用拒绝SIGABRT iOS

时间:2014-04-16 09:54:35

标签: ios multithreading exception-handling crash sigabrt

由于EXC_CRASH(SIGABRT)异常,我最近收到了拒绝应用。 异常是从try-catch块中抛出的。

所以我有两个主要问题:

  1. 目标c中的try-catch子句是否捕获所有异常?

  2. 我在符号化的崩溃日志下面。在线程7(崩溃的那个)上我试着写一个NSMutableDictionary。同样的字典也在其他线程上使用(修改)。这可能是造成这次事故的原因吗? (也许2个线程试图一次修改字典)。如果是这样,为什么不是第二个线程试图在崩溃日志中做同样的事情?另外:@synchronize(用于识别该变量的NSString){更改我的NSMutableDictionary /从我的NSMutableDictionary读取}解决了我的问题?

  3. 感谢。

    符号化崩溃日志:

    Incident Identifier: 1A82F42E-59AA-499A-8C1D-CE744808F566
    CrashReporter Key:   4f2c8fa05c83e9d455c232dbd2fa63e852283d0e
    Hardware Model:      xxx
    Version:             1.0 (1.0)
    Code Type:           ARM-64 (Native)
    Parent Process:      launchd [1]
    
    OS Version:          iOS 7.1 (11D167)
    Report Version:      104
    
    Exception Type:  EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Triggered by Thread:  7
    
    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0:
    0   libsystem_kernel.dylib          0x0000000191179ca0 mach_msg_trap + 8
    1   CoreFoundation                  0x000000018408a570 __CFRunLoopServiceMachPort + 180
    2   CoreFoundation                  0x0000000184088764 __CFRunLoopRun + 932
    3   CoreFoundation                  0x0000000183fc96cc CFRunLoopRunSpecific + 448
    4   GraphicsServices                0x0000000189c65c08 GSEventRunModal + 164
    5   UIKit                           0x00000001870fafd8 UIApplicationMain + 1152
    6   brandnooz                       0x00000001000df500 main (main.m:16)
    7   libdyld.dylib                   0x0000000191097a9c start + 0
    
    Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
    Thread 1:
    0   libsystem_kernel.dylib          0x0000000191179aa8 kevent64 + 8
    1   libdispatch.dylib               0x000000019107d998 _dispatch_mgr_thread + 48
    
    Thread 2:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 3 name:  Dispatch queue: com.apple.root.default-priority
    Thread 3:
    0   libsystem_kernel.dylib          0x0000000191179cdc semaphore_wait_trap + 8
    1   brandnooz                       0x000000010006fe9c __41-[RequestsViewController waitForRequests]_block_invoke (RequestsViewController.m:79)
    2   libdispatch.dylib               0x000000019107c010 _dispatch_call_block_and_release + 20
    3   libdispatch.dylib               0x000000019107bfd0 _dispatch_client_callout + 12
    4   libdispatch.dylib               0x00000001910832b4 _dispatch_root_queue_drain + 552
    5   libdispatch.dylib               0x00000001910834f8 _dispatch_worker_thread2 + 72
    6   libsystem_pthread.dylib         0x00000001912116b8 _pthread_wqthread + 352
    7   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 4:
    0   libsystem_kernel.dylib          0x0000000191179ca0 mach_msg_trap + 8
    1   CoreFoundation                  0x000000018408a570 __CFRunLoopServiceMachPort + 180
    2   CoreFoundation                  0x0000000184088700 __CFRunLoopRun + 832
    3   CoreFoundation                  0x0000000183fc96cc CFRunLoopRunSpecific + 448
    4   Foundation                      0x0000000184b652c0 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 292
    5   Foundation                      0x0000000184bc2d74 -[NSRunLoop(NSRunLoop) run] + 92
    6   brandnooz                       0x0000000100115ed8 +[GAI threadMain:] + 68
    7   Foundation                      0x0000000184c4c408 __NSThread__main__ + 996
    8   libsystem_pthread.dylib         0x0000000191213e18 _pthread_body + 164
    9   libsystem_pthread.dylib         0x0000000191213d70 _pthread_start + 136
    10  libsystem_pthread.dylib         0x0000000191211550 thread_start + 0
    
    Thread 5 name:  Dispatch queue: com.apple.root.default-priority
    Thread 5:
    0   libsystem_kernel.dylib          0x0000000191192448 __psynch_rw_rdlock + 8
    1   libobjc.A.dylib                 0x0000000190aaab84 lookUpImpOrForward + 164
    2   libobjc.A.dylib                 0x0000000190ab43f8 _objc_msgSend_uncached_impcache + 56
    3   brandnooz                       0x00000001000a14f8 -[AFHTTPRequestOperation hasAcceptableStatusCode] (AFHTTPRequestOperation.m:203)
    4   brandnooz                       0x00000001000a0710 -[AFHTTPRequestOperation error] (AFHTTPRequestOperation.m:137)
    5   brandnooz                       0x00000001000ebed8 -[AFJSONRequestOperation error] (AFJSONRequestOperation.m:99)
    6   brandnooz                       0x00000001000ec128 __64-[AFJSONRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke (AFJSONRequestOperation.m:121)
    7   brandnooz                       0x0000000100075a20 __47-[AFURLConnectionOperation setCompletionBlock:]_block_invoke (AFURLConnectionOperation.m:321)
    8   Foundation                      0x0000000184c34168 __103+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke96 + 24
    9   libdispatch.dylib               0x000000019107c010 _dispatch_call_block_and_release + 20
    10  libdispatch.dylib               0x000000019107bfd0 _dispatch_client_callout + 12
    11  libdispatch.dylib               0x00000001910832b4 _dispatch_root_queue_drain + 552
    12  libdispatch.dylib               0x00000001910834f8 _dispatch_worker_thread2 + 72
    13  libsystem_pthread.dylib         0x00000001912116b8 _pthread_wqthread + 352
    14  libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 6 name:  Dispatch queue: com.apple.root.high-priority
    Thread 6:
    0   libsystem_kernel.dylib          0x0000000191192394 __psynch_cvwait + 8
    1   Foundation                      0x0000000184c338e0 -[__NSOperationInternal _waitUntilFinished:] + 100
    2   brandnooz                       0x00000001000b71f0 -[ApiConnection get:] (ApiConnection.m:152)
    3   brandnooz                       0x0000000100104b2c __38-[ApiRequests getTranslationsForCode:]_block_invoke (ApiRequests.m:185)
    4   libdispatch.dylib               0x000000019107c010 _dispatch_call_block_and_release + 20
    5   libdispatch.dylib               0x000000019107bfd0 _dispatch_client_callout + 12
    6   libdispatch.dylib               0x00000001910832b4 _dispatch_root_queue_drain + 552
    7   libdispatch.dylib               0x00000001910834f8 _dispatch_worker_thread2 + 72
    8   libsystem_pthread.dylib         0x00000001912116b8 _pthread_wqthread + 352
    9   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 7 name:  Dispatch queue: com.apple.root.high-priority
    Thread 7 Crashed:
    0   libsystem_kernel.dylib          0x000000019119258c __pthread_kill + 8
    1   libsystem_c.dylib               0x0000000191126804 abort + 108
    2   libsystem_malloc.dylib          0x00000001911cc5c0 nanozone_error + 292
    3   libsystem_malloc.dylib          0x00000001911cbd5c nano_free_definite_size + 128
    4   CoreFoundation                  0x00000001840ca268 __rehashd + 236
    5   CoreFoundation                  0x0000000183fd1814 -[__NSDictionaryM setObject:forKey:] + 648
    6   brandnooz                       0x0000000100103f84 __22-[ApiRequests getFaq:]_block_invoke (ApiRequests.m:120)
    7   libdispatch.dylib               0x000000019107c010 _dispatch_call_block_and_release + 20
    8   libdispatch.dylib               0x000000019107bfd0 _dispatch_client_callout + 12
    9   libdispatch.dylib               0x00000001910832b4 _dispatch_root_queue_drain + 552
    10  libdispatch.dylib               0x00000001910834f8 _dispatch_worker_thread2 + 72
    11  libsystem_pthread.dylib         0x00000001912116b8 _pthread_wqthread + 352
    12  libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 8 name:  Dispatch queue: com.apple.root.high-priority
    Thread 8:
    0   libsystem_kernel.dylib          0x0000000191192394 __psynch_cvwait + 8
    1   Foundation                      0x0000000184c338e0 -[__NSOperationInternal _waitUntilFinished:] + 100
    2   brandnooz                       0x00000001000b71f0 -[ApiConnection get:] (ApiConnection.m:152)
    3   brandnooz                       0x00000001001038e8 __24-[ApiRequests getTerms:]_block_invoke (ApiRequests.m:84)
    4   libdispatch.dylib               0x000000019107c010 _dispatch_call_block_and_release + 20
    5   libdispatch.dylib               0x000000019107bfd0 _dispatch_client_callout + 12
    6   libdispatch.dylib               0x00000001910832b4 _dispatch_root_queue_drain + 552
    7   libdispatch.dylib               0x00000001910834f8 _dispatch_worker_thread2 + 72
    8   libsystem_pthread.dylib         0x00000001912116b8 _pthread_wqthread + 352
    9   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 9:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 10 name:  Dispatch queue: com.apple.root.high-priority
    Thread 10:
    0   libsystem_kernel.dylib          0x0000000191192394 __psynch_cvwait + 8
    1   Foundation                      0x0000000184c338e0 -[__NSOperationInternal _waitUntilFinished:] + 100
    2   brandnooz                       0x00000001000b71f0 -[ApiConnection get:] (ApiConnection.m:152)
    3   brandnooz                       0x00000001001060b4 __46-[ApiRequests getProductsWithKickbackForCache]_block_invoke (ApiRequests.m:307)
    4   libdispatch.dylib               0x000000019107c010 _dispatch_call_block_and_release + 20
    5   libdispatch.dylib               0x000000019107bfd0 _dispatch_client_callout + 12
    6   libdispatch.dylib               0x00000001910832b4 _dispatch_root_queue_drain + 552
    7   libdispatch.dylib               0x00000001910834f8 _dispatch_worker_thread2 + 72
    8   libsystem_pthread.dylib         0x00000001912116b8 _pthread_wqthread + 352
    9   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 11:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 12 name:  AFNetworking
    Thread 12:
    0   libsystem_platform.dylib        0x000000019120cdc8 _platform_memmove + 40
    1   CoreFoundation                  0x0000000183fe205c dataWrite + 176
    2   CoreFoundation                  0x0000000183fe1dc8 CFWriteStreamWrite + 440
    3   brandnooz                       0x0000000100077e3c -[AFURLConnectionOperation connection:didReceiveData:] (AFURLConnectionOperation.m:797)
    4   Foundation                      0x0000000184b82894 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 76
    5   Foundation                      0x0000000184b82780 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 228
    6   Foundation                      0x0000000184b82678 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
    7   Foundation                      0x0000000184b82a7c _NSURLConnectionDidReceiveData + 76
    8   CFNetwork                       0x0000000183caf320 ___ZN27URLConnectionClient_Classic23_delegate_cacheTrifectaEPK20_CFCachedURLResponseU13block_pointerFvvE_block_invoke + 428
    9   CFNetwork                       0x0000000183cab6e0 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 92
    10  CoreFoundation                  0x0000000183fc908c CFArrayApplyFunction + 64
    11  CFNetwork                       0x0000000183c20be8 RunloopBlockContext::perform() + 132
    12  CFNetwork                       0x0000000183c20a64 MultiplexerSource::perform() + 284
    13  CFNetwork                       0x0000000183c208a0 MultiplexerSource::_perform(void*) + 56
    14  CoreFoundation                  0x000000018408b040 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
    15  CoreFoundation                  0x000000018408a39c __CFRunLoopDoSources0 + 252
    16  CoreFoundation                  0x0000000184088634 __CFRunLoopRun + 628
    17  CoreFoundation                  0x0000000183fc96cc CFRunLoopRunSpecific + 448
    18  Foundation                      0x0000000184b652c0 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 292
    19  Foundation                      0x0000000184bc2d74 -[NSRunLoop(NSRunLoop) run] + 92
    20  brandnooz                       0x000000010007533c +[AFURLConnectionOperation networkRequestThreadEntryPoint:] (AFURLConnectionOperation.m:193)
    21  Foundation                      0x0000000184c4c408 __NSThread__main__ + 996
    22  libsystem_pthread.dylib         0x0000000191213e18 _pthread_body + 164
    23  libsystem_pthread.dylib         0x0000000191213d70 _pthread_start + 136
    24  libsystem_pthread.dylib         0x0000000191211550 thread_start + 0
    
    Thread 13 name:  com.apple.NSURLConnectionLoader
    Thread 13:
    0   libsystem_malloc.dylib          0x00000001911bf020 free + 72
    1   CoreFoundation                  0x0000000184088b38 __CFRunLoopRun + 1912
    2   CoreFoundation                  0x0000000183fc96cc CFRunLoopRunSpecific + 448
    3   Foundation                      0x0000000184bbe424 +[NSURLConnection(Loader) _resourceLoadLoop:] + 344
    4   Foundation                      0x0000000184c4c408 __NSThread__main__ + 996
    5   libsystem_pthread.dylib         0x0000000191213e18 _pthread_body + 164
    6   libsystem_pthread.dylib         0x0000000191213d70 _pthread_start + 136
    7   libsystem_pthread.dylib         0x0000000191211550 thread_start + 0
    
    Thread 14:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 15:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 16:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 17:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 18:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 19:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 20:
    0   libsystem_kernel.dylib          0x0000000191192e74 __workq_kernreturn + 8
    1   libsystem_pthread.dylib         0x0000000191211548 start_wqthread + 0
    
    Thread 21 name:  com.apple.CFSocket.private
    Thread 21:
    0   libsystem_kernel.dylib          0x000000019119276c __select + 8
    1   libsystem_pthread.dylib         0x0000000191213e18 _pthread_body + 164
    2   libsystem_pthread.dylib         0x0000000191213d70 _pthread_start + 136
    3   libsystem_pthread.dylib         0x0000000191211550 thread_start + 0
    
    Thread 7 crashed with ARM Thread State (64-bit):
        x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
        x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x00676f6c7379732f   x7: 0x0000000000000110
        x8: 0x000000000c000000   x9: 0x0000000004000000  x10: 0x000000000000000a  x11: 0x0000000000000007
        x12: 0x0000000000000037  x13: 0x00000001001814dc  x14: 0x0000000000000071  x15: 0x0000000004060401
        x16: 0x0000000000000148  x17: 0x0000000001030301  x18: 0x0000000000000000  x19: 0x0000000000000006
        x20: 0x0000000103180000  x21: 0x0000000100258000  x22: 0x00000001911d3053  x23: 0x0000000178037e20
        x24: 0x0000000000000000  x25: 0x00000001914e4000  x26: 0x00000001914e4000  x27: 0x0000000000000003
        x28: 0x0000000000000003  fp: 0x000000010317fc50   lr: 0x000000019121516c
        sp: 0x000000010317fc30   pc: 0x000000019119258c cpsr: 0x00000000
    

    代码示例:

    -(void) getFaq:(NSString*)ln
    {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
        [self.isDone setObject:dispatch_group_create() forKey:TAG_GET_FAQ];
    
        dispatch_group_async(self.isDone[TAG_GET_FAQ],dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    
            @try
            {
                ApiConnection* apiConnection = [[ApiConnection alloc] init];
    
                NSString* apiPath = [TAG_API_PATH_GET_FAQ stringByReplacingOccurrencesOfString:@"LANGUAGE" withString:ln];
                id JSON=[apiConnection get:apiPath];
    
                [self.responses setObject:JSON forKey:TAG_GET_FAQ];                  //  <-- crash
                [self.processedResponses setObject:JSON forKey:TAG_GET_FAQ];
            }
            @catch (NSException *exception) {
                id tracker = [[GAI sharedInstance] defaultTracker];
                NSString* message = [NSString stringWithFormat:@"Exception ApiRequests: %@", exception];
                [tracker send:[[GAIDictionaryBuilder createExceptionWithDescription:message withFatal:NO] build]];
    
                NSLog(@"Error in [ApiRequests getFaq] - possible null response");
                [self.responses setObject:[[NSMutableDictionary alloc] init] forKey:TAG_GET_FAQ];
                [self.processedResponses setObject:[[NSMutableDictionary alloc] init] forKey:TAG_GET_FAQ];
            }
            @finally
            {
                [self setNetworkActivityIndicatorVisibility:TAG_GET_FAQ];
            }
        });
    }
    
    
    Constants.h
    
    extern NSString* const TAG_GET_FAQ;
    extern NSString* const TAG_API_PATH_GET_FAQ;
    
    Constants.m
    
    NSString* const TAG_GET_FAQ = @"fooBar1";
    NSString* const TAG_API_PATH_GET_FAQ = @"fooBar2";
    

3 个答案:

答案 0 :(得分:0)

你应该确保他们的密钥不是零。密钥应符合NSCopying协议。

请参阅here

并在 Apple文档

The key for value. Note that when using key-value coding, the key must be a string (see “Key-Value Coding Fundamentals”).

source

答案 1 :(得分:0)

看起来有些内存损坏,可能发生在代码中的任何地方。不会抛出任何异常,因此不会捕获任何异常。

答案 2 :(得分:0)

严格阅读您的代码,

TAG_API_PATH_GET_FAQ = @"fooBar2";

表示

[TAG_API_PATH_GET_FAQ stringByReplacingOccurrencesOfString:@"LANGUAGE" withString:ln];

将是fooBar2

我猜这将会成为

            id JSON=[apiConnection get:apiPath];

返回零。我这样说是因为你的寄存器

Thread 7 crashed with ARM Thread State (64-bit):
x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x00676f6c7379732f   x7: 0x0000000000000110
x8: 0x000000000c000000   x9: 0x0000000004000000  x10: 0x000000000000000a  x11: 0x0000000000000007

大部分都是零(告诉我回到基础套路的零)。

您是否忘记使用正确的值更新fooBar2?如果你故意模糊了这个的实际价值,那么你能用更接近实际例子的内容来替换你的帖子吗。

此外,try-catch的使用与Apple家居风格(您可能不同意)不符。 try-catch用于编程错误,不会对外部系统做出错误的响应。

如果你有一个热门数据结构(并发添加/删除),那么值得投资记录数据的所有更新,并可能有断言。