有没有办法使用 PyDev 在 Python 中的变量访问上设置断点?
我有一个全局变量(我知道)正在从某个地方的好值更改为坏值。我不知道在哪里,我想知道在哪里。我希望我的调试器(Eclipse/PyDev)能够在任何代码写入此全局变量时中断,类似于 OllyDBG 中的硬件断点。
我发现有时在这种情况下有效的一个技巧是将变量重构为属性,然后在该属性的 setter 中设置断点:对变量的任何访问都会通过 setter,然后我从调试器中得到我想要的东西。在这种情况下这不起作用。
有想法吗?
I have a global variable (I know) that is being changed from a good value to a bad value somewhere. I don't know where, and I'd like to find out where. I would like my debugger (Eclipse/PyDev) to break any time any code writes to this global variable, something akin to hardware breakpoints in OllyDBG.
One trick I've found that sometimes works in this situation is to refactor the variable as a property and then set a breakpoint in that property's setter: any access to the variable goes through the setter and I get what I want from the debugger. This isn't working in this case.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,PyDev 没有这样的功能(在思考了如何实现这一功能之后,我无法想出一种实现该功能的方法)——我使用的是您更改属性的解决方案当我需要该功能时(正如您所说,它不适用于全局变量......在这种情况下,我通常没有一个全局变量,而是一个包含变量的“持有者”实例,在这种情况下它仍然是可以创建一个让它工作的属性)。
@slowdog:这是一个与观察点相关的不同问题(现在实际上适用于 PyDev)。
Unfortunately, PyDev does not have such a feature (and after thinking a bit on how would that be implemented, I couldn't come up with a way to implement that) -- your solution on changing it for a property is the one I use when I need that feature (and it won't work for a global variable as you said... in this case, instead of having a global variable I usually have a 'holder' instance that contains the variables, in which case it's still possible to create a property for it to work).
@slowdog: that was a different question related to watchpoints (which actually works on PyDev now).