
1.动态调试
2.Xcode的动态调试原理
3.动态调试任意APP
动态调试
- 什么叫动态调试?
将程序运行起来,通过断点、打印等方式,查看参数、返回值、函数调用流程等
Xcode的动态调试原理

- 关于GCC、LLVM、GDB、LLDB
Xcode的编译器发展历程:GCC -> LLVM
Xcode的调试器发展历程:GDB -> LLDB
- debugserver一开始存放在Xcode里面
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/De
viceSupport/9.1/DeveloperDiskImage.dmg/usr/bin/debugserver
- Xcode识别到手机是会自动把debugserver安装到iPhone上
/Developer/usr/bin/debugserver
动态调试任意APP
- debugserver的权限问题
默认情况下/Developer/usr/bin/debugserver缺少一定权限,只能调试通过Xcode安装的APP, 无法调试其他APP
如果需要调试其他APP,需要对debugserver重签名,签上2个调试相关权限
权限1:get-task-allow
权限2:task_for_pid-allow
- 使用ldid命令重新签名
到处签名权限: ldid -e debugserver > debugserver.entitlements
添加上述两条权限 get-task-allow 和 task_for_pid-allow
重新签名: ldid -Sdebugserver.entitlements debugserver
- 让debugserver附加到某个APP进程
$ debugserver *: 端口号 -a 进程
- 在MAC上启动LLDB,远程连接到iPhone上的debugserver服务
启动LLDB: $ lldb
连接debugserver服务: (lldb) process connect connect://手机IP地址:debugserver服务端口
使用LLDB的c命令让程序继续运行: (lldb) c