iOS_LLDB
6640 ワード
LLVMはモジュール化され再利用可能なコンパイラとツールチェーン技術の集合であり、創始者はChris Lattnerであり、Swiftの親LLDBもLLVMのサブプロジェクトであり、LLVMが提供するライブラリとClangに基づいて構築された優れたローカルデバッガである.
端末にLLDBデバッガを使用するには、以下の内容を知る必要がある.デバッグ の準備のためのプログラムのロード実行プログラムをLLDB にバインドするブレークポイントおよび観察ポイント を設定する.
mainへmファイルの12行にブレークポイントを設定
ブレークポイントの補足として観察ポイントを設定し、LLDBはプログラムの実行を中断せずにいくつかの変数を監視するために観察ポイントをサポートします.たとえば、globalという変数の書き込み操作をモニタし、(global==5)が真の場合にモニタを停止するには、次のコマンドを使用します.制御プログラムの実行 イニシエータデバッグされたプログラムで をナビゲートする.ステータスと値をチェックする変数 スレッドのステータスの表示
呼び出しスタックのステータスの表示代替コード を実行する.
Expressionコマンドは、デバッガの値だけでなく、プログラムの実際の値も変更します.
XcodeでLLDBデバッガを使用するのは本質的にコマンドラインでのデバッガと同じである(XcodeはGUI、グラフィック操作インタフェースにすぎない)、以上の手順はまったく同じであり、関連するコマンドはアップルの公式ドキュメントを参照することができる.
helpコマンドは、使用可能なコマンドのリストをリストできます.
ここでは、一般的なコマンドの使い方を説明します.
1.print命令 printコマンドは、オブジェクトのタイプと関連属性を印刷する. printコマンドの別名はprin,pri,p, である. poコマンドNSObjectから継承するオブジェクトについては、print関数と同様にdescriptionの内容が印刷され、structについては が印刷されます.
Swiftでの印刷
OCでの印刷
2.印刷ビューの階層
OC
Swift
3.印刷ビューコントローラの階層
OC
Swift
4.出力のフォーマット
5.expressionコマンド
expressionの略記にはexp,eがあります.新しい変数をexpressionで宣言したり、既存の変数の値を変更したりできます.eが宣言した変数は
6.イメージコマンド
イメージコマンドは、スタックアドレスに対応するコード位置を探すために使用できます.
以上の情報から、問題が
問題は30行です
参考GDBとLLDB LLDBデバッガ使用概要LLDBの基本コマンド使用(Swift)
コマンドラインでのデバッガ
端末にLLDBデバッガを使用するには、以下の内容を知る必要がある.
$ lldb /Projects/Sketch/build/Debug/Sketch.app
Current executable set to '/Projects/Sketch/build/Debug/Sketch.app' (x86_64).
mainへmファイルの12行にブレークポイントを設定
(lldb) breakpoint set --file main.m --line 12
ブレークポイントの補足として観察ポイントを設定し、LLDBはプログラムの実行を中断せずにいくつかの変数を監視するために観察ポイントをサポートします.たとえば、globalという変数の書き込み操作をモニタし、(global==5)が真の場合にモニタを停止するには、次のコマンドを使用します.
(lldb) watch set var global
Watchpoint created: Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w
declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12'
(lldb) watch modify -c '(global==5)'
(lldb) watch list
(lldb) process launch
(lldb) run
(lldb) r
(lldb) thread continue
Resuming thread 0x2c03 in process 46915
Resuming process 46915
(lldb) thread list
呼び出しスタックのステータスの表示
(lldb) frame variable self
(SKTGraphicView *) self = 0x0000000100208b40
Expressionコマンドは、デバッガの値だけでなく、プログラムの実際の値も変更します.
(lldb) exp a = 10
(NSInteger) $0 = 10
(lldb) exp b = 100
(NSInteger) $1 = 100
2015-01-25 14:00:41.313 test[18064:71466] a + b = 110, abc
XcodeでLLDBデバッガを使用するのは本質的にコマンドラインでのデバッガと同じである(XcodeはGUI、グラフィック操作インタフェースにすぎない)、以上の手順はまったく同じであり、関連するコマンドはアップルの公式ドキュメントを参照することができる.
Xcodeでのデバッグ
helpコマンドは、使用可能なコマンドのリストをリストできます.
(lldb) help
ここでは、一般的なコマンドの使い方を説明します.
1.print命令
Swiftでの印刷
(lldb) print a
(Int) $R1 = 10
(lldb) print p
(LCCustomTools_Swift.Person) $R2 = (name = "lucy", age = 12)
(lldb) prin a
(Int) $R3 = 10
(lldb) pri a
(Int) $R4 = 10
(lldb) p a
(Int) $R5 = 10
//
(lldb) po p
▿ Person
- name : "lucy"
- age : 12
// class
(lldb) po p2
(lldb)
OCでの印刷
(lldb) p a
(int) $0 = 10
(lldb) p person
(Person *) $1 = 0x0000608000010780
(lldb) po person
2.印刷ビューの階層
OC
(lldb) po [self.view recursiveDescription]
Swift
(lldb) po view. recursiveDescription
>
| >
| >
| >
| | >
| | >
| | | <_uilabelcontentlayer:> (layer)
3.印刷ビューコントローラの階層
OC
(lldb) po [UIWindow valueForKeyPath:@"keyWindow.rootViewController._printHierarchy"]
Swift
(lldb) po UIWindow.valueForKeyPath("keyWindow.rootViewController._printHierarchy")
, state: appeared, view:
| , state: appeared, view:
| , state: disappeared, view: not in the window
4.出力のフォーマット
// 16
(lldb) p/x p2.age
(Int) $R2 = 0x000000000000000c
// 10
(lldb) p/d p2.age
(Int) $R3 = 12
// 8
(lldb) p/o p2.age
(Int) $R4 = 014
(lldb) p/x 0x7fcf83807a00
(Int) $R5 = 0x00007fcf83807a00
5.expressionコマンド
expressionの略記にはexp,eがあります.新しい変数をexpressionで宣言したり、既存の変数の値を変更したりできます.eが宣言した変数は
$
で始まるのを見ました.私たちも$
記号を付ける必要があります.(lldb) e let $arr = ["a", "b", "c"]
(lldb) p $arr
([String]) $R0 = 3 values {
[0] = "a"
[1] = "b"
[2] = "c"
}
(lldb) po $arr[0]
"a"
6.イメージコマンド
イメージコマンドは、スタックアドレスに対応するコード位置を探すために使用できます.
NSArray *arr = @[@"a", @"b"];
NSLog(@"%@", arr[2]);
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndexedSubscript:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x000000011045d12b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010faf1f41 objc_exception_throw + 48
2 CoreFoundation 0x000000011049d0cc _CFThrowFormattedException + 194
3 CoreFoundation 0x0000000110510890 +[__NSArrayI allocWithZone:] + 0
4 LCCustomTools_OC 0x000000010f1cf878 -[AppDelegate application:didFinishLaunchingWithOptions:] + 184
5 UIKit 0x0000000110fe5bca -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299
6 UIKit 0x0000000110fe7648 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4113
7 UIKit 0x0000000110fecaeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
...
以上の情報から、問題が
[AppDelegate application:didFinishLaunchingWithOptions:]
であることが分かるが、具体的にどの行にあるかは不明である.次のコマンドでエラーの場所を見つけます.(lldb) image lookup --address 0x000000010f1cf878
Address: LCCustomTools_OC[0x0000000100009878] (LCCustomTools_OC.__TEXT.__text + 32824)
Summary: LCCustomTools_OC`-[AppDelegate application:didFinishLaunchingWithOptions:] + 184 at AppDelegate.m:30
問題は30行です
参考GDBとLLDB LLDBデバッガ使用概要LLDBの基本コマンド使用(Swift)