【发布时间】:2016-06-02 17:24:38
【问题描述】:
例如,在编写 GDB 宏时,我可以给出如下内容:
list_iterate $arg0
如果我的 C 代码中的 list_iterate() 函数看起来像
list_iterate(list_node *)
在 LLDB Python API 中,我该如何做同样的事情,即从 C 代码调用和执行函数?我已经搜索了文档,但似乎找不到这样的东西
【问题讨论】:
例如,在编写 GDB 宏时,我可以给出如下内容:
list_iterate $arg0
如果我的 C 代码中的 list_iterate() 函数看起来像
list_iterate(list_node *)
在 LLDB Python API 中,我该如何做同样的事情,即从 C 代码调用和执行函数?我已经搜索了文档,但似乎找不到这样的东西
【问题讨论】:
SBFrame::EvaluateExpression 是你想要的功能。比如:
(lldb) script
>>> options = lldb.SBExpressionOptions()
>>> result = lldb.frame.EvaluateExpression('printf("Hello there.\\n");', options)
Hello there.
>>> print result
(int) $1 = 13
注意,如果您正在编写脚本(或 Python 命令等),请不要使用 lldb.frame,您可以从您的进程中获取选定的帧,或者如果您正在编写命令,请使用传递给SBExecutionContext。见:
https://lldb.llvm.org/use/python-reference.html
了解更多详情。
【讨论】: