原文地址:http://blog.sina.com.cn/s/blog_71715bf801016d2y.htmlhtml
gdb不是万能的,但是没有gdb倒是万万不能的。这里给你们简单介绍下iOS开发中最基本的gdb命令。函数
po是print-object的简写,可用来打印全部NSObject对象。使用举例以下:工具
(gdb) po self <LauncherViewController: 0x552c570> (gdb) po [self view] <UIView: 0x544eb80; frame = (0 0; 320 411); autoresize = W+H; layer = <CALayer: 0x544ebb0>> (gdb) print-object [self view] <UIView: 0x544eb80; frame = (0 0; 320 411); autoresize = W+H; layer = <CALayer: 0x544ebb0>>
p是print的简写,能够用来打印全部的简单类型,如int, float,结构体等。使用举例以下:this
(gdb) p self $1 = (LauncherViewController *) 0x552c570 (gdb) p [[self view] size] Unable to call function “objc_msgSend” at 0x1e7e08c: no return type information available. To call this function anyway, you can cast the return type explicitly (e.g. ‘print (float) fabs (3.0)’) (gdb) p (CGSize)[[self view] size] $1 = { width = 320, height = 411 } (gdb) print (CGSize)[[self view] size] $2 = { width = 320, height = 411 }
call便是调用的意思。其实上述的po和p也有调用的功能。所以通常只在不须要显示输出,或是方法无返回值时使用call。使用举例以下:spa
(gdb) call [[self view]sizeToFit] Unable to call function “objc_msgSend” at 0x1e7e08c: no return type information available. To call this function anyway, you can cast the return type explicitly (e.g. ‘print (float) fabs (3.0)’) (gdb) call (void)[[self view]sizeToFit] (gdb) call [[self view] size] Unable to call function “objc_msgSend” at 0x1e7e08c: no return type information available. To call this function anyway, you can cast the return type explicitly (e.g. ‘print (float) fabs (3.0)’) (gdb) call (void)[[self view] size]
**************************************************************************************************************开放源代码
Xcode的调试器为用户提供了一个GDB的界面,GDB是GNU组织的开放源代码调试器。您能够在Xcode的图形界面里作任何事情;可是,若是您须要 您能够在命令行里使用GDB的命令。 命令行
要在一个调试的任务里输入GDB命令行命令:
在工具栏里点击Console Drawer (控制台抽屉窗口)按钮打开控制台。
您能够在控制台里查看Xcode调试器发送给GDB的命令,或者您能够直接在控制台里输入GDB命令。在控制台窗口里点击而后在gdb提示符后面 输入命令。调试
break NUM | 在指定的行上设置断点。 |
bt | 显示全部的调用栈帧。该命令可用来显示函数的调用顺序。 |
clear | 删除设置在特定源文件、特定行上的断点。其用法为:clear FILENAME:NUM。 |
continue | 继续执行正在调试的程序。该命令用在程序因为处理信号或断点而致使中止运行时。 |
display EXPR | 每次程序中止后显示表达式的值。表达式由程序定义的变量组成。 |
file FILE | 装载指定的可执行文件进行调试。 |
help NAME | 显示指定命令的帮助信息。 |
info break | 显示当前断点清单,包括到达断点处的次数等。 |
info files | 显示被调试文件的详细信息。 |
info func | 显示全部的函数名称。 |
info local | 显示当函数中的局部变量信息。 |
info prog | 显示被调试程序的执行状态。 |
info var | 显示全部的全局和静态变量名称。 |
kill | 终止正被调试的程序。 |
list | 显示源代码段。 |
make | 在不退出gdb的状况下运行make工具。 |
next | 在不单步执行进入其余函数的状况下,向前执行一行源代码。 |
print EXPR | 显示表达式EXPR的值。 |
print- object | 打印一个对象 |
print (int) name | 打印一个类型 |
print- object [artist description] | 调用一个函数 |
set artist = @"test" | 设置变量值 |
whatis | 查看变理的数据类型 |