有什么方法可以设置值相关断点吗?

发布于 2024-10-07 05:00:11 字数 209 浏览 0 评论 0原文

我想知道,Visual Studio 2008 有没有办法设置值断点之类的东西?就像说有一个名为“test”的变量,我希望代码停止在整个项目中该变量的值被更改的任何行..?

也就是说,我不需要任何特定于行的断点..我只希望Visual Studio停在对某些变量进行更改的代码行..

我的代码非常复杂,而且会很多如果我能以某种方式获得上述功能,我就可以更轻松地调试代码..

I want to know, is there any way in Visual Studio 2008 to set a value breakpoint kind of a thing ? Like say there's a variable called 'test', and I want to the code to stop at any line in the entire project where the value of this variable is being changed .. ?

That is, I don't want any line specific breakpoint .. I just want Visual Studio to stop at the line of code where a change is being made to some variable ..

The code I have is very complex and it would be a lot easier for me to debug the code if I can get the mentioned functionality somehow ..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明媚如初 2024-10-14 05:00:11

您应该将变量封装在属性中,以便名为 test 的字段变为 _testmTest 或其他内容,然后创建一个名为 test 的新属性代码将使用。您可以将断点放在属性的设置器上。

因此,

public int test;

您可以拥有

private int _test;

public int test
{
  get { return _test; }
  set { _test = value; } // Breakpoint goes here.
}

,而无需更改 test 的任何用户,除非它们已经被编译,在这种情况下,您需要再次编译它们。

You should encapsulate the variable in a property so the field named test becomes _test or mTest or whatever and you create a new property called test that other code will use. You can put the breakpoint on the setter of the property.

So instead of having

public int test;

You can have

private int _test;

public int test
{
  get { return _test; }
  set { _test = value; } // Breakpoint goes here.
}

And there's no need to alter any of the users of test, unless they've already been compiled in which case you'll need to compile them again.

蓝梦月影 2024-10-14 05:00:11

是的,使用条件断点

将断点设置到您要调试的代码行。

然后右键单击红色圆圈(断点),单击“条件”。

然后设置你想要的条件,以便断点。 (例如,当“test”== 1 时中断)。

请记住 - 您仍然需要在某处设置断点,因为它需要具有条件中使用的变量的范围。

HTH。

Yep, use a Conditional Breakpoint.

Set a breakpoint to the line of code you want to debug.

Then right click on the red circle (breakpoint), click "Condition".

Then set the condition that you want to be true in order to breakpoint. (e.g break when "test" == 1).

Keep in mind - you still have to set the breakpoint somewhere, as it needs to have scope of the variable used in the condition.

HTH.

謸气贵蔟 2024-10-14 05:00:11

您使用条件断点,并在值中键入变量名称,然后将复选框从“Is true”更改为“Has Change”。

要进行设置,请左键单击出现断点的左侧列。将创建一个断点。

然后,右键单击出现的红色字形,然后从下拉菜单中选择条件。

这应该能让你到达你需要去的地方。

You use a conditional breakpoint, and in the values, type in the variable name, and change the checkbox from "Is true" to "Has changed".

To set this up, left click on the left hand column where breakpoints appear. A breakpoint will be created.

You then right click on the red glyph that appeared, and select condition from the drop down menu.

This should get you where you need to be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文