MS编译器的优化,在函数替换变量? [英] MS compiler optimization that replaces variables in a function?

查看:108
本文介绍了MS编译器的优化,在函数替换变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该怎么解释,我看到的行为,但在这里不用。

我有一个函数foo的有三个参数,一个指针,一个int,另一个指针。当我突破点内富,我可以清楚地看到,所有的变量都是他们应该是值。然而,当我下台超出了局部变量声明,参数之一(INT)突然变为零。但是,函数的执行剩下的就好像它是原始值,所以一切都很好。

这并不完全调试发生,但在常规的调试确实会发生。这是某种形式的优化?如果是这样,它是什么叫和我在哪里可以得到详细信息?

例如:

 无效美孚(无效* A,INT B,无效* C)
{
  // B == 5
  INT X = 3;
  字符* Y = getSomeStaticString();
  // ...一些其他的变量声明像上面  // B,按调试器,现在是0
  如果(B == 5){
    //但是,这仍然执行
  }
}


解决方案

您正在调试优化code。局部变量不能信任 - 编译器可以自由地重用他们的空间,在寄存器中缓存起来,等

什么你可能看到的是B在寄存器中缓存和它的堆栈位置被其他一些变量重复使用。

类似的问题在这里:<一href=\"http://stackoverflow.com/questions/563000/can-optimizations-affect-the-ability-to-debug-a-vc-app-using-its-pdb/567886\">http://stackoverflow.com/questions/563000/can-optimizations-affect-the-ability-to-debug-a-vc-app-using-its-pdb/567886

I'm not sure how to explain the behavior I'm seeing, but here goes.

I have a function foo that takes three parameters, a pointer, an int, and another pointer. When I break-point inside foo, I can clearly see that all the variables are the values they should be. However, when I step down beyond the local variable declarations, one of the parameters (the int) suddenly changes to zero. However, the rest of the function executes as if it were the original value, so all is well.

This doesn't happen in full debug, but does happen in regular debug. Is this some kind of optimization? If so, what is it called and where can I get the details?

Example:

void foo(void *A, int B, void *C)
{
  // B == 5
  int X = 3;
  char *Y = getSomeStaticString();
  // ... some other variable declarations like the above

  // B, according to the debugger, is now 0
  if (B == 5) {
    // But this still executes
  }
}

解决方案

You're debugging optimized code. Local variables can't be trusted - the compiler is free to reuse their space, cache them in a register, and so on.

What you're probably seeing is B is cached in a register and its stack location is being reused for some other variable.

Similar question here: http://stackoverflow.com/questions/563000/can-optimizations-affect-the-ability-to-debug-a-vc-app-using-its-pdb/567886

这篇关于MS编译器的优化,在函数替换变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆