为什么Visual Studio Release生成在未执行的代码行中断
Why does Visual Studio Release build break on non-executing code line
在Visual Studio 10中使用默认发布配置构建c++程序时,我在一条永远不应该到达的线上设置了一个断点。让我感到困惑的是,当运行程序时,它在断点处停止了。
发生中断的代码如下所示(尽管使用此函数创建最小项目不会产生相同的行为)。添加一个volatile语句并将断点移到此行可以使执行不中断。
为什么"释放调试器"(?)会踩在这一行上,并在nto执行时触发断点?如果我在中断后继续执行,代码将继续执行return false语句。
bool BoundingBox::intersects(int32_t xpos, int32_t ypos, int32_t dx, int32_t dy) const
{
int32_t intersectionX;
int32_t intersectionY;
if((dx > 0 && xpos > right)
|| (dx < 0 && xpos < left)
|| (dy > 0 && ypos > top)
|| (dy < 0 && ypos < bot))
return false;
if(dx != 0)
{
intersectionY = ypos + (left - xpos)*dy/dx;
if (intersectionY > bot && intersectionY < top)
return true;
intersectionY = ypos + (right - xpos)*dy/dx;
if (intersectionY > bot && intersectionY < top)
return true;
}
if(dy != 0)
{
intersectionX = xpos + (bot - ypos)*dx/dy;
if (intersectionX > left && intersectionX < right)
return true;
// Could return false here
intersectionX = xpos + (top - ypos)*dx/dy;
if (intersectionX > left && intersectionX < right)
{
// volatile int e = 9;
return true; // !! Code execution will break here
}
}
return false; // Stepping with F10 will move here
}
在发布版本中,这样的行为并不奇怪。有了优化的代码,一行源代码和一个特定地址之间就不再有精确的对应关系。因此断点和单步执行将是不稳定的。
相关文章:
- 需要将此代码更改为执行代码
- 当前不会命中断点。没有调试器目标代码类型的可执行代码与此文件关联
- 单步执行代码时重复上一行
- 如何使用介子在C++中执行代码覆盖?
- Visual Studio 2017,C++,在单步执行代码时指向错误的行
- 在 R 中执行C++代码
- 通过 dll 注入在主线程中执行代码
- 无法在 c++ 中循环后执行代码
- 执行C 代码时快速频繁的文件访问
- 执行 C++ 代码后出错
- 一个人如何从代表函数的字符串中执行运行时执行C 代码
- 是否可以在程序崩溃后执行代码?
- 第一次在 Linux 上执行 c++ 代码的时间非常慢
- 计算 JSON 中的条目数并相应地执行代码
- 将在 CATCH 块之后执行代码
- 分析执行C++代码的每一行所花费的确切时间
- 我在执行代码时不断得到"Bus Error"?
- c while()..执行代码行的条件
- 从并行线程在主 Maya 线程上执行代码
- 在调用GNUPLOT之后,如何继续执行C 代码