在调试器中使用“表达式”命令。使用它相对简单。只需键入命令表达式并按回车键。然后将提示您输入表达式。这是一个例子
(lldb) expression
Enter expressions, then terminate with an empty line to evaluate:
2+2
(int) $2 = 4
我还附上了下面表达式命令的帮助信息。希望这会有所帮助。
在当前程序上下文中计算一个 C/ObjC/C++ 表达式,使用用户
定义的变量和当前范围内的变量。这个命令需要
“原始”输入(无需引用内容)。
语法:表达式——
命令选项用法:
表达式 [-f ] [-G ] [-a ] [-d ] [-t ] [-u ] --
表达式 [-o] [-a ] [-d ] [-t ] [-u ] --
表达
-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.
超时:
如果可以静态评估表达式(无需运行代码),那么它将是。
否则,默认情况下,表达式将在当前线程上运行,但超时时间很短:
目前为 0.25 秒。如果在那个时间内没有返回,评估将被中断
并在所有线程运行的情况下恢复。您可以使用 -a 选项禁用所有重试
线程。您可以使用 -t 选项设置更短的超时时间。
用户定义变量:
为方便起见,您可以定义自己的变量或在后续表达式中使用。
您定义它们的方式与在 C 中定义变量的方式相同。如果
您的用户定义变量是 $,那么该变量的值将在未来可用
表达式,否则它只会在当前表达式中可用。
例子:
expr my_struct->a = my_array[3]
expr -f bin -- (index * 8) + 5
expr unsigned int $foo = 5
expr char c[] = "foo"; c[0]
重要提示:由于此命令采用“原始”输入,如果您使用任何
命令选项你必须在命令选项的结尾之间使用'--'
以及原始输入的开头。