解析IOS控制台利用GDB命令查看报错堆栈

解析IOS控制台利用GDB命令查看报错堆栈是本文要介绍的内容,在ios开发中,如果提前释放一个指针的内存,在以后还继续使用这个指针,那么程序会立刻crash掉,而且很难有报错信息,我以前都是靠猜测去判断错误的原因,我们应该利用工具去找到错误的地方,然后快速准确的定位到错误地方,及其错误原因,最后进行改进。

其实ios控制台,提供这种机制,如果你选择debug模式,在程序crash之后,在控制台输入bt,就可以显示crash堆栈

  1. Program received signal:  “EXC_BAD_ACCESS”.   
  2. warning: Unable to read symbols for /Developer/ios4.2.1/Platforms/iPhoneOS.platform/DeviceSupport/
  3. 4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).   
  4. (gdb) bt   
  5. #0  0x33a06464 in objc_msgSend ()   
  6. #1  0x3139de2e in -[UIImageView setImage:] ()   
  7. #2  0x00009ecc in -[RoundMenuView touchesEnded:withEvent:] 
  8. (self=0x29e140_cmd=0x316b1a7btouches=0x2e1050event=0x2424f0) at /Users/wangjun/workspace/iphone/Classes/RoundMenuView.m:130   
  9. #3  0x313b1354 in -[UIWindow _sendTouchesForEvent:] ()   
  10. #4  0x313b0cce in -[UIWindow sendEvent:] ()   
  11. #5  0x3139bfc6 in -[UIApplication sendEvent:] ()   
  12. #6  0x3139b906 in _UIApplicationHandleEvent ()   
  13. #7  0x31eecf02 in PurpleEventCallback ()   
  14. #8  0x304236fe in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()   
  15. #9  0x304236c2 in __CFRunLoopDoSource1 ()   
  16. #10 0x30415f7c in __CFRunLoopRun ()   
  17. #11 0x30415c86 in CFRunLoopRunSpecific ()   
  18. #12 0x30415b8e in CFRunLoopRunInMode ()   
  19. #13 0x31eec4aa in GSEventRunModal ()   
  20. #14 0x31eec556 in GSEventRun ()   
  21. #15 0x313cf328 in -[UIApplication _run] ()   
  22. #16 0x313cce92 in UIApplicationMain ()   
  23. #17 0x00002da2 in main (argc=1argv=0x2fdff44c) at /Users/wangjun/workspace/iphone/main.m:19   
  24. kill   
  25. quit 
原文地址:https://www.cnblogs.com/yingkong1987/p/2948620.html