在调试iOS程序时如何追溯到dispatch_async之外? [英] how can I trace back beyond dispatch_async when debugging an iOS program?

查看:223
本文介绍了在调试iOS程序时如何追溯到dispatch_async之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人在调试我的iOS程序时知道如何追溯到dispatch_async之外。我的程序常量在以下两个位置崩溃:在buffer_is_unused中,如和,
和release_shmem_bitmap中的内容,如和。所有这些都不会在主线程上发生,并且在线程本地堆栈上几乎没有任何东西,除了一些dispatch_async和pthread作业。考虑到我对XCode的配置,它几乎不提供有关谁调用此dispatched_async的信息。我用Google搜索 release_shmem_bitmap,发现网络上只有几个网页,但没有一个有用。我想知道是否有人知道如何制作Xcode来显示谁调用了这些dispatch_async,或者总的来说我该如何解决此类崩溃?

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?

推荐答案

iOS异步堆栈跟踪记录 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.

但是,XBAsyncStackTrace将为您提供

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 !

这篇关于在调试iOS程序时如何追溯到dispatch_async之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆