【问题标题】:how can I trace back beyond dispatch_async when debugging an iOS program?调试 iOS 程序时如何追溯 dispatch_async 之外的内容?
【发布时间】:2015-06-30 21:59:24
【问题描述】:

我想知道是否有人知道在调试我的 iOS 程序时如何追溯 dispatch_async 之外的内容。我的程序在两个地方经常崩溃:在buffer_is_unused中,如和所示, 并在release_shmem_bitmap中,如和所示。这些都不会发生在主线程上,而在线程本地堆栈上,除了一些 dispatch_async 和 pthread 作业之外几乎什么都没有。鉴于我的 XCode 配置,它几乎没有给我关于谁调用了这个 dispatched_async 的信息。我用谷歌搜索“release_shmem_bitmap”,发现网上只有几个网页,没有一个有用。我想知道是否有人知道我怎样才能让 Xcode 显示谁调用了这些 dispatch_async 或者一般来说我应该如何修复这种崩溃?

【问题讨论】:

  • 请发布您的堆栈跟踪
  • @Zolnoor 线程视图不是堆栈跟踪吗?你是说 po [NSThread callstackSymbols] 的输出吗?
  • 不,兄弟,它看起来像这样imgur.com/Voq04M2
  • @Zolnoor 嗨,是的,我真的很想得到那种堆栈跟踪,但是我怎样才能得到呢?我搜索了“如何获取 iOS stracktrace”,答案(如 stackoverflow.com/questions/220159/…)只说“[NSThread callstackSymbols]”,其输出不是很有帮助。
  • 使用它来打开你的控制台调试器stackoverflow.com/questions/25860987/… 虽然如果你输入po 听起来你正在使用它。您应该让程序崩溃以查看此跟踪。您的程序可能会在 all exception 断点处暂停。

标签: ios debugging dispatch-async


【解决方案1】:

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

宾果游戏!

【讨论】:

    猜你喜欢
    • 2011-05-16
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多