Xcode的控制台调试命令

XCode4.0以后,编译器换成了LLVM 编译器 2.0
与以前相比,更加强大:

1.LLVM 编译器是下一带开源的编译技术.完全支持C, Objective-C, 和 C++.

2.LLVM 速度比 GCC快两倍,建立的程序也会运行的更快. 因为它更好的利用现代的芯片的结构.

3.LLVM和Xcode 4完全的整合在一起.包括关键字高亮,代码完整性等全都是由LLVM语法分析器来分析的. 这样可以在编辑的时候就可以很好的了解你的代码.


编译器进化之后,控制台调试命令前缀,也由原来的gdb更改成了lldb,所以当你看到控制台没有gdb而出现lldb的时候,不用惊慌,因为我们以前常用的调试命令依然可以使用:

使用前提:

1.既然是调试命令,理所当然的,程序模式应该选择Debug模式。

2.在Debug模式下,如果你的程序在运行中崩溃(Crash)掉,那么恭喜你,使用lldb调试的机会来了。

符合以上两个条件之后,控制台(即日志输出窗口All Output)会自动打出一个(lldb)命令,你在其后输入bt,回车。

恭喜你,这时Xcode会自动输出最后的一次调用堆栈。如下:

[cpp] view plaincopyprint?
1. *thread#1: tid = 0x1f03, 0x0132edee CoreFoundation___forwarding___ + 206, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)</span></span>
2. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #0: 0x0132edee CoreFoundation
forwarding + 206

3. frame #1: 0x0132ecb2 CoreFoundation_CF_forwarding_prep_0 + 50</span>
4. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #2: 0x00002e60 testMVC
-[ViewCtrl2 touchesBegan:withEvent:] + 128 at ViewCtrl2.m:40

5. frame #3: 0x013c9e99 CoreFoundation-[NSObject performSelector:withObject:withObject:] + 73</span>
6. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #4: 0x000ffc49 UIKit
forwardTouchMethod + 268

7. frame #5: 0x000ffb38 UIKit-[UIResponder touchesBegan:withEvent:] + 30</span>
8. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #6: 0x0003a2cf UIKit
-[UIWindow _sendTouchesForEvent:] + 272

9. frame #7: 0x0003a5e6 UIKit-[UIWindow sendEvent:] + 273</span>
10. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #8: 0x00020dc4 UIKit
-[UIApplication sendEvent:] + 464

11. frame #9: 0x00014634 UIKit_UIApplicationHandleEvent + 8196</span>
12. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #10: 0x012b2ef5 GraphicsServices
PurpleEventCallback + 1274

13. frame #11: 0x0139c195 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53</span>
14. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #12: 0x01300ff2 CoreFoundation
__CFRunLoopDoSource1 + 146

15. frame #13: 0x012ff8da CoreFoundation__CFRunLoopRun + 2218</span>
16. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #14: 0x012fed84 CoreFoundation
CFRunLoopRunSpecific + 212

17. frame #15: 0x012fec9b CoreFoundationCFRunLoopRunInMode + 123</span>
18. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #16: 0x012b17d8 GraphicsServices
GSEventRunModal + 190

19. frame #17: 0x012b188a GraphicsServicesGSEventRun + 103</span>
20. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #18: 0x00012626 UIKit
UIApplicationMain + 1163

21. frame #19: 0x000026fa testMVCmain + 170 at main.m:16</span>
22. <span style="margin: 0; padding: 0; border: none; color: rgba(0, 0, 0, 1); background-color: inherit">frame #20: 0x00002645 testMVC
start + 53



当然还有其他的命令(和gdb命令通用):

[cpp] view plaincopyprint?
1. 命令 解释
2. breakNUM 在指定的行上设置断点。
3. bt 显示所有的调用栈帧。该命令可用来显示函数的调用顺序。
4. clear 删除设置在特定源文件、特定行上的断点。其用法为:clear FILENAME:NUM。
5. continue继续执行正在调试的程序。该命令用在程序由于处理信号或断点而导致停止运行时。
6. display EXPR 每次程序停止后显示表达式的值。表达式由程序定义的变量组成。
7. fileFILE装载指定的可执行文件进行调试。
8. help NAME 显示指定命令的帮助信息。
9. infobreak显示当前断点清单,包括到达断点处的次数等。
10. info files 显示被调试文件的详细信息。
11. info func 显示所有的函数名称。
12. info local 显示当函数中的局部变量信息。
13. info prog 显示被调试程序的执行状态。
14. info var 显示所有的全局和静态变量名称。
15. kill 终止正被调试的程序。
16. list 显示源代码段。
17. make 在不退出 gdb 的情况下运行 make 工具。
18. next 在不单步执行进入其他函数的情况下,向前执行一行源代码。
19. print EXPR 显示表达式 EXPR 的值。
20. print-object 打印一个对象
21. print (int) name 打印一个类型
22. print-object [artist description] 调用一个函数
23. set artist = @"test"设置变量值
24. whatis 查看变理的数据类型





使用lldb调试工具,结合上文解决EXC_BAD_ACCESS错误的一种方法--NSZombieEnabled一起使用,实在是查找crash的一大利器啊,很是方便!

欢迎喜欢交流和热心的iphone开发朋友加入qq群参与讨论:186739796,验证码:csdn。

原文链接: https://www.cnblogs.com/zsw-1993/p/4879990.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/93977

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月10日 上午2:24
下一篇 2023年2月10日 上午2:25

相关推荐