Xcode5でLLDBデバッガコマンドを使ってみる

※キーウインドウ上の曖昧な制約を表示する、[UIWindow keyWindow] _autolayoutTrace]を追記
Xcodeブレークポイントでプログラムを停止している時に入力できるコマンドです。



VisualStudioのイミディエイトウインドウライクに変数の値を変えられます。
値を変更して何度もテストしたい時に便利そうです。



・参考資料
WWDC 2012 Session VideosのDebugging with LLDB (https://developer.apple.com/videos/wwdc/2012/)※英語
GDBとLLDBのコマンド対応表 (http://lldb.llvm.org/lldb-gdb.html) ※英語,公式
チュートリアル等 (http://lldb.llvm.org/tutorial.html) ※英語,公式
変数のフォーマット (http://lldb.llvm.org/varformats.html) ※英語,公式
LLDBを使ってCUIで動作させているテストケースをデバッグする。(http://akisute.com/2012/07/lldb-cui.html)


簡単なコマンド一覧表

省略形 内容 正式名
h ヘルプの表示 help
s ステップイン thread step-in
c 続きを実行(次のbreakPointまで) process continue
po 式の評価(poはオブジェクト、pは基本型も可) expression -o --
br l breakPointを一覧表示 breakpoint list
bt 現スレッドのバックトレース情報を表示 thread backtrace
b objc_msgSend objc_msgSend関数にシンボリックブレークポイントを設定 -


[使用例]

・変数cellCountの値を変更する。
p cellCount = 6


・self.view.subViewsのカウントを一時変数fooに代入
p NSUInteger $foo = (NSUInteger)[[self.view subviews] count]

・変数fooの値を表示(基本型に利用可、オブジェクトはアドレスの表示になる。)
p $foo
(int) $foo = 6


・self.viewの値を表示する。(オブジェクトのみ)
コマンド po self.view
実行結果例↓
(UIView *) $1 = 0x0e3d5c00 ; contentOffset: {0, 0}>


・self.viewの階層を再帰的に表示
コマンド po [self.view recursiveDescription]
実行結果例↓
; layer = ; contentOffset: {0, 0}>
| >
| >
| >


・カレントスレッドのバックトレースを3つまで表示
コマンド bt -c 3
実行結果例↓
thread #1: tid = 0x1f03, 0x00002ab5 Test02`-[AppDelegate application:didFinishLaunchingWithOptions:] + 85 at AppDelegate.m:16, stop reason = breakpoint 5.1
frame #0: 0x00002ab5 Test02`-[AppDelegate application:didFinishLaunchingWithOptions:] + 85 at AppDelegate.m:16
frame #1: 0x000107b7 UIKit`-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266
frame #2: 0x00010da7 UIKit`-[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1248


・キーウインドウ上の全ての曖昧な制約をプリントする
po [[UIWindow keyWindow] _autolayoutTrace]
実行例↓
- AMBIGUOUS LAYOUT

省略

- AMBIGUOUS LAYOUT
- AMBIGUOUS LAYOUT


・指定したViewのHorizontal(0)/Vertical(1)制約を表示
po [0xb9da840 constraintsAffectingLayoutForAxis:0]
実行例↓
<__NSArrayM 0xb8014f0>(
,
,
,

)