在Xcode中,GDB允许您在调试时更改本地变量(参见如何在XCode中调试时更改NSString的值?)。 LLDB是否提供类似的功能?如果是,我们该如何使用它?
在Xcode中,GDB允许您在调试时更改本地变量(参见如何在XCode中调试时更改NSString的值?)。 LLDB是否提供类似的功能?如果是,我们该如何使用它?
expr myString = @"Foo"
(lldb) help expr
在当前程序上下文中评估C/ObjC/C++表达式,使用当前作用域中的变量。该命令接受“raw”输入(不需要引用内容)。语法:expression --
命令选项用法:expression [-f ] [-G ] [-d ] [-u ]-- expression [-o] [-d ] [-u ]-- expression
-G <gdb-format> ( --gdb-format <gdb-format> )
Specify a format using a GDB format specifier string.
-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.
-u <boolean> ( --unwind-on-error <boolean> )
Clean up program state if the expression causes a crash, breakpoint
hit or signal.
示例:
表达式 my_struct->a = my_array[3]
表达式 -f bin -- (index * 8) + 5
表达式 char c[] = "foo"; c[0]
重要提示:由于该命令接受“原始”输入,因此如果您使用任何命令选项,则必须在命令选项结尾和原始输入开头之间使用“--”。
“expr”是“expression”的缩写
expr (void)[label setText:@"Foo"]
应该可以实现。点语法在调试器中通常不起作用。lldb 可能会将其解释为您要访问 c 结构体的成员,但我不确定这是它无法工作的原因。点语法也不适用于 po
。与其使用 po label.text
,您应该使用 po [label text]
。 - Matthias Bauch@property
声明时才能够这样做。 - BJ Homerp
作为 expr
的快捷方式。例如:(lldb) p url = @"http://google.com"
- funrolle
代替 expr
。另外,p
是 print
的别名,它是 expr --
(仅对原始输入求值)或 expr -o -- [object]
或 po
的别名,通常会为对象提供更有用的输出。 - Jason Newell以下的方法适用于我的情况。 我正在使用Xcode 8。
如果你想将某个变量(例如“dict”)设置为nil,然后测试代码流程,可以尝试以下步骤。
它将在控制台中显示类似于以下内容。
(lldb) expression dict = nil
(NSDictionary *) $5 = nil
po myString = "Hello World"
更改变量。