当条件应该给出错误时,Visual Studio调试器会做什么

时间:2012-06-12 13:51:51

标签: c++ debugging visual-studio-2010

我正在调试一些代码,当字符串中的字符(const char *)等于某事时,我需要每次都中断。

所以我把断点和附加条件放在一起,如:s[0] == 'e'。但是我正在调试的代码是在CRT中,并且有可能s == 0是真的。因此“寻址空指针”应该会产生某种错误。是的 - 我可以给条件s != 0,但它不会那么有趣:)

我很好奇,调试器在尝试评估这种情况时会做些什么?它将如何在内部表现?显然,s == 0

时,它没有给出任何错误,也没有停在此断点上

感谢您的回答。

1 个答案:

答案 0 :(得分:3)

从未尝试过,但我认为它会停止执行。我的假设基于:

If you set a breakpoint condition with invalid syntax, a warning message appears immediately. If you specify a breakpoint condition with valid syntax but invalid semantics, a warning message appears the first time the breakpoint is hit. In either case, the debugger breaks execution when the invalid breakpoint is hit. The breakpoint is skipped only if the condition is valid and evaluates to false.

Source