转自:http://blog.youkuaiyun.com/mars2639/article/details/7589802
更新说明:后面发现这篇文章介绍的比较全面http://blog.youkuaiyun.com/ch_soft/article/details/6740000
gdb不是万能的,可是没有gdb却是万万不能的。这里给大家简单介绍下iOS开发中最基本的gdb命令。
po
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
p是print的简写,可以用来打印所有的简单类型,如int, float,结构体等。使用举例如下:
(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
call即是调用的意思。其实上述的po和p也有调用的功能。因此一般只在不需要显示输出,或是方法无返回值时使用call。使用举例如下:
(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 查 看变理的数据类型