In pdb (python debugger), can I set a breakpoint on a builtin function?

℡╲_俬逩灬. 提交于 2019-12-01 21:31:14

Thanks! Using @avasal's answer and Doug Hellmann's pdb webpage, I came up with this:

Since I was trying to catch set.update, I had to edit the sets.py file, but that wasn't enough, since python was using the builtin set class rather than the one I edited. So I overwrote the builtin sets class:

import sets
locals()['__builtins__'].set=sets.Set

Then I could set conditional break points in the debugger:

b set.update, iterable=='a' #successful
b set.update, iterable=='b' #won't stop for ss.update('a')

My entire example file looks like this:

import pdb
import sets
locals()['__builtins__'].set=sets.Set

pdb.set_trace()
ss = set()
ss.update('a')

print "goodbye cruel world"

Then at the debugger prompt, enter this:

b set.update, iterable=='a'

Hope this helps others too.

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