在Xcode中,GDB允许您在调试时更改局部变量(请参见how to change NSString value while debugging in XCode?)。 LLDB是否提供类似的功能?如果是这样,我们如何使用它?
expr myString = @"Foo"
((lldb)help expr计算当前的C / ObjC / C ++表达式程序上下文,使用当前作用域中的变量。这个命令接受“原始”输入(无需引用内容)。
语法:表达式-
命令选项的用法:表达式[-f] [-G][-d] [-u]-表达式[-o] [-d] [-u]-表达式
-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.
示例:
expr my_struct-> a = my_array [3]expr -f bin-(索引* 8)+ 5expr char c [] =“ foo”; c [0]
重要说明:由于此命令采用'原始'输入,因此,如果您使用任何命令选项,则在末尾之间必须使用'-'。命令选项和原始输入的开头。
'expr'是'expression'的缩写
以下内容对我有用。我正在使用Xcode 8。
如果要将某些变量(例如“ dict”)设置为nil,然后测试代码流,则可以尝试以下操作。
它将在控制台中看起来像。
(lldb) expression dict = nil
(NSDictionary *) $5 = nil
如果使用的是Xcode 10或11,则在将断点初始化为所需的变量后正确地放置断点,然后可以使用po myString = "Hello World"
轻松更改变量。