title

Expression 是lldb调试命令中最重要的命令

  • 1.打印内容
    expression -o – <=> po(po 是 expression -o – 的别名)
    expression ==> e
1
2
3
4
5
6
7
8
expression self.view
(UIView *) $6 = 0x00007fba7f786290

expression -o -- self.view
<UIView: 0x7fba7f786290; frame = (0 0; 568 320); autoresize = W+H; gestureRecognizers = <NSArray: 0x600182e467b0>; layer = <CALayer: 0x6180e963e520>>

po self.view
<UIView: 0x7fba7f786290; frame = (0 0; 568 320); autoresize = W+H; gestureRecognizers = <NSArray: 0x600182e467b0>; layer = <CALayer: 0x6180e963e520>>
  • 2.执行表达式
1
2
expression -- self.view.backgroundColor = [UIColor redColor];
expression -- [CATransaction flush];
结果: self.view的背景颜色被成功修改成红色    

e-- flush

breakpoint 断点

  • 1.添加断点
1
br set -n viewDidLoad

(给当前类的viewDidLoad方法增加断点)
给其他文件的viewDidLoad方法加断点 怎么做?

1
br set -f SecondViewController.m -n viewDidLoad

-f 指定文件, -n 指定方法
br-set-f-n

1
br set -r SecondViewController

-r 匹配设置断点,所有执行到 SecondViewController 相关的代码都会被打上断点
br-set-r
touchbegin

  • 2.查看断点
    br list (会显示整个工程所有的断点信息)
    可以用来查询工程有没有设断点
    包含信息:文件路径,代码行数,触发次数(hit count)
    br-list
  • 3.br disable/enable
    (取消/打开全局断点) 一般我们不需要用,xcode工具栏自带了

  • 4.br delete
    删除断点,不带参数表示删除所有断点,xcode自带了
    执行后会有个确认的操作,y/n
    br-delete

    watchpoint 监听地址

  • 1.添加断点

1
2
3
4
5
6
7
8
9
10
11
12
wa set variable _mainTable (监听当前tableview的地址变化)
Watchpoint created: Watchpoint 1: addr = 0x7f808a1118d8 size = 8 state = enabled type = w
watchpoint spec = '_mainTable'
new value: 0x0000000000000000

Watchpoint 1 hit:
old value: 0x0000000000000000
new value: 0x00007f808881b000

Watchpoint 1 hit:
old value: 0x00007f808881b000
new value: 0x0000000000000000

  • 2.disable/enble/delete
    与 breakpoint 相同

    总结:可以用来检测类中的某个成员变量是否被成功析构
    初始化 会触发一次watchpoint,析构的时候也会触发一次

wa-set

image lookup 寻址 (im loo)

  • image lookup –address
    获取某个指针地址的代码所在位置
    一般情况用不上,如果一个方法内有多个地方使用到 objectAtIndex方法,这个时候crash了 就比较有用了

    假如有一个crash堆栈如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    2017-06-05 14:49:20.091 tztHuaTaiZLMobile[80016:3110869] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
    *** First throw call stack:
    (
    0 CoreFoundation 0x000000010dfd8d4b __exceptionPreprocess + 171
    1 libobjc.A.dylib 0x000000010ca1521e objc_exception_throw + 48
    2 CoreFoundation 0x000000010df132bb -[__NSArrayI objectAtIndex:] + 155
    3 tztHuaTaiZLMobile 0x000000010a425388 -[tztHuaTaiZLMobileDelegate HTLaunchManagerWillStartLaunch] + 696
    4 tztHuaTaiZLMobile 0x000000010a0499da -[HTLaunchManager launchWithWindow:launchOptions:delegate:] + 442
    5 tztHuaTaiZLMobile 0x000000010a4234ac -[tztHuaTaiZLMobileDelegate application:didFinishLaunchingWithOptions:] + 492
    6 UIKit 0x00000001109e03c2 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290
    7 UIKit 0x00000001109e1d47 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4236
    8 UIKit 0x00000001109e80ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
    9 UIKit 0x00000001109e526d -[UIApplication workspaceDidEndTransaction:] + 188
    10 FrontBoardServices 0x0000000114cc46cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    11 FrontBoardServices 0x0000000114cc4544 -[FBSSerialQueue _performNext] + 189
    12 FrontBoardServices 0x0000000114cc48cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    13 CoreFoundation 0x000000010df7d761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14 CoreFoundation 0x000000010df6298c __CFRunLoopDoSources0 + 556
    15 CoreFoundation 0x000000010df61e76 __CFRunLoopRun + 918
    16 CoreFoundation 0x000000010df61884 CFRunLoopRunSpecific + 420
    17 UIKit 0x00000001109e3aea -[UIApplication _run] + 434
    18 UIKit 0x00000001109e9c68 UIApplicationMain + 159
    19 tztHuaTaiZLMobile 0x0000000109cb24ff main + 111
    20 libdyld.dylib 0x0000000113b0868d start + 1
    ) 0x0000000100353777 -[UIViewController view] + 29

执行命令:

1
image lookup -a 0x000000010a425388

得到结果:

1
2
Address: tztHuaTaiZLMobile[0x00000001007b0388] (tztHuaTaiZLMobile.__TEXT.__text + 8053672)  
Summary: tztHuaTaiZLMobile`-[tztHuaTaiZLMobileDelegate HTLaunchManagerWillStartLaunch] + 696 at tztHuaTaiZLMobileDelegate.m:497