XCode编译器技巧
来源:互联网 发布:c语言1到n求和 编辑:程序博客网 时间:2024/03/29 08:40
XCode 内置GDB,我们可以在命令行中使用 GDB 命令来调试我们的程序。下面将介绍一些常用的命令以及调试技巧。
po 命令:为 print object 的缩写,显示对象的文本描述(显示从对象的 description 消息获得的字符串信息)。
比如:
上图中,我使用 po 命令显示一个 NSDictionary 的内容。注意在左侧我们可以看到 dict 的一些信息:3 key/value pairs,显示该 dict 包含的数据量,而展开的信息显示 isa 层次体系(即class 和 metaclass结构关系)。我们可以右击左侧的 dict,选中“Print Description of "dict"”,则可以在控制台输出 dict 的详细信息:
[cpp] view plaincopyprint?
Printing description of dict:
<CFBasicHash 0x1001149e0 [0x7fff7e27ff40]>{type = immutable dict, count = 3,
entries =>
}
(gdb)
print 命令:有点类似于格式化输出,可以输出对象的不同信息:
如:
[cpp] view plaincopyprint?
(gdb) print (char *)[[dict description] cStringUsingEncoding:4]
$1 = 0x1001159c0 "{\n
(gdb) print (int)[dict retainCount]
$2 = 1
(gdb)
注:4是 NSUTF8StringEncoding 的值。
info 命令:我们可以查看内存地址所在信息
比如 "info symbol 内存地址" 可以获取内存地址所在的 symbol 相关信息:
[cpp] view plaincopyprint?
(gdb) info symbol 0x00000001000017f7
main + 343 in section LC_SEGMENT.__TEXT.__text of /Users/LuoZhaohui/Library/Developer/Xcode/DerivedData/RunTimeSystem-anzdlhiwvlbizpfureuvenvm
比如 "info line *内存地址" 可以获取内存地址所在的代码行相关信息:
[cpp] view plaincopyprint?
(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版本信息
[cpp] view plaincopyprint?
(gdb) show version
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug
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.
This GDB was configured as "x86_64-apple-darwin".
help 命令:如果忘记某条命令的语法了,可以使用 help 命令名 来获取帮助信息。如:help info 显示 info 命令的用法。
[cpp] view plaincopyprint?
(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 又很难重现。保守的做法是在系统抛出异常之前设置断点,具体来说是在
- XCode编译器技巧
- Xcode编译器
- XCode 的调试定位技巧, 使用Xcode 4编译器设定Release/Debug教程
- XCode编译器介绍
- xcode编译器指令使用指南
- xcode之编译器
- XCode编译器介绍
- XCode编译器介绍
- XCode编译器介绍
- [XCode] 编译器介绍
- XCode编译器介绍
- XCode编译器介绍
- XCode编译器介绍
- Xcode clang 编译器
- Xcode消除编译器警告
- XCode4 的调试定位技巧, 使用Xcode 4编译器设定Release/Debug教程
- XCode4 的调试定位技巧, 使用Xcode 4编译器设定Release/Debug教程
- Xcode 技巧
- MacDonalds 翻译成“麦当劳”为什么好?英语翻译技巧E
- 通用基于TCP协议的C/S模型的代码
- ModelSim PE Student Edition 10.1b 的安装和使用
- Andriod OpenGL 教程 05 - 3D空间
- TextField输入完成后关闭键盘
- XCode编译器技巧
- Oracle表中重复记录只显示一条
- Struts2的OGNL表达式对编辑器输入的内容不进行转义
- JNI学习笔记(二)JNI中的java语言与本地C/C++语言之间的映射(附例子)
- 正则表达式学习(三)正则表达式各种操作符的运算优先级
- 仿android系统主界面 下方的小按钮滑动
- 读书笔记整理二:11g存储增强
- Oracle AWR(Automatic Workload Repository) 说明 --转自tianlesoftware
- poj 3974 Palindrome