[英]Visual Studio: how do I have the debugger stop when a member variable is modified?
I have program that has a variable that should never change. 我的程序有一个永远不会改变的变量。 However, somehow, it is being changed. 然而,不知何故,它正在改变。 Is there a way to have the debugger stop when that particular member variable is modified? 有没有办法让修改器在修改特定成员变量时停止?
Set a data breakpoint to stop execution whenever some variable changes. 设置数据断点以在某个变量发生更改时停止执行。
Break on the initialization of your variable, or someplace where your variable is visible - you need to be able get its address in memory. 打破变量的初始化,或者变量可见的位置 - 您需要能够在内存中获取其地址。 Then, from the menus choose Debug -> New Breakpoint -> New Data Breakpoint. 然后,从菜单中选择Debug - > New Breakpoint - > New Data Breakpoint。 Enter " &var
" (with var
replaced by the name of your variable.) 输入“ &var
”( var
替换为变量名称。)
This will break into the debugger on the exact line of code that is modifying your variable. 这将在修改变量的确切代码行中进入调试器。
More documentation here: 更多文档:
http://msdn.microsoft.com/en-us/library/350dyxd0.aspx http://msdn.microsoft.com/en-us/library/350dyxd0.aspx
You can set conditional breakpooint at places where the variable is used. 您可以在使用变量的位置设置条件断点。
In Visual Studio set breakpoint by pressing F9 when your cursor at the line where you want to set breakpoint. 在Visual Studio中设置断点,当光标位于要设置断点的行时按F9。
Next, right click on the breakpoint and select Condition. 接下来,右键单击断点并选择Condition。
Type your condition like 输入你喜欢的条件
n != 5
Good luck. 祝好运。
Here's a link from MSDN . 这是MSDN的链接 。
If it is being modified through an assignment or other direct update, the data breakpoint will work. 如果通过赋值或其他直接更新对其进行修改,则数据断点将起作用。 However, if it is being modified via some other means - for example a buffer overwrite - I'm not sure if it will tell you exactly when it occurs. 但是,如果通过其他方式修改它 - 例如缓冲区覆盖 - 我不确定它是否会告诉你它何时发生。 Just something to keep in mind. 请记住一些事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.