了解IOS控制臺Consol
了解IOS控制臺Consol是本文要介紹的內容,文中分別從利用 gdb 命令查看報錯堆棧和查看全局變量值兩個內容介紹,先來看詳解。
利用 gdb 命令查看報錯堆棧
在 iOS 開發(fā)中,如果提前釋放一個指針的內存,在以后還繼續(xù)使用這個指針,那么程序會立刻 crash 掉,而且很難有報錯信息,我以前都是靠猜測去判斷錯誤的原因,我們應該利用工具去找到錯誤的地方,然后快速準確的定位到錯誤地方,及其錯誤原因,***進行改進。
其實 iOS 控制臺提供這種機制,如果你選擇 debug 模式,在程序 crash 之后,在控制臺輸入 bt,就可以顯示 crash 堆棧:
- Program received signal: “EXC_BAD_ACCESS”.
 - warning: Unable to read symbols for /Developer/ios4.2.1/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1
 - (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
 - (gdb) bt
 - #0 0x33a06464 in objc_msgSend ()
 - #1 0x3139de2e in -[UIImageView setImage:] ()
 - #2 0x00009ecc in -[RoundMenuView touchesEnded:withEvent:] (self=0x29e140, _cmd=0x316b1a7b,
 - touches=0x2e1050, event=0x2424f0) at /Users/wangjun/workspace/iphone/Classes/RoundMenuView.m:130
 - #3 0x313b1354 in -[UIWindow _sendTouchesForEvent:] ()
 - #4 0x313b0cce in -[UIWindow sendEvent:] ()
 - #5 0x3139bfc6 in -[UIApplication sendEvent:] ()
 - #6 0x3139b906 in _UIApplicationHandleEvent ()
 - #7 0x31eecf02 in PurpleEventCallback ()
 - #8 0x304236fe in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
 - #9 0x304236c2 in __CFRunLoopDoSource1 ()
 - #10 0x30415f7c in __CFRunLoopRun ()
 - #11 0x30415c86 in CFRunLoopRunSpecific ()
 - #12 0x30415b8e in CFRunLoopRunInMode ()
 - #13 0x31eec4aa in GSEventRunModal ()
 - #14 0x31eec556 in GSEventRun ()
 - #15 0x313cf328 in -[UIApplication _run] ()
 - #16 0x313cce92 in UIApplicationMain ()
 - #17 0x00002da2 in main (argc=1, argv=0x2fdff44c) at /Users/wangjun/workspace/iphone/main.m:19
 - kill
 - quit
 
利用堆棧信息,就可以準確的定位到錯誤地方。
利用 gdb 命令查看全局變量值
在consol控制臺中,輸入print 變量名,就可以查看其值。
小結:了解IOS控制臺Consol的內容介紹完了,希望通過本文的介紹對你有所幫助!
















 
 
 
 
 
 
 