今天我要写的是 LLDB 的高档调试特性。我称它为高档是由于我自己很长时间都不知道它。它答应您增加一个符号断点,该断点将在特定点停止履行,以便您能够回溯并开始查询触发此办法调用的方位。

假如上面的介绍没让你明白,让我用一个例子解释一下。假设在您的代码中的某个当地,调用了一个封闭 UIViewController 的办法 dismissViewController。现在你的代码库中或许有数百个dismissViewController 办法。可是你怎样知道代码的哪一部分实践调用了这个dismissViewController办法呢?这个问题的答案是增加符号断点。

一旦你在dismissViewController 办法处增加一个符号断点进行中止,程序履行将在它处停止,并在仓库跟踪中回来将让你找到导致controller 被dismiss的原因。

ios调试技巧(3 )设置符号断点

ios调试技巧(3 )设置符号断点

参阅上面的截图,咱们的程序流程已经在dismissViewController的调用处中止。假如咱们追溯它,咱们知道类 Sample 中的 viewDidAppear 办法担任封闭这个视图控制器。

让咱们看一下能够在程序履行期间增加的不同符号断点的示例,

1.给目标特点值设置值时的符号断点

例如,您有一个 UILabel 或 UITextView 目标,并且您想知道某些特点(例如 text、numberOfLines 或 translatesAutoresizingMaskIntoConstraints)分配给它们的方位。您能够单击 Breakpoint Navigator 并单击底部的 + 符号,然后挑选 Symbolic Breakpoint 作为选项。

ios调试技巧(3 )设置符号断点

ios调试技巧(3 )设置符号断点
ios调试技巧(3 )设置符号断点

ios调试技巧(3 )设置符号断点

现在,依据您想要break at 的condition,您能够在“符号”字段周围增加以下值

ios调试技巧(3 )设置符号断点

ios调试技巧(3 )设置符号断点

现在,您或许会这样问, 这关于简略变量的放一个断点很好处理。可是,当特点名称是 isScrollEnabled 或 isEditable 呢?

走运的是,它与咱们之前所做的十分相似。您需求做的便是去掉前缀 is,然后和之前相同的处理逻辑。

ios调试技巧(3 )设置符号断点

ios调试技巧(3 )设置符号断点

2. Symbolic breakpoint when UIViewController is presented

当项目中的任意方位预备present视图控制器时你想断点程序,您能够经过将以下符号增加到符号断点来完成


-[UIViewController presentViewController:animated:completion:]
  1. Symbolic breakpoint when UIViewController is dismissed

When UIViewController is dismissed, it can be caught by adding the following symbol

-[UIViewController dismissViewControllerAnimated:completion:]

  1. Symbolic breakpoint when UIViewController is pushed on the navigation stack

相似的符号当 UIViewController instance 被push在导航控制器


-[UINavigationController pushViewController:animated:]
  1. Symbolic breakpoint when you UIViewController is popped from the navigation stack

And when current UIViewController instance is popped from the navigation stack


-[UINavigationController popViewControllerAnimated:]
  1. Symbolic breakpoint when UIViewController’s lifecycle methods are called

This is a one-off trick to catch execution of any of the lifecycle methods associated with UIViewController such as viewDidLoad, viewDidAppear, viewWillAppear and so on. For example, you can stop the execution when the viewDidLoad method gets called using the following symbol,


-[UIViewController viewDidLoad]

##符号断点使用需求留意的点:

1.符号断点和一般断点的最大区别是:假如你想断点的当地是体系的framework或许第三方的你没办法拿到源码的framework情况,你都需求符号断点,由于一般断点你有必要到 .m文件中去才行

2.特别需求的符号断点的写法:

关于 -[UINavigationController pushViewController:animated:] 来说你能够有两种写法: a. 就按照上面的这种写法写,可是需求留意的留意点是 – 和 [ 之间不能留空格,不然断点无效。类名UINavigationController 和pushViewController:animated: 之间有必要加空格

假如办法中有参数,比方说 pushViewController:, 特别需求留意的是 pushViewController: 后边要紧跟着animated: , “`:““后边不能加空格。

b.还能够直接 写 “` pushViewController:animated: ““会将所有有这个符号的类都加上断点

3.- [类名 办法名] ,这个办法有必要要自己完成的才行,假如是继承过来的,断点无效。比方说你设置了一个 LWZTestLabel 办法,可是你使用 -[LWZTestLabel setHidden]办法,由于这个办法是UIView 的办法,所以你这样设置符号断点并没效果。

4.断点的条件表达式Condition如何书写?

i > 5000

i == 99

(BOOL)[item isEqualToString:@”three”],前面的(BOOL)是有必要的,不然console会提示类型不符号,导致条件不能收效。

ios调试技巧(3 )设置符号断点

  1. objc_msgSend(id self, SEL selector, parmat1, parmat2)

所以不论在哪个办法停留咱们都能够拿到获取 arg1(便是当时办法的调用者self),arg1 (便是当时办法的调用者 self), arg2 便是selector,能够依据这些参数做一些条件判断或许输出。