WEB开发网
开发学院手机开发iPhone 开发 IOSXcode调试攻略 阅读

IOSXcode调试攻略

 2012-10-23 17:35:48 来源:WEB开发网   
核心提示: 1. Xcode内置GDB,可以使用GDB调试,调试命令:1.1 po 命令:为 print object 的缩写,IOSXcode调试攻略,显示对象的文本描述(lldb) po [$eax class]:输出异常对象的地址
(lldb) po [$eax name]:输出这个异常的名字
(l

 1. Xcode内置GDB,可以使用GDB调试,调试命令:

1.1 po 命令:为 print object 的缩写,显示对象的文本描述

(lldb) po [$eax class]:输出异常对象的地址


(lldb) po [$eax name]:输出这个异常的名字


(lldb) po [$eax reason]:这个将会输出错误消息:


(lldb) “po $eax”:对这个对象调用“description”方法和打印出来

“$eax”是cup的一个寄存器。在一个异常的情况下,这个寄存器将会包含一个异常对象的指针。注意:$eax只会在模拟器里面工作,假如你在设备上调试,你将需要使用”$r0″寄存器

1.2 print 命令:有点类似于格式化输出,可以输出对象的不同信息

比如:print (char*)[[dic description] cString]、(lldb) print (int)[label retainCount]

1.3 info 命令:我们可以查看内存地址所在信息

1.4 info line *内存地址:可以获取内存地址所在的代码行相关信息

1.5 show 命令:显示 GDB 相关的信息。如:show version 显示GDB版本信息

1.6 bt: 显示当前进程的函数调用栈的情况;"up num":查看调用的详细信息;down:返回栈列表;l:显示详细代码信息;p:输出数值。

2. 添加全局断点(Add Exception BreakPoint):

2.1 添加步骤:

1. In the bottom-left corner of the breakpoints navigator, click the Add button.
2. Choose Add Exception Breakpoint.
3. Choose the type of exception from the Exception pop-up menu.
4. Choose the phase of the exception handling process at which you want program execution to stop.
5. Click Done.

2.2 使用场景:

程序因为SIGABRT而crash,想要定位到导致crash的行。

3. 添加符号断点(Add Symbolic BreakPoint):

3.1 断点执行的时机:Symbolic breakpoints stop program execution when a specific function or method starts executing

3.2 添加步骤:

1. Steps In the bottom-left corner of the breakpoint navigator, click the Add button.

2. Choose Add Symbolic Breakpoint.
3. Enter the symbol name in the Symbol field.
4. Click Done.

3.3 使用场景:

当想让系统在某个指定条件处中断时,设置相应的断点。

比如:

objc_exception_throw:在系统抛出异常处设置断点。

-[NSException raise]:

4. 设置NSZombieEnabled、MallocStackLogging、NSAutoreleaseFreedObjectCheckEnabled、NSDebugEnabled:

4.1 设置方法:

1. Product->Edit Scheme...->Run...->EnvironmentVariables.
2. add NSZombieEnabled,set the value with YES
3. add MallocStackLogging, set the value with YES.

4. add NSAutoreleaseFreedObjectCheckEnabled, set the value with YES.

5. add NSDebugEnabled, set the value with YES.

4.2 使用场景:

主要为了解决EXC_BAD_ACCESS问题,MallocStackLogging用来启用malloc记录(使用方式 malloc_history ${App_PID} ${Object_instance_addr})。

4.3 需要注意的问题

NSZombieEnabled只能在调试的时候使用,千万不要忘记在产品发布的时候去掉,因为NSZombieEnabled不会真正去释放dealloc对象的内存。

5. 重写respondsToSelector方法

5.1 实现方式


#ifdef _FOR_DEBUG_
-(BOOL) respondsToSelector:(SEL)aSelector {
printf("SELECTOR: %s\n", [NSStringFromSelector(aSelector) UTF8String]);

1 2  下一页

Tags:IOSXcode 调试 攻略

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接