在调试iOS程序时,如何追溯到dispatch_async之外?

时间:2015-04-23 00:06:00

标签: ios debugging dispatch-async

我想知道在调试我的iOS程序时是否有人知道如何追溯到dispatch_async之外。我的程序在两个位置不断崩溃:在buffer_is_unused中,如所示,  在release_shmem_bitmap中,如所示。这些都不会发生在主线程上,并且在线程局部堆栈上几乎没有任何东西,除了一些dispatch_async和pthread作业。鉴于我的XCode配置,它几乎没有给出关于谁调用此dispatched_async的信息。我用谷歌搜索“release_shmem_bitmap”,发现网上只有几个网页,但没有一个是有帮助的。我想知道是否有人知道如何让Xcode显示谁调用这些dispatch_async,或者一般如何解决这种崩溃?

1 个答案:

答案 0 :(得分:0)

iOS异步堆栈跟踪记录 https://github.com/tiantianbobo/XBAsyncStackTrace

假设在发行版中编译时是这样的代码:

- (void)callCrashFunc {
id object = (__bridge id)(void*)1;
[object class];
//    NSLog(@"remove this line will cause tail call optimization");
}
- (void)testDispatchAsyncCrash {
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [self callCrashFunc];
    });
}

正常的堆栈跟踪方法只会为您提供:

frame #0: 0x000000010186fd85 libobjc.A.dylib`objc_msgSend + 5
    frame #1: 0x0000000104166595 libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #2: 0x0000000104167602 libdispatch.dylib`_dispatch_client_callout + 8
    frame #3: 0x000000010416a064 libdispatch.dylib`_dispatch_queue_override_invoke + 1028
    frame #4: 0x000000010417800a libdispatch.dylib`_dispatch_root_queue_drain + 351
    frame #5: 0x00000001041789af libdispatch.dylib`_dispatch_worker_thread2 + 130
    frame #6: 0x0000000104553169 libsystem_pthread.dylib`_pthread_wqthread + 1387
    frame #7: 0x0000000104552be9 libsystem_pthread.dylib`start_wqthread + 13

但是您仍然不知道实际代码在哪里。

但是,XBAsyncStackTrace将为您提供:

0   XBAsyncStackTraceExample            0x000000010c89d75c blockRecordAsyncTrace + 76
1   XBAsyncStackTraceExample            0x000000010c89d302 wrap_dispatch_async + 98
2   XBAsyncStackTraceExample            0x000000010c89c02c -[ViewController testDispatchAsyncCrash] + 92
3   XBAsyncStackTraceExample            0x000000010c89be3d -[ViewController viewDidLoad] + 269
4   UIKitCore                           0x0000000110ae44e1 -[UIViewController loadViewIfRequired] + 1186
5   UIKitCore                           0x0000000110ae4940 -[UIViewController view] + 27

宾果!