- 浏览: 527903 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
landerson:
明显就有要求的嘛
ANDROID轻量级JSON序列化和反序列化[转] -
jimode2013:
很不错,就是需要这个方法
多个UIViewController使用addSubView,第二个 UIViewController 不响应旋转[转] -
w11h22j33:
...
[转]NSMutableArray中的自动释放对象让我郁闷了一整天 -
w11h22j33:
UILabel* label = [[UILabel a ...
Iphone开发 -
w11h22j33:
http://mobile.51cto.com/iphone- ...
获得通讯录中联系人的所有属性[转]
[Cocoa]XCode的一些调试技巧【转】
- 博客分类:
- Iphone开发
XCode 内置GDB,我们可以在命令行中使用 GDB 命令来调试我们的程序。下面将介绍一些常用的命令以及调试技巧。
po 命令:为 print object 的缩写,显示对象的文本描述(显示从对象的 description 消息获得的字符串信息)。
比如:
上图中,我使用 po 命令显示一个 NSDictionary 的内容。注意在左侧我们可以看到 dict 的一些信息:3 key/value pairs,显示该 dict 包含的数据量,而展开的信息显示 isa 层次体系(即class 和 metaclass结构关系)。我们可以右击左侧的 dict,选中“Print Description of "dict"”,则可以在控制台输出 dict 的详细信息:
- Printing description of dict:
- <CFBasicHash 0x1001149e0 [0x7fff7e27ff40]>{type = immutable dict, count = 3,
- entries =>
- 0 : <CFString 0x100002458 [0x7fff7e27ff40]>{contents = "first"} = <CFString 0x100002438 [0x7fff7e27ff40]>{contents = "one"}
- 1 : <CFString 0x100002498 [0x7fff7e27ff40]>{contents = "second"} = <CFString 0x100002478 [0x7fff7e27ff40]>{contents = "two"}
- 2 : <CFString 0x1000024d8 [0x7fff7e27ff40]>{contents = "third"} = <CFString 0x1000024b8 [0x7fff7e27ff40]>{contents = "three"}
- }
- (gdb)
print 命令:有点类似于格式化输出,可以输出对象的不同信息:
如:
- (gdb) print (char *)[[dict description] cStringUsingEncoding:4]
- $1 = 0x1001159c0 "{\n first = one;\n second = two;\n third = three;\n}"
- (gdb) print (int)[dict retainCount]
- $2 = 1
- (gdb)
注:4是 NSUTF8StringEncoding 的值。
info 命令:我们可以查看内存地址所在信息
比如 "info symbol 内存地址" 可以获取内存地址所在的 symbol 相关信息:
- (gdb) info symbol 0x00000001000017f7
- main + 343 in section LC_SEGMENT.__TEXT.__text of /Users/LuoZhaohui/Library/Developer/Xcode/DerivedData/RunTimeSystem-anzdlhiwvlbizpfureuvenvmatnp/Build/Products/Debug/RunTimeSystem
比如 "info line *内存地址" 可以获取内存地址所在的代码行相关信息:
- (gdb) info line *0x00000001000017f7
- Line 62 of "/Users/LuoZhaohui/Documents/Study/RunTimeSystem/RunTimeSystem/main.m" starts at address 0x1000017f7 <main+343> and ends at 0x10000180a <main+362>.
show 命令:显示 GDB 相关的信息。如:show version 显示GDB版本信息
- (gdb) show version
- GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011)
- Copyright 2004 Free Software Foundation, Inc.
- GDB is free software, covered by the GNU General Public License, and you are
- welcome to change it and/or distribute copies of it under certain conditions.
- Type "show copying" to see the conditions.
- There is absolutely no warranty for GDB. Type "show warranty" for details.
- This GDB was configured as "x86_64-apple-darwin".
help 命令:如果忘记某条命令的语法了,可以使用 help 命令名 来获取帮助信息。如:help info 显示 info 命令的用法。
- (gdb) help info
- Generic command for showing things about the program being debugged.
- List of info subcommands:
- info address -- Describe where symbol SYM is stored
- info all-registers -- List of all registers and their contents
- info args -- Argument variables of current stack frame
- info auxv -- Display the inferior's auxiliary vector
- info breakpoints -- Status of user-settable breakpoints
- info catch -- Exceptions that can be caught in the current stack frame
- info checkpoints -- Help
- info classes -- All Objective-C classes
- ......
- Type "help info" followed by info subcommand name for full documentation.
- Command name abbreviations are allowed if unambiguous.
- (gdb)
在系统抛出异常处设置断点
有时候我们的程序不知道跑到哪个地方就 crash 了,而 crash 又很难重现。保守的做法是在系统抛出异常之前设置断点,具体来说是在 objc_exception_throw处设置断点。设置步骤为:首先在 XCode 按 CMD + 6,进入断点管理窗口;然后点击右下方的 +,增加新的 Symbolic Breakpoint,在 Symbol 一栏输入:objc_exception_throw,然后点击 done,完成。 这样在 Debug 模式下,如果程序即将抛出异常,就能在抛出异常处中断了。比如在前面的代码中,我让 [firstObjctcrashTest]; 抛出异常。在 objc_exception_throw 处设置断点之后,程序就能在该代码处中断了,我们从而知道代码在什么地方出问题了。
发表评论
-
iOS App性能优化
2014-01-03 11:23 1649http://www.hrchen.com/2013/05/ ... -
iOS多线程编程Part 3/3 - GCD
2014-01-03 11:21 1593http://www.hrchen.com/2013/07/ ... -
iOS多线程编程Part 2/3 - NSOperation
2014-01-03 11:20 4490http://www.hrchen.com/2013/06/ ... -
iOS多线程编程Part 1/3 - NSThread & Run Loop
2014-01-03 11:17 7045http://www.hrchen.com/2013/06/ ... -
iOS移动网络环境调优那些事[转]
2014-01-02 17:10 2660http://xiangwangfeng.com/201 ... -
生成APNS Service证书的步骤[转]
2013-05-23 09:19 5639要进行推送服务的第一件事就是获取推送证书。它用来对你通过SS ... -
xcode 环境,多工程联编设置【转】
2013-02-28 21:59 8881http://blog.csdn.net/vienna_zj ... -
干掉你程序中的僵尸代码【转】
2012-12-22 11:05 926随着万圣节越来越流行,我感觉有必要跟大家讨论一下一个 ... -
一个文本框搞定信用卡相关信息的输入[转]
2012-12-22 11:03 1089http://beforweb.com/node/134 ... -
【转】深度技术分析“为什么ios比android流畅”
2012-09-23 19:41 1404原文 Andorid更新了一个版本又一个版本,硬 ... -
Iphone开发
2012-09-17 22:46 11631. NSClassFromString 这个方法 ... -
HowTo: Install iPhone SDK 2.0 – 3.1 for XCode 3.2[转]
2012-09-06 09:00 1179原文链接 So… you’ve installe ... -
Xcode 中设置部分文件ARC支持[转]
2012-08-03 10:57 1703ARC是什么 ARC是iOS 5推出的新功 ... -
xcode4 设置调试错误信息小结【转】
2012-07-19 14:37 1758方案1:NSZombieEnabled 先选中工程, ... -
Finding iPhone Memory Leaks: A “Leaks” Tool Tutorial【转】
2012-07-19 14:36 1237Finding iPhone Memory Lea ... -
[IPhone]如何使用Leak检查内存泄漏[转]
2012-07-19 14:34 1187简介 在IPhone程式开发中,记忆体泄漏(内存泄漏)是 ... -
获得通讯录中联系人的所有属性[转]
2012-06-21 14:04 1565获得通讯录中联系人的所有属性 ,看代码: ABAdd ... -
多个UIViewController使用addSubView,第二个 UIViewController 不响应旋转[转]
2012-06-20 23:51 16372------------------------------- ... -
shouldAutorotateToInterfaceOrientation 不触发或者不执行的问题[转]
2012-06-20 22:58 1413今天遇到一个很郁闷 ... -
UIViewController生命周期-学习笔记[转]
2012-06-20 22:57 1092UIViewController生命周 ...
相关推荐
通过阅读本书,你将学习 Swift 面向对象的概念、理解如何使用 Apple 的开发工具,以及探索 Cocoa 是如何提供 iOS 应用所需的底层功能的。
iOS编程基础:Swift、Xcode和Cocoa入门指南.pdf
iOS 11 Programming Fundamentals with Swift Swift, Xcode, and Cocoa Basics 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Cocoa多线程开发Objective-C详解 多线程 Objective-C iOS cocoa Xcode
IOS 10 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics by Matt Neuburg English | ISBN: 1491970073 | 2016 | PDF | 518 pages | 7 MB Move into iOS development by getting a firm ...
Mac OS X 下的Cocoa Application对话框程序,使用Xcode4.2.1开发工具,实现字母大小写的转换功能
iOS编程基础:Swift、Xcode和Cocoa入门指南 (O’Reilly精品图书系列) iOS编程基础:Swift、Xcode和Cocoa入门指南 (O’Reilly精品图书系列) iOS编程基础:Swift、Xcode和Cocoa入门指南 (O’Reilly精品图书系列)
iOS编程基础:Swift、Xcode和Cocoa入门指南 O’Reilly精品图书系列
iOS 7 Programming Fundamentals: Objective-C, Xcode, and Cocoa Basics by Matt Neuburg (Author) Publisher: O’Reilly Media (October 2013) Language: English ISBN-10: 1491945575 ISBN-13: 978-...
重要性等同于windows上的《Windows程序设计》的巨著!
realm sync cocoa for ios Xcode realm sync cocoa for ios Xcode
iOS9 Programming Fundamentals with Swift(Swift.Xcode.and.Cocoa.Basics)
每章中学到的技巧都作为基础铺垫后面章节中介绍的更高级的技巧和概念。您将学到: ·高效地用好苹果的开发工具套装,包括Xcode和Interface Builder ·构建单一的和多窗口的基于文档架构的应用程序 ·用Cocoa的...
cocoa avplayer demo xcode中文档的例子
这本书手把手教你使用xcode开发cocoa程序,菜鸟必备
The Cocoa frameworks are some of the most powerful frameworks for creating native desktop applications available on any platform today, and Apple gives them away, along with the Xcode development ...
swift 与 cocoa 框架研发 https://github.com/thesecretlab/SwiftDevelopmentWithCocoa1stEd
If you are a novice programmer who is familiar with the concepts of object-oriented programming, but have little to no knowledge of Swift, Xcode, or Apple’s Cocoa APIs, then this book is for you....