Skip to content
戴铭 edited this page Feb 28, 2015 · 1 revision

断点和调试器交互

help命令

  • help 列出所有命令
  • help 列出某个命令更多细节,例如help print

print

  • print 打印需要查看的变量,例如print totalCount
  • print 还能使用简写prin, pri, p
  • po(print object)可以打印对象的description方法的结果
  • 打印不同格式可以用p/x number打印十六进制,p/t number打印二进制,p/c char打印字符。这里是完整清单https://sourceware.org/gdb/onlinedocs/gdb/Output-Formats.html

expression

  • expression 可以改变一个值,例如expression s
  • expression可以使用e来代替
  • e -p — dataArray 也可以打印对象的description方法的结果,等同于po

流程控制

  • continue会取消暂停,继续执行下去到达下一个断电,LLDB中使用process continue,别名continue,或者使用缩写c
  • step over会执行当前这个函数,然后继续。LLDB中使用thread step-over,next或者缩写n
  • step into指跳进一个函数调试。LLDB中使用thread step in,step或者s
  • step out会继续执行到下一个返回语句,然后再次停止
  • thread return会在当前断点处直接返回出函数,函数剩余部分不会被执行。LLDB中使用thread return NO

断点管理

  • breakpoint list可以看到所有断点,简写br li
  • breakpoint set可以创建断点,缩写br

在LLDB执行C/Objective-C/C++/Swift

  • 除了创建函数,类,block等其它的都可以做到
  • 使用e进行操作,p进行打印显示结果

在调试器中直接更行UI

(lldb) e id $myView = (id)0x7f82b1d01fd0
(lldb) e (void)[$myView setBackgroundColor:[UIColor blueColor]]
(lldb) e (void)[CATransaction flush]

查找Button的target

查看按钮按下后谁会接收到按钮发出的action

(lldb) po [$myButton allTargets]
{(
<MagicEventListener: 0x7fb58bd2e240>
)}
(lldb) po [$myButton actionsForTarget:(id)0x7fb58bd2e240 forControlEvent:0]
<__NSArrayM 0x7fb58bd2aa40>(
_handleTap:
)

观察实例变量变化

想监视vMain变量什么时候被重写了,监视这个地址什么时候被写入

(lldb) p (ptrdiff_t)ivar_getOffset((struct Ivar *)class_getInstanceVariable([MyView class], "vMain"))
(ptrdiff_t) $0 = 8
(lldb) watchpoint set expression -- (int *)$myView + 8
Watchpoint created: Watchpoint 3: addr = 0x7fa554231340 size = 8 state = enabled type = w
new value: 0x0000000000000000
Clone this wiki locally