iOS跟踪异常堆栈方法

分析堆栈报告,例如:

2015-12-28 23:16:39.258 NSLogDemo[1010:65404] -[ViewController func]: unrecognized selector sent to instance 0x7fb2cb517fc0
2015-12-28 23:16:39.262 NSLogDemo[1010:65404] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController func]: unrecognized selector sent to instance 0x7fb2cb517fc0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000108201e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000107c78deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010820a48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010815790a ___forwarding___ + 970
    4   CoreFoundation                      0x00000001081574b8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x00000001085b1194 -[UIApplication sendAction:to:from:forEvent:] + 92
    6   UIKit                               0x00000001087206fc -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00000001087209c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
    8   UIKit                               0x000000010871faf8 -[UIControl touchesEnded:withEvent:] + 601
    9   UIKit                               0x000000010862049b -[UIWindow _sendTouchesForEvent:] + 835
    10  UIKit                               0x00000001086211d0 -[UIWindow sendEvent:] + 865
    11  UIKit                               0x00000001085cfb66 -[UIApplication sendEvent:] + 263
    12  UIKit                               0x00000001085a9d97 _UIApplicationHandleEventQueue + 6844
    13  CoreFoundation                      0x000000010812da31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x000000010812395c __CFRunLoopDoSources0 + 556
    15  CoreFoundation                      0x0000000108122e13 __CFRunLoopRun + 867
    16  CoreFoundation                      0x0000000108122828 CFRunLoopRunSpecific + 488
    17  GraphicsServices                    0x000000010b9faad2 GSEventRunModal + 161
    18  UIKit                               0x00000001085af610 UIApplicationMain + 171
    19  NSLogDemo                           0x0000000107777b4f main + 111
    20  libdyld.dylib                       0x000000010a95592d start + 1
)

第一行代码的表示 不能识别ViewController 中的func方法

一条堆栈信息有5部分

    19  NSLogDemo  0x0000000107777b4f   main  + 111
    ①      ②                 ③         ④      ⑤

第一部分:堆栈输出序列号,序号越大表示越早被调用
第二部分:调用方法(或函数)所属的框架(或库),上面信息中的是我们编写的项目名
第三部分:调用方法的内存地址,对我们用处不大
第四部分:调用方法(或函数)名,这个信息很重要
第五部分:调用方法编译后的代码偏移量,不是行号,没什么帮助

堆栈信息是要从下往上看的,下面的语句是NSLogDemo中的main函数调用UIKit中的UIApplicationMain方法

    18  UIKit  0x00000001085af610 UIApplicationMain + 171
    19  NSLogDemo  0x0000000107777b4f main + 111

最快的阅读方式是从上向下看,找到第二部分中第一个自己的方法 ,找到TA上一行中的第四部分,这个位置就是出错的地方

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,226评论 30 472
  • 1.属性readwrite,readonly,assign,retain,copy,nonatomic 各是什么作...
    曾令伟阅读 1,084评论 0 10
  • 讲一个老生常谈的话题。 初中之前,偶然一次听到老师说到:“我们中国有两所最著名大学,一个是清华,一个是北大,清华大...
    Giftfor2016阅读 398评论 0 1
  • 想留下点什么 虽然我总是害怕回顾过去 但是 总是会想留下什么 因为我太健忘了 知道自己是个懒惰的人 也是只会在...
    栗子梨阅读 287评论 0 0