调试器离奇三元操作行为对x64平台 [英] Bizarre ternary operator behavior in debugger on x64 platform
问题描述
我用一个很简单的三元表达我的C#代码:
I'm using a very simple ternary expression in my C# code:
helperClass.SomeData = helperClass.HasData ? GetSomeData() : GetSomeOtherData();
在这两种情况下,表达的每个路径上的函数返回一个非空的对象,但是,如果我看结果在调试器,它为空,直到我引用它的代码,如使用断言:
In both cases, the functions on each path of the expression return a non-null object, but if I look at the result in the debugger, it is null until I reference it in the code such as using an assert:
Debug.Assert(helperClass.SomeData != null);
这才会出现,如果我用一个64,或在调试任何CPU平台设置发生模式。它在86的模式很好。
This only appears to happen if I use an "x64" or "Any CPU" platform setting in Debug mode. It's fine in "x86" mode.
我尽量假设我发现在编译器或调试错误之前非常谨慎,但我不能找到任何。别的解释这种行为
I try to be very cautious before assuming I've found a bug in the compiler or debugger, but I can't find any other explanation for this behavior.
下面是一个完整的类做一个摄制,只需调用SomeClass.SomeAction()在64位模式下的调试器和单步看看吧:
Here's a full class to do a repro, just call SomeClass.SomeAction() in the debugger in x64 mode and step through to see it:
public class SomeClass {
public bool HasData;
public object SomeData;
private SomeClass() {
HasData = false;
}
public static void SomeAction() {
var helperClass = new SomeClass();
// Exhibits weird debugger behavior of having helperClass.SomeData = null after this line:
helperClass.SomeData = helperClass.HasData ? GetSomeData() : GetSomeOtherData();
// Note that trying helperClass.SomeData.ToString() returns a debugger error saying SomeData is null
// But this code is just fine
//if(helperClass.HasData) {
// helperClass.SomeData = GetSomeData();
//}
//else {
// helperClass.SomeData = GetSomeOtherData();
//}
// In both cases though, after this line things are fine:
Debug.Assert(helperClass.SomeData != null);
}
private static object GetSomeData() {
return new object();
}
private static object GetSomeOtherData() {
return new object();
}
}
我缺少的东西,或者这是一个臭虫在64位调试器吗我使用调试模式,因此没有优化应该存在。
Am I missing something or is this a bug in the x64 debugger? I'm using debug mode so no optimizations should be present.
推荐答案
拍摄埃里克利珀特的建议,这可能是一个错误,我已经提交了正式的连接错误此问题: https://开头连接.microsoft.com / VisualStudio中/反馈/信息/ 684202
Taking Eric Lippert's advice that this is probably a bug, I've filed an official Connect bug for this issue: https://connect.microsoft.com/VisualStudio/feedback/details/684202
谢谢大家对您的意见!
更新:他们回来对我说,他们已经固定在编译器的下一个版本这个角落情况。万岁! :)
UPDATE: They got back to me and said they've fixed this corner case in the next version of the compiler. Hooray! :)
这篇关于调试器离奇三元操作行为对x64平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!