Xcode在debugging时评估expression式

我正在开发一个iPhone应用程序。 我是一个全职的Java开发人员,我习惯于使用Eclipse,在那里我可以放置一个断点,并停止进程。 然后,我可以input任何我想要的expression式,Eclipse将使用该过程中的值来评估它。

有没有办法做到这一点在Xcode? 我希望能够在断点处停下来,然后input一些代码来评估它。 GDB控制台将让我做po ( 打印对象 ),但它是非常有限的。 任何帮助?

我的做法:

po [NSUserDefaults standardUserDefaults]

显示: <NSUserDefaults:0x6143040>

po [[NSUserDefaults standardUserDefaults] stringForKey:@"Currency"]

显示: “CHF”

在XCode 4.0中,这是隐藏在GUI中的。 当你处于断点处时,你可能会看到debugging区域内的variables视图; 它是显示局部variables等的窗格。 右键单击variables视图,然后select“添加expression式…”

我意识到这是一个古老的线程,但它仍然是一个顶级的谷歌命中,所以我觉得值得回答。

在debugging器中使用“expression式”命令。 使用它相对简单。 只需input命令expression式并按下回车键。 您将被提示input一个expression式。 这是一个例子

 (lldb) expression Enter expressions, then terminate with an empty line to evaluate: 2+2 (int) $2 = 4 

我还附上了下面的expression式命令的帮助信息。 希望这可以帮助。

在当前程序上下文中使用用户定义的variables和当前在范围内的variables来评估C / ObjC / C ++expression式。 这个命令需要'原始'input(不需要引用的东西)。

语法:expression式 –

命令选项用法:expression [-f] [-G] [-a] [-d] [-t] [-u] – expression式[-o] [-a] [-d] [-t] [ – 你] – expression

  -G <gdb-format> ( --gdb-format <gdb-format> ) Specify a format using a GDB format specifier string. -a <boolean> ( --all-threads <boolean> ) Should we run all threads if the execution doesn't complete on one thread. -d <boolean> ( --dynamic-value <boolean> ) Upcast the value resulting from the expression to its dynamic type if available. -f <format> ( --format <format> ) Specify a format to be used for display. -o ( --object-description ) Print the object description of the value resulting from the expression. -t <unsigned-integer> ( --timeout <unsigned-integer> ) Timeout value for running the expression. -u <boolean> ( --unwind-on-error <boolean> ) Clean up program state if the expression causes a crash, breakpoint hit or signal. 

超时:如果可以静态评估expression式(没有运行代码),那么它将是。 否则,默认情况下,expression式将在当前线程上运行一个短暂超时:当前.25秒。 如果在这段时间内没有返回,则评估将被中断,并在所有线程运行时恢复。 您可以使用-a选项禁用所有线程重试。 您可以使用-t选项设置更短的超时时间。

用户定义的variables:您可以定义自己的variables以方便使用或在后续expression式中使用。 您可以用与在C中定义variables相同的方式来定义它们。如果用户定义的variables的第一个字符是$,那么variables的值将在将来的expression式中可用,否则它将在当前expression式中可用。

例子:

  expr my_struct->a = my_array[3] expr -f bin -- (index * 8) + 5 expr unsigned int $foo = 5 expr char c[] = "foo"; c[0] 

重要提示:由于此命令采用“原始”input,如果使用任何命令选项,则必须在命令选项结尾和原始input开始之间使用“ – ”。

不回答关于Xcode的问题,但是JetBrains的AppCode以我们大多数人从其他平台知道的标准IDE方式来完成。