visual-studio VS 调试和观察变量的变化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2530532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:42:43  来源:igfitidea点击:

VS debugging and watching a variable for changes

c#visual-studiodebugging

提问by Shawn Mclean

I have a property inside a class that is getting changed by something. The only place I change the value of this code is a line that looks like this:

我在一个被某些东西改变的类中有一个属性。我更改此代码值的唯一地方是如下所示的一行:

pushpin.Position.Altitude = -31;

During visual studio debugging, is there a way to watch .Altitude for any changes made, preferably it breaks at the assignment statement that changes the value.

在 Visual Studio 调试期间,有没有办法观察 .Altitude 所做的任何更改,最好是在更改值的赋值语句处中断。

If this is the correct way to track down this problem, could I have a step-by-step tutorial/instruction on how to do this?

如果这是追踪此问题的正确方法,我是否可以提供有关如何执行此操作的分步教程/说明?

Thanks.

谢谢。

采纳答案by JaredPar

If this is a property then you can do this by adding a breakpoint to the set method of the property. Putting the cursor in the set statement and hit F9 will create the break point.

如果这是一个属性,那么您可以通过向该属性的 set 方法添加断点来实现。将光标放在 set 语句中并按 F9 将创建断点。

If this is a field then there's no way to watch this directly. Breaking when a field changes a value is a supported operation in C++, known as data break points, but is not supported in the CLR. The best work around is to convert the field to a property temporarily and break on the set statement.

如果这是一个字段,则无法直接观看。在字段更改值时中断是 C++ 中受支持的操作,称为数据断点,但在 CLR 中不受支持。最好的解决方法是暂时将字段转换为属性并中断 set 语句。

EDIT

编辑

Updating based on OP saying it's a 3rd party DLL.

根据 OP 说它是第 3 方 DLL 进行更新。

In this case you want to use the Break at Function feature of Visual Studio. The first step is to disable Just My Code.

在这种情况下,您希望使用 Visual Studio 的函数处中断功能。第一步是禁用仅我的代码。

  • Tools -> Options -> Debugger
  • Uncheck "Enable Just My Code"
  • 工具 -> 选项 -> 调试器
  • 取消选中“仅启用我的代码”

Next actually set the named break point

接下来实际设置命名断点

  • Open up the break points window (Debugger -> Windows -> Break Points)
  • Click on the new button and select "Break at function"
  • Enter the name of the property. For example: Position.set_Altitude
  • 打开断点窗口(Debugger -> Windows -> Break Points)
  • 单击新按钮并选择“中断函数”
  • 输入属性的名称。例如:Position.set_Altitude

You may need to fully qualify the name in order to get it to work

您可能需要完全限定名称才能使其正常工作

回答by Sky Sanders

You can set a conditional breakpoint by setting the bp and then right-click to specify a condition upon which to break at that line.

您可以通过设置 bp 来设置条件断点,然后右键单击以指定在该行中断的条件。

You can add a 'Watch' to a variable and specify to break anywhere/anytime the value changes.

您可以向变量添加“监视”并指定在值更改的任何地方/任何时候中断。

回答by Leftium

You need to set a data breakpoint. A data breakpoint will cause the debugger to break when a certain memory address has changed.

您需要设置数据断点。当某个内存地址发生变化时,数据断点将导致调试器中断。

More detailed description and instructions how to set a data breakpoint.

更详细的描述和说明如何设置数据断点。