轉(zhuǎn)載自http://supermao.cn/duan-dian-shen-ru-liao-jie/
轉(zhuǎn)載自http://supermao.cn/duan-dian-shen-ru-liao-jie/
轉(zhuǎn)載自http://supermao.cn/duan-dian-shen-ru-liao-jie/
編碼不能沒調(diào)試,調(diào)試不能沒斷點(diǎn)(Break Point)。XCode的斷點(diǎn)功能也是越來越強(qiáng)大。
基本斷點(diǎn)
編輯斷點(diǎn)
斷點(diǎn)是可以編輯的。
斷點(diǎn)有下面幾個(gè)屬性可以設(shè)置:
Condition
Ignore
Action
Options
Condition
這里可以輸入條件表達(dá)式,滿足條件的時(shí)候斷點(diǎn)就會(huì)生效。例如上面輸入a == 50
。這個(gè)是非常有用的設(shè)置,特別在循環(huán)體內(nèi)調(diào)試的時(shí)候,用著真的是爽。
Ingore
在這里可以設(shè)置忽略斷點(diǎn)次數(shù)。
Action
Action是這里最復(fù)雜的,最強(qiáng)大的功能了。Action有6中類型。如下圖
AppleScript
Capture GPU Frame
Debugger Command
Log Message
Shell Command
Sound
常用的就是Log Message和Debugger Command
Log Message
會(huì)打印斷點(diǎn)的名字,%H
會(huì)打印斷點(diǎn)的調(diào)用次數(shù),@@
中間可以輸入表達(dá)式。 上面的設(shè)置在控制臺(tái)的輸出如下:
...-application:didFinishLaunchingWithOptions: 92 202015-07-28 22:19:21.905 Test[981:38016] 91 -application:didFinishLaunchingWithOptions: 93 20-application:didFinishLaunchingWithOptions: 94 20-application:didFinishLaunchingWithOptions: 95 202015-07-28 22:19:21.913 Test[981:38016] 92 2015-07-28 22:19:21.921 Test[981:38016] 93 2015-07-28 22:19:21.929 Test[981:38016] 94 -application:didFinishLaunchingWithOptions: 96 202015-07-28 22:19:21.937 Test[981:38016] 95 -application:didFinishLaunchingWithOptions: 97 202015-07-28 22:19:21.944 Test[981:38016] 96 -application:didFinishLaunchingWithOptions: 98 202015-07-28 22:19:21.952 Test[981:38016] 97 -application:didFinishLaunchingWithOptions: 99 202015-07-28 22:19:21.959 Test[981:38016] 98 -application:didFinishLaunchingWithOptions: 100 202015-07-28 22:19:21.967 Test[981:38016] 99
Debugger Command
這里可以輸入調(diào)試命令,也就是po
(打印對(duì)象信息),bt
(打印函數(shù)棧),expression
(表達(dá)式)這些調(diào)試命令。看圖就明白了:
<UIApplication: 0x7fc92360b1d0>* thread #1: tid = 0xb7db, 0x0000000101d0eb11 Test
-[AppDelegate application:didFinishLaunchingWithOptions:](self=0x00007fc923400570, _cmd=0x00000001033f3123, application=0x00007fc92360b1d0, launchOptions=0x0000000000000000) + 97 at AppDelegate.m:20, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 * frame #0: 0x0000000101d0eb11 Test
-[AppDelegate application:didFinishLaunchingWithOptions:](self=0x00007fc923400570, _cmd=0x00000001033f3123, application=0x00007fc92360b1d0, launchOptions=0x0000000000000000) + 97 at AppDelegate.m:20 frame #1: 0x0000000102c0d748 UIKit-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 240 frame #2: 0x0000000102c0e357 UIKit
-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2540 frame #3: 0x0000000102c1119e UIKit-[UIApplication _runWithMainScene:transitionContext:completion:] + 1349 frame #4: 0x0000000102c10095 UIKit
-[UIApplication workspaceDidEndTransaction:] + 179 frame #5: 0x0000000107d3c5e5 FrontBoardServices__31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21 frame #6: 0x00000001024da41c CoreFoundation
CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 frame #7: 0x00000001024d0165 CoreFoundation__CFRunLoopDoBlocks + 341 frame #8: 0x00000001024cff25 CoreFoundation
__CFRunLoopRun + 2389 frame #9: 0x00000001024cf366 CoreFoundationCFRunLoopRunSpecific + 470 frame #10: 0x0000000102c0fb02 UIKit
-[UIApplication _run] + 413 frame #11: 0x0000000102c128c0 UIKitUIApplicationMain + 1282 frame #12: 0x0000000101d0edbf Test
main(argc=1, argv=0x00007fff5def13a8) + 111 at main.m:14 frame #13: 0x0000000104dbd145 libdyld.dylibstart + 1 frame #14: 0x0000000104dbd145 libdyld.dylib
start + 1(int) $2 = 982015-07-28 22:36:54.654 Test[1150:47067] 98 2015-07-28 22:36:54.670 Test[1150:47067] 99
Options
勾選Automatically continue after evaluating actions之后程序會(huì)在斷點(diǎn)產(chǎn)生后繼續(xù)運(yùn)行。這個(gè)屬性是相當(dāng)有用的,可以輸入調(diào)試信息至于不暫停程序。
出了上面的基本斷點(diǎn)外,XCode還提供了下面四種斷點(diǎn),需要點(diǎn)擊斷點(diǎn)面板左下角的+
號(hào)添加。
Exception Breakpoint
OpenGL ES Error Breakpoint
Symbolic Breakpoint
Test Failure Breakpoint
Exception Breakpoint
OpenGL ES Error Breakpoint
這個(gè)主要是OpenGL ES的斷點(diǎn)調(diào)試,這個(gè)個(gè)人沒用到過。
Symbolic Breakpoint
比普通斷點(diǎn)多了兩個(gè)屬性Symbol
和Module
。
Symbol
Symbol的內(nèi)容,可以有如下幾種: 1. 方法名稱:會(huì)對(duì)所有具有此方法名稱的類方法生效。例如 initWithFrame: 。 2. 特定類的方法:OC類和C++類都適用,例如 ,[UIView initWithFrame:]或者 Shap::draw()。 3. 函數(shù)名稱。例如普通C函數(shù)。
通過設(shè)置Symbol來調(diào)試,好用根本停不下來,想怎么斷點(diǎn)就怎么斷點(diǎn)。
Test Failure Breakpoint
這個(gè)類型的斷點(diǎn)會(huì)在test assertion 失敗的時(shí)候暫停程序的執(zhí)行。