简体   繁体   English

Visual Studio:如何在修改成员变量时停止调试器?

[英]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.

相关问题 如果没有Xcode项目,如何在Mac OS上获得可视化调试器? - How do I get a visual debugger on Mac OS when I have no Xcode project? 我可以在Visual Studio调试器中定义变量吗? - Can I define a variable in Visual Studio debugger? 如何在Visual Studio 2017中启动HLSL调试器? - How do I launch the HLSL debugger in Visual Studio 2017? 如何编写一个非常简单的Visual Studio调试器可视化工具? - How do I write a very simple Visual Studio debugger visualizer? 当我安装了多个Visual Studio版本时,如何使用Visual Studio 2008构建增强功能? - How do I build boost with Visual Studio 2008 when I have multiple Visual Studio versions installed? 如何确保在修改.h文件时,使用Visual Studio 2008在Release版本中自动编译包括它的.cc文件? - How do I make sure that when a .h file is modified, the .cc files including it are compiled automatically in a Release build using Visual Studio 2008? Visual Studio调试器的类成员修饰 - Class member decoration for Visual Studio debugger 在Visual Studio调试器中,如何从内存中打印一系列字节? - In the Visual Studio debugger, how do I print a range of bytes from memory? 返回成员变量时如何利用移动语义? - How do I utilize move semantics when returning a member variable? 我如何解决:“错误C2039:'{ctor}':不是”在Visual Studio 2005中的成员? - How do I resolve: “error C2039: '{ctor}' : is not a member of” in Visual Studio 2005?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM