LLVM

LLDB调试和实战

2019-10-14  本文已影响0人  奔跑的鸿

LLDB

LLDB官方文档教程

(lldb) print a
(NSInteger) $0 = 20
(lldb) exp $0 = 100
(NSInteger) $9 = 100
(lldb) p a
(NSInteger) $10 = 100

接手新项目,不看代码直接锁定控制器

老生常谈的符号断点 for Xcode ,找出你想要的ViewController

-[UIViewController viewDidLoad]
thread return
thread return
po self
continue

注意千万不能勾选automatically continue,否则app会卡死,continue本身就表示遇到断点也继续执行。

报出exc_bad_access错误

实战

定位点击事件位置的几种方法

点击事件涉及几种情况:tableViewCell、collectionViewCell、UIButton、UIImageView或UIView的手势tab点击,每一种拦截方式都不同,但只要懂得锁定这几种方式的技巧,就能快速找到点击事件的代码位置。

breakpoint set --selector 方法名

表格cell点击一般有tableViewCell或collectionViewCell点击,方法名为tableView:didSelectRowAtIndexPath: 或collectionView:didSelectItemAtIndexPath:。若断点设置成功,会输出如下:

Breakpoint 1: 77 locations

以上1表示方法名称标识号,77表示成功设置了77处涉及该方法名称的断点。也可用命令 breakpoint list查看已设置的所有断点
之后点击LLDB continue execution按钮继续运行,然后点击视图便可在Xcode左边的堆栈列表中找到代码位置。如果不需要了,可以重新运行Xcode 或删除该断点:

breakpoint delete 1    【#这里1是上述方法名称的标识号】

更多用法可用命令help breakpoint set查看。

(lldb) register read
General Purpose Registers:
       rax = 0x00007fc8efc72db0
       rbx = 0x00007fc8efc72db0
       rcx = 0x00007fc8efc72db0
       rdx = 0x000000010e603878 "itemClick:"
       rdi = 0x00007fc8efc76a50
       rsi = 0x0000000111354ce4 "sendAction:to:forEvent:"
       rbp = 0x00007ffee16bb7a0
       ...
        fs = 0x0000000000000000
        gs = 0x0000000000000000

在rdx后面可看到点击事件的方法名称itemClick:,此时不要激动,我们还需要找到方法调用者,因为工程中可能存在多个同名方法。怎么操作?答案是LLDB命令po $rax,打印的便是调用者对象,如

(lldb) po $rax
<HomeNavigationGridView: 0x7fc8efc72db0; frame = (0 0; 414 193.2); layer = <CALayer: 0x604000431820>>

如此我们便可知道有[HomeNavigationGridView itemClick:],从而定位到按钮点击事件在程序中的代码位置。

(lldb) po $rax
(action=informationTap:, target=<HotInformationView 0x7fbf72c43e00>)

(lldb) po $rdx
<UITapGestureRecognizer: 0x6000001f1800; state = Ended; view = <HotInformationItem 0x7fbf72e1e970>; target= <(action=informationTap:, target=<HotInformationView 0x7fbf72c43e00>)>>

由此可知有[HotInformationView informationTap:HotInformationItem],从而定位到手势事件的代码

上一篇 下一篇

猜你喜欢

热点阅读