使用Xcode和LLDB进行高级调试

1、WWDC2018

1.1 Advanced Debugging with Xcode and LLDB link

Discover advanced techniques, and tips and tricks for enhancing your Xcode debugging workflows. Learn how to take advantage of LLDB and custom breakpoints for more powerful debugging. Get the most out of Xcode's view debugging tools to solve UI issues in your app more efficiently.

1.2 视频介绍的内容

  • 每次启动app再到响应的测试业务需要经过很多个步骤,使用LLDB调试可以减少这个时间花费
  • 这个步骤是可以直接拖动跳过的
thread jump
#跳过响应的执行行数
thread jump --by 2
#跳过之后可以执行预期需要执行的代码
expression [self.view setBackgroudColor:[UIColor redColor]]
  • 介绍了LLDB的常用指令
    (lldb) p & po
    (lldb) expression & e
    (lldb) frame variable 
    
  • 介绍了LLDB 执行 Python,快捷LLDB脚本集合Chisel
  • 介绍了Xcode来调试UI界面,直接页面操作copy响应视图或者约束
Debug View Hierarchy


2、Chisel功能使用

2.1 chisel集成

#1.安装
brew update
brew install chisel
#这里如果出现错误按照提示解决
#Cannot brew update or upgrade: Error: homebrew-cask is a shallow clone
#https://github.com/Homebrew/brew/issues/9420

#2.根目录创建llbdinit文件
touch .lldbinit 
open .lldbinit 

#3.集成Chisel python脚本集合
command script import /usr/local/opt/chisel/libexec/fbchisellldb.py

#4.重启xcode,在Xcode输入pviews查看视图结构 | help查看指令

2.2 脚本常用指令

There are many commands; here's a few: (Compatibility with iOS/Mac indicated at right)

Command Description iOS OS X
pviews Print the recursive view description for the key window. Yes Yes
pvc Print the recursive view controller description for the key window. Yes No
visualize Open a UIImage, CGImageRef, UIView, CALayer, NSData (of an image), UIColor, CIColor, or CGColorRef in Preview.app on your Mac. Yes No
fv Find a view in the hierarchy whose class name matches the provided regex. Yes No
fvc Find a view controller in the hierarchy whose class name matches the provided regex. Yes No
show/hide Show or hide the given view or layer. You don't even have to continue the process to see the changes! Yes Yes
mask/unmask Overlay a view or layer with a transparent rectangle to visualize where it is. Yes No
border/unborder Add a border to a view or layer to visualize where it is. Yes Yes
caflush Flush the render server (equivalent to a "repaint" if no animations are in-flight). Yes Yes
bmessage Set a symbolic breakpoint on the method of a class or the method of an instance without worrying which class in the hierarchy actually implements the method. Yes Yes
wivar Set a watchpoint on an instance variable of an object. Yes Yes
presponder Print the responder chain starting from the given object. Yes Yes

更多指令介绍:Wiki

你可能感兴趣的:(使用Xcode和LLDB进行高级调试)