Visual C 上的条件调试2008年快报
有没有办法在 Visual C++ 2008 Express 上调试代码,例如我可以观察某个变量的某些值,并在它采用该值时中断?
例如,我想在 x
变为 5
时中断。在 gdb 中,我会设置一个断点,然后设置一个条件 x == 5
。我怎样才能在 Visual C++ 2008 Express 上做到这一点(如果可能)?
Is there a way to debug code on Visual C++ 2008 Express, such as I can watch a variable for certain value(s) and, when it assumes this value, to break?
For instance, I want to break when x
becomes 5
. In gdb I would set a breakpoint then a condition that x == 5
. How can I do it (if possible) on Visual C++ 2008 Express?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尽管 Express 版本中缺少对其的内置支持,但还有另一种方法可以解决它。
我在类似问题的另一个答案中发现了这一点。
该示例显示,如果 Name 属性与“Book”匹配,则会出现断点。
这是最初的问题:
我如何:创建断点使用条件? [C# Express]
Although built in support for it is missing in the express editions, there is another way around it.
I found this on another answer for a similar question.
The example shows that if the Name property matches "Book", a breakpoint occurs.
Here is the original question:
How Do I: Create a Breakpoint Using Conditions? [C# Express]
这在 Visual Studio Express 版本中是不可能的。但在完整版本中这是可能的。
This is not possible in the Express versions of Visual Studio. But it is possible in the full versions.
看来即使在快递中也可以做到这一点,至少在这里它有效。标记断点后,我右键单击它的标记,然后设置一个“条件”(这再简单不过了)
!设置条件
然后您可以编写一个计算结果为 true 的表达式。我的同事刚刚向我展示了这个,他说他们在使用它来比较字符串时遇到了一些问题,但对于使用整数进行简单比较来说,它非常简洁。
!条件窗口
但是,正如另一个答案中所述,这是不如直接输入中断代码那么快。
It seems it's possible to do this even in express, at least here it worked. After marking the breakpoint, I right-clicked on its mark, and set a "Condition" (it couldn't be easier than that)
!Setting a condition
Then you can write an expression which evaluates to true. My colleague who has just showed this to me said they have some issues using this for comparing strings, but it's pretty neat for simple comparisons using ints.
!Condition window
However, as said in the other answer, this is not so fast as typing the break code directly.
幸运的! C/C++ 的 Visual Studio 2010 Express 确实支持它。请参阅如何:指定断点条件 。
我试过了。
Lucky! Visual Studio 2010 Express of C/C++ does support it. See How to: Specify a Breakpoint Condition.
I've tried it.