Skip to content

LLDB 正则表达式断点

jiaxw32 edited this page Jan 6, 2021 · 3 revisions

设置正则表达式断点

匹配 UIImagePickerController 的所有方法

breakpoint set -r '\[UIImagePickerController .*\]$'

上述断点包括类方法与实例方法,但不括父类方法

正则表达式说明:

  1. \ 为转义字符,用于匹配一些保留的字符,如:[ ] ( ) { } . * + ? ^ $ \ |
  2. . 句号匹配除换行符的任意单个字符
  3. * 匹配>=0个重复的在*号之前的字符
  4. $ 匹配字符串结束

使用 br list 查看断点,效果如下图:

匹配父类方法

如果要包括父类方法,可以使用条件语句,如下:

br s -r '\[UIViewController .*\]$' -c '(BOOL)[(id)$arg1 isKindOfClass:[CustomVC class]]’

统计所有 +load 方法

br s -r "\+\[.+ load\]$"
  1. .匹配任意单个字符,但不匹配换行符
  2. +号匹配+号之前的字符出现 >=1 次

br list 查看结果如下所示:

(lldb) br list
Current breakpoints:
14: regex = '\+\[.+ load\]$', locations = 515, resolved = 515, hit count = 0

参考资料

Clone this wiki locally