Cannot obtain value of local or argument as it is not available at this instruction pointer, possibly because it has been optimized away

后端 未结 17 2167
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 16:12

Visual Studio 2010 kills (there is no other word) data in one of the arguments of the function in the unsafe block. What could cause this error? The following message shows

17条回答
  •  误落风尘
    2020-11-29 17:04

    If you compile with optimizations enabled, then many variables will be removed; for example:

    SomeType value = GetValue();
    DoSomething(value);
    

    here the local variable value would typically get removed, keeping the value on the stack instead - a bit like as if you had written:

    DoSomething(GetValue());
    

    Also, if a return value isn't used at all, then it will be dropped via "pop" (rather than stored in a local via "stloc", and again; the local will not exist).

    Because of this, in such a build the debugger can't get the current value of value because it doesn't exist - it only exists for the brief instant between GetValue() and DoSomething(...).

    So; if you want to debug... don't use a release build! or at least, disable optimizations while you debug.

提交回复
热议问题