在局部变量值上设置 Visual Studio(条件)断点

发布于 2024-08-09 08:03:08 字数 129 浏览 5 评论 0原文

我正在尝试调试一种方法,其中将项目添加到该方法本地的列表中。

然而,列表大小经常被设置为零“中流”。我想将调试器设置为在列表大小变为零时中断,但我不知道如何操作,并且希望了解有关如何执行此操作的任何指示。

谢谢。

I'm trying to debug a method which among other things, adds items to a list which is local to the method.

However, every so often the list size gets set to zero "midstream". I would like to set the debugger to break when the list size becomes zero, but I don't know how to, and would appreciate any pointers on how to do this.

Thanks.

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

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

发布评论

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

评论(4

风为裳 2024-08-16 08:03:08

在 C# 中

if(theList.Count == 0){
  //do something meaningless here .e.g.
  int i = 1; //  << set your breakpoint here
}

在 VB.NET 中

If theList.Count = 0 Then
  'do something meaningless here .e.g.
  Dim i = 1; '  << set your breakpoint here
End If

为了完整起见,这里是 C++ 版本:

if(theList->Count == 0){
  //do something meaningless here .e.g.
  int i = 1; //  << set your breakpoint here
}

in C#

if(theList.Count == 0){
  //do something meaningless here .e.g.
  int i = 1; //  << set your breakpoint here
}

in VB.NET

If theList.Count = 0 Then
  'do something meaningless here .e.g.
  Dim i = 1; '  << set your breakpoint here
End If

For completeness sake, here's the C++ version:

if(theList->Count == 0){
  //do something meaningless here .e.g.
  int i = 1; //  << set your breakpoint here
}
羁拥 2024-08-16 08:03:08

我可以为 Visual Studio 2005 提供部分答案。如果打开“断点”窗口 (Alt + F9),您将获得断点列表。右键单击所需的断点,然后选择“条件”。然后输入你想要的条件。

I can give a partial answer for Visual Studio 2005. If you open the "Breakpoints" window (Alt + F9) you get a list of breakpoints. Right-click on the breakpoint you want, and choose "Condition." Then put in the condition you want.

稍尽春風 2024-08-16 08:03:08

您已经获得了建议的两个主要选项:
1.条件断点
2. 检查错误值的代码,如果发生这种情况则使用断点

第一个选项是最简单也是最好的,但不幸的是在大循环上它真的很慢!如果你循环数百次或数千次迭代,唯一真正的选择是#2。在选项 #1 中,CPU 在每次迭代时都会中断到调试器,然后评估条件,如果中断条件为 false,则它会继续执行程序。当它发生数千次时,这很慢,如果你只循环 1000 次,它实际上很慢(当然取决于硬件),

因为我怀疑你真的想要一个“全局”断点条件,如果满足某个条件,它应该中断程序(数组大小== 0),不幸的是,据我所知,这并不存在。我制作了一个调试函数来检查条件,如果条件成立,它会执行一些无意义的操作,因为我设置了断点(即选项2),然后我经常在我怀疑原始函数失败的地方调用该函数。当系统出现故障时,您可以使用调用堆栈来识别故障位置。

You have already got both major options suggested:
1. Conditional breakpoints
2. Code to check for the wrong value, and with a breakpoint if so happens

The first option is the easiest and best, but on large loops it is unfortunately really slow! If you loop 100's of thousands iterations the only real option is #2. In option #1 the cpu break into the debugger on each iteration, then it evaluates the condition and if the condition for breaking is false it just continiues execution of the program. This is slow when it happens thousands of times, it is actually slow if you loop just 1000 times (depending on hardware of course)

As I suspect you really want an "global" breakpoint condition that should break the program if a certain condition is met (array size == 0), unfortunately that does not exist to my knowledge. I have made a debugging function that checks the condition, and if it is true it does something meaningless that I have a breakpoint set to (i.e. option 2), then I call that function frequently where I suspect the original fails. When the system breaks you can use the call stack to identify the faulty location.

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