【发布时间】:2015-08-24 21:28:46
【问题描述】:
查看http://lldb.llvm.org/python_reference/index.html 的SBWatchpoint 文档,我没有看到在触发观察点时分配python 回调函数的方法。
有没有办法用 Python API 做到这一点?
【问题讨论】:
查看http://lldb.llvm.org/python_reference/index.html 的SBWatchpoint 文档,我没有看到在触发观察点时分配python 回调函数的方法。
有没有办法用 Python API 做到这一点?
【问题讨论】:
有一个
watchpoint command add
支持这样做的命令
watchpoint command add [-e <boolean>] [-s <none>] [-F <python-function>] <watchpt-id>
如果你有一个 SBWatchpoint,你可以查询它的 ID,然后设计一个合适的命令行传递给 SBDebugger.HandleCommand
您将需要您的 Python 模块包含您要执行的脚本函数,并在命令行上通过限定名称传递它。例如,如果你有
# myfile.py
def callback(wp_no):
# stuff
# more stuff
mywatchpoint = ...
debugger.HandleCommand("watchpoint command add -F myfile.callback %s" % mywatchpoint.GetID())
将是告诉 LLDB 您的回调的方式
目前,无法将 Python 函数直接传递给 LLDB API 调用。
没有理由说这是不可能的,但是在一个多种脚本语言可以共存的世界中,要做到这一点有点棘手,而且由于缺乏可行的替代策略,所以没有太大的压力让它发挥作用。
【讨论】: