how can I trace back beyond dispatch_async when debugging an iOS program?

心不动则不痛 提交于 2019-12-11 02:23:31

问题


I wonder if anyone knows how can I trace back beyond dispatch_async when debugging my iOS program. My program constant crash at two spots: in buffer_is_unused, as shown in

and

, and in release_shmem_bitmap, as shown in

and

. None of this happens at the main thread, and on the thread-local stack there is almost nothing except some dispatch_async and pthread jobs. Given my configuration of XCode, it gives me almost no information on who called this dispatched_async. I googled "release_shmem_bitmap" and found only a few webpage on the web and none of them are helpful. I wonder if anyone knows how can I make Xcode to show who called these dispatch_async or in general how shall I fix such crash?

回答1:


iOS async stack trace record https://github.com/tiantianbobo/XBAsyncStackTrace

Suppose codes like this when compiled in release version:

- (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];
    });
}

normal stack trace methods only get you this:

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

But you still don't know where actual code is.

However, XBAsyncStackTrace will give you:

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

Bingo!



来源:https://stackoverflow.com/questions/29811207/how-can-i-trace-back-beyond-dispatch-async-when-debugging-an-ios-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!