GDB 在 LLDB 中的“定义”是什么?

What is the equivalent of GDB's “define” in LLDB?

我想定义一个同时运行 2 个命令的 LLDB 函数(例如,打印变量值并转到下一行)。使用 GDB 调试 C 代码我会这样做:

(gdb) def f
Type commands for definition of "f".
End with a line saying just "end".
>p i
>n
>end
(gdb) f

但是用 LLDB 尝试同样的方法不起作用:

(lldb) def f
error: 'def' is not a valid command.
error: Unrecognized command 'def'.

有办法吗?

来自http://lldb.llvm.org/tutorial.html

lldb also has a built-in Python interpreter, which is accessible by the "script" command. All the functionality of the debugger is available as classes in the Python interpreter, so the more complex commands that in gdb you would introduce with the "define" command can be done by writing Python functions using the lldb-Python library, then loading the scripts into your running session and accessing them with the "script" command.