编程难免有bug,一些隐蔽的bug往往让人比较烦恼,初学者更是如此,俺经过亲身经历,整理了一些debug的小技巧,希望对初学者有所帮助,高手拍砖也欢迎哈
1.最常用的肯定是NSLog了,可以查看各种变量在各个状态的值,而且对于程序流程的整理也很有帮助
2.单步调试,一般鼠标悬浮在变量上就可以快速查看变量的状态,俺一般看这个变量的地址,就是0x开头的,主要是看它是否为nil,nil的地址是0x0,字符串可以看具体值,而字典和数组却只显示count,即有多少个元素或键值对,如果要查看整个数组或字典的话,此时是不行的(呵呵,方法在后面)
俺主要想说的其实是后面这几点,呵呵
3.debuger在单步调试的时候会出现,三部分,俺初学的时候只用下面的单步调试,直观快捷
3-1.后来发现:有个比较快捷的方法查看数组和字典,右上角的窗口里,有Arguments和locals(俺常用),在Arguments的self或loacls里有你想查看的数组的话,选中它,右键菜单上有print description to console,可以很方便的在console里查看数组和字典的值,当然像文件夹路径这种长字符串更不在话下了
3-2.左上角的窗口以前看上去好复杂,虽然现在看还是复杂,但俺看出了点门道,特别是在interrupt的时候,报错状态下,左上角的第一行显示????,其实左上角是倒序显示的,就是说最后执行的语句是在第一句,而已经执行的是显示在下面,有的时候,???下面有一些是显示"方法的调用",即[object message],这很关键,可以找到距离报错的地点最近的地方,经过俺的实践,常常就是在那解决bug的
4.也是在报错状态,console一般会显示错误信息,常见的unregnise selector这些看多了也就熟悉了,有的时候会显示Call stack at first throw这种也是倒着看,先执行的在下面显示,定位到离错误最近的地方解决bug,如:
2010-10-16 20:14:13.633 Universiade 2011[5293:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MoreSecondViewController_ser 0x6d49bf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mytableView.' *** Call stack at first throw: ( 0 CoreFoundation 0x0264db99 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x0279d40e objc_exception_throw + 47 2 CoreFoundation 0x0264dad1 -[NSException raise] + 17 3 Foundation 0x0008a0f3 _NSSetUsingKeyValueSetter + 135 4 Foundation 0x0008a061 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285 5 UIKit 0x0050870a -[UIRuntimeOutletConnection connect] + 112 6 CoreFoundation 0x025c3d0f -[NSArray makeObjectsPerformSelector:] + 239 7 UIKit 0x00507121 -[UINib instantiateWithOwner:options:] + 1041 8 UIKit 0x00508eb5 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 9 UIKit 0x003be95f -[UIViewController _loadViewFromNibNamed:bundle:] + 70 10 UIKit 0x003bc675 -[UIViewController loadView] + 120 11 UIKit 0x003bc54f -[UIViewController view] + 56 12 UIKit 0x003ba9f4 -[UIViewController contentScrollView] + 42 13 UIKit 0x003ca7e2 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48 14 UIKit 0x003c8ea3 -[UINavigationController _layoutViewController:] + 43 15 UIKit 0x003ca067 -[UINavigationController _startTransition:fromViewController:toViewController:] + 326 16 UIKit 0x003c4ccd -[UINavigationController _startDeferredTransitionIfNeeded] + 266 17 UIKit 0x003cbd8b -[UINavigationController pushViewController:transition:forceImmediate:] + 876 18 UIKit 0x003c4b67 -[UINavigationController pushViewController:animated:] + 62 19 Universiade 2011 0x0002a82e -[MoreTableView tableView:didSelectRowAtIndexPath:] + 1050 20 UIKit 0x00385a48 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140 21 UIKit 0x0037c32e -[UITableView _userSelectRowAtIndexPath:] + 219 22 Foundation 0x0009121a __NSFireDelayedPerform + 441 23 CoreFoundation 0x0262ef73 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19 24 CoreFoundation 0x026305b4 __CFRunLoopDoTimer + 1364 25 CoreFoundation 0x0258cdd9 __CFRunLoopRun + 1817 26 CoreFoundation 0x0258c350 CFRunLoopRunSpecific + 208 27 CoreFoundation 0x0258c271 CFRunLoopRunInMode + 97 28 GraphicsServices 0x02f2c00c GSEventRunModal + 217 29 GraphicsServices 0x02f2c0d1 GSEventRun + 115 30 UIKit 0x00320af2 UIApplicationMain + 1160 31 Universiade 2011 0x00002a5c main + 102 32 Universiade 2011 0x000029ed start + 53 ) terminate called after throwing an instance of 'NSException' Program received signal: “SIGABRT”.
5.比较恼火的BAD_ACCESS,网上有个做法是设置ZomebieEnabled,确实不错,有的时候确不显示(不知道是不是人品问题..)不显示的时候用俺刚才说的debuger左上角的定位至离错误最近的地方那个方法,一般都OK了
吾生有涯,debug无涯,未完待续
相关推荐
debug欣赏debug欣赏debug欣赏debug欣赏debug欣赏
debug.logdebug.log
DebugView帮助文档 DebugView使用说明 DebugView介绍DebugView帮助文档 DebugView使用说明 DebugView介绍DebugView帮助文档 DebugView使用说明 DebugView介绍DebugView帮助文档 DebugView使用说明 DebugView介绍
debug资料.rar debug资料.rar debug资料.rar debug资料.rar debug资料.rar debug资料.rar
特别的,该方式不仅适合deepspeed命令debug,也适用torchrun命令debug,更能延伸其它命令debug模式。本文内容分为三部分,第一部分介绍如何使用vscode传递参数debug;第二部分介绍如何使用deepspeed进行debug;第三...
debug debug32 用于调试很有用的,具体用法可以先查看网上的资源,以后整理好了再上传.
DEBUG32 32位DEBUG 32位DEBUG 32位DEBUG 32位DEBUG
汇编debug调试命令汇编debug调试命令汇编debug调试命令汇编debug调试命令汇编debug调试命令
在学习汇编语言时,debug不失为练习得好工具。读者操作系统若为32位,可直接运行debug。 在64位操作系统下,想运行debug,需要两个东西:DOSBox,debug.exe。 1,下载、安装DOSBox。 2,下载debug.exe,将debug.exe...
DEBUG的使用 DEBUG的使用 DEBUG的使用
SAP ABAP DEBUG 方式总结 一、一般Debug 1、内、外部断点。外部断点功能涵盖了内部断点 2、图上方红框为一次为F5\F6\F7\F8 3、在Debug 进入内表时,可以通过右侧的工具按钮来对内表内容的增删改。 4、若DEBUG想返回...
xpdebug debug32这两个工具
Debug常用命令集 Debug 原意是杀虫子。这里是机器调试工具。虽然,现在好的软件越来越多了,但是有些,我们只需动手,用Debug就可解决,且快而好!
给64位系统的同学们提供的,汇编程序调试工具,既有debug.exe也有debug32.exe
serial debug
使用IDEA开发环境时,采用Spring Boot框架开启debug模式的流程
win7或win8运行debug,完成汇编。包含debug.exe+dosbox,使用说明和汇编简单指令。
httpdebug httpdebug httpdebug httpdebug
DEBUG命令详解 DEBUG命令详解 DEBUG命令详解 DEBUG命令详解
DEBUG命令大全.txtDEBUG命令大全.txt