打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Xcode调试技巧2
Xcode从默认使用LLDB后,有很多实用的调试技巧,这里简单介绍一下。
输出被调用的方法/函数
Log the called method/func1NSLog(@"%s", __PRETTY_FUNCTION__);
监测任意的异常
Add ALL EXCEPTION breakpoint
objc_exception_throw(Add Symbolic Exception)
为任意方法添加断点
以UIView的setFrame方法为例:启动App,挂上Debugger,在任意时刻暂停App,在lldb中输入
Set breakpoint1(lldb) breakpoint set -n "-[UIView setFrame:]"
Sound Breakpoint
添加断点,设置action为sound,然后勾选Automatically continue after evaluating。可以简单地用以确认某些方法是否被调用了。
输出所有线程的backtrace
命中断点后,在lldb中输入:
Print Backtrace1(lldb) bt all
输出View结构
任意时刻暂停App,在lldb中输入:
Print View Hierachy1(lldb) po [[[[UIApplication sharedApplication] delegate] window] recursiveDescription]
输出NSData
Debugger中,选中NSData->View Memory,会看到一些无法阅读的数据; 在lldb中,输入:
Print NSData object to get address1(lldb) po yourDataObject
会得到yourDataObject的地址,用该地址替换掉Memory Viewer中的地址,会自动使用合适的encoding。
Instruments Flags
这在调试多线程应用时格外有用,因为很难保证固定的执行顺序。使用这个特性,需要添加DTPerfomanceSession.framework到Xcode project中。
下面的代码片段,将在使用Instruments时,添加一个flag:
Use DTSendSignalFlag to set flags in Instruemnts123#import <DTPerformanceSession/DTSignalFlag.h> // ...DTSendSignalFlag("com.invasivecode.mytracepoints.app.point", DT_POINT_SIGNAL, TRUE);
你也可以在Instruments中显示开始和结束标志:
Use DTSentSignalFlag to set Start and End Flags123456789#import <DTPerformanceSession/DTSignalFlag.h> // ...// Put this line at the begginingDTSendSignalFlag("com.invasivecode.mytracepoints.app.start", DT_START_SIGNAL, TRUE);// ... more code here// put this at the endDTSendSignalFlag("com.invasivecode.mytracepoints.app.end", DT_END_SIGNAL, TRUE);
Reference:
Presentation by Mike Hay at CocoaHeads
Flags: very useful when debugging with instruments
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
逆向破解4
Xcode中断点的威力
LLDB 调试
Xcode LLDB Debug教程
instruments 教程
[IOS]instruments命令行启动
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服