LLDB: Python API & Setting callback function for a watchpoint

心不动则不痛 提交于 2019-12-11 11:07:30

问题


Looking at the documentation for SBWatchpoint at http://lldb.llvm.org/python_reference/index.html, I do not see a method for assigning a python callback function for when a watchpoint is triggered.

Is there a way to do this with the Python API?


回答1:


There is a

watchpoint command add

command that supports doing that

  watchpoint command add [-e <boolean>] [-s <none>] [-F <python-function>] <watchpt-id>

If you have an SBWatchpoint, you can query for its ID, and then craft an appropriate command line to pass down to SBDebugger.HandleCommand

You will need your Python module to contain the script function you want executed, and pass it by qualified name on the command line. For instance, if you have

# myfile.py
def callback(wp_no):
   # stuff
# more stuff
mywatchpoint = ...
debugger.HandleCommand("watchpoint command add -F myfile.callback %s" % mywatchpoint.GetID())

would be the way to tell LLDB about your callback

Currently, there is no way to pass Python functions directly to LLDB API calls.

There is no reason why that is impossible, but it is a little tricky to get right in a world where multiple scripting languages could coexist, and given the lack of a viable alternative strategy, there's not much pressure to get it working.



来源:https://stackoverflow.com/questions/32192027/lldb-python-api-setting-callback-function-for-a-watchpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!