如何获取导致崩溃的类和方法名称?

时间:2017-01-04 08:40:26

标签: ios objective-c stack-trace

当应用程序崩溃时,我的调试控制台中的堆栈低于堆栈。

(
    0   CoreFoundation                      0x000000010811434b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000107b4821e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010816cbdf -[__NSSingleObjectArrayI objectAtIndex:] + 111
    3   FanPaas                             0x0000000106fa48fa -[ViewController openCrash] + 90
    4   UIKit                               0x0000000109bd3b88 -[UIApplication sendAction:to:from:forEvent:] + 83
    5   UIKit                               0x0000000109d592b2 -[UIControl sendAction:to:forEvent:] + 67
    6   UIKit                               0x0000000109d595cb -[UIControl _sendActionsForEvents:withEvent:] + 444
    7   UIKit                               0x0000000109d584c7 -[UIControl touchesEnded:withEvent:] + 668
    8   UIKit                               0x0000000109c410d5 -[UIWindow _sendTouchesForEvent:] + 2747
    9   UIKit                               0x0000000109c427c3 -[UIWindow sendEvent:] + 4011
    10  UIKit                               0x0000000109befa33 -[UIApplication sendEvent:] + 371
    11  UIKit                               0x000000010a3e1b6d __dispatchPreprocessedEventFromEventQueue + 3248
    12  UIKit                               0x000000010a3da817 __handleEventQueue + 4879
    13  CoreFoundation                      0x00000001080b9311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x000000010809e59c __CFRunLoopDoSources0 + 556
    15  CoreFoundation                      0x000000010809da86 __CFRunLoopRun + 918
    16  CoreFoundation                      0x000000010809d494 CFRunLoopRunSpecific + 420
    17  GraphicsServices                    0x000000010f82ba6f GSEventRunModal + 161
    18  UIKit                               0x0000000109bd1f34 UIApplicationMain + 159
    19  FanPaas                             0x0000000106fdf66f main + 111
    20  libdyld.dylib                       0x000000010c65868d start + 1
)

所以我尝试使用[NSThread callStackSymbols]中的NSSetUncaughtExceptionHandler(&HandleException)抓住该堆栈跟踪。

(
    0   FanPaas                             0x000000010176f05e +[UncaughtExceptionHandler backtrace] + 46
    1   FanPaas                             0x000000010176fe92 HandleException + 98
    2   CoreFoundation                      0x00000001028f156c __handleUncaughtException + 732
    3   libobjc.A.dylib                     0x00000001022bc496 _ZL15_objc_terminatev + 94
    4   libc++abi.dylib                     0x0000000107382e69 _ZSt11__terminatePFvvE + 8
    5   libc++abi.dylib                     0x0000000107382af4 __cxa_rethrow + 99
    6   libobjc.A.dylib                     0x00000001022bc3b7 objc_exception_rethrow + 40
    7   CoreFoundation                      0x000000010281151b CFRunLoopRunSpecific + 555
    8   GraphicsServices                    0x000000010a6bfa6f GSEventRunModal + 161
    9   UIKit                               0x0000000104345f34 UIApplicationMain + 159
    10  FanPaas                             0x000000010175020f main + 111
    11  libdyld.dylib                       0x00000001074ec68d start + 1
)

实际上[ViewController openCrash]导致了崩溃,但我没有在callStackSymbols中得到这个。但是它在调试控制台中显示。

如何获取导致崩溃的类和方法名称?

3 个答案:

答案 0 :(得分:1)

enter image description here

  

在顶部选择断点符号,然后单击底部的+符号,然后单击异常断点。因此,它会引导您导致崩溃的特定行。

答案 1 :(得分:1)

您可以通过Twitter使用Fabric Crashlytic。这很好。

PS。我不隶属于Twitter。

见这里https://fabric.io/kits/ios/crashlytics

答案 2 :(得分:0)

你可以这样做:

1. Enable exception breakpoint.
2. Your breakpoint will stop on method which causing crash.
3. Add try catch block in that method, in catch block you can print method name and exception.