如何暂时停止优化WPF框架元素?

How to temporarily stop optimisation of WPF framework elements?

我正在单步调试 WPF 源代码以调试我自己的代码的一些问题。我有源代码和 pdb(我使用 dotpeek 作为符号服务器,所以我有带源代码的完整 pdb),我可以毫无问题地进入 WPF 代码。我感兴趣的模块是 PresentationFramework 和 System.Xaml。调试体验很糟糕,因为框架模块已经过优化(通常是件好事!)。

我(非常夸张)的理解是,它们在安装时由 VS 或其他软件使用 ngen.exe 进行了预编译...这导致了混淆。

正在从本机图像缓存中卸载 .NET Framework 元素以改进调试

据我了解,我可以使用 ngen.exe(从 Visual Studio 文件夹启动的开发人员命令提示符)卸载本机图像文件。例如...

ngen uninstall PresentationFramework
Uninstalling assembly PresentationFramework, Version=3.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil
Uninstalling assembly PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Uninstalling assembly PresentationFramework, Version=4.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil

我相信这将迫使 C# 编译器恢复到 MSIL 版本,并在 运行 时对它们进行 JIT 编译。我还假设我可以禁用 运行time JIT 优化,这就是我获得良好调试体验的方式。
但是,卸载目标本机映像很麻烦。 Ngen 做到了,但是,就调试体验而言,它没有任何影响。

当我尝试再次卸载相同的模块时,我被告知它们没有安装 - 这令人鼓舞 - 但我也得到了依赖于它们的文件列表,很多 dll 和 exe 文件以及一些本机图像文件(大约十个)和以下消息...

You may need to uninstall these assembly roots in order to delete the native image for PresentationFramework
Error: The specified assembly is not installed.

因此,我假设我需要找到这十个文件的根并从那里开始卸载所有内容。如果存在大量依赖项,这可能会很快失控。

禁用特定 MSIL 模块的 JIT 优化

假设我可以获得未优化的模块,为了抑制 JIT 优化,我将 ini 文件添加到与我要逐步执行的模块相同的文件夹中,例如,在 C:\Windows\Microsoft.NET\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35 我有

PresentationFramework.ini

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

在 Tools/Options/Debugging/General/ 中,我禁用了启用源服务器支持并启用了抑制模块加载时的 JIT 优化。

在项目选项中,我在构建部分禁用了优化代码,我还在 Build/Advanced 中将调试信息设置为完整。

我走在正确的轨道上吗? VS 某处是否有一个配置选项,我可以告诉它使用 dll 文件并忽略积极优化的本机图像?

如果您想“调试”框架,关闭 JIT 不是您所需要的。

According to this blog,

All PDBs that are present in the Microsoft Symbol Server do not have any source information in them, which makes them not very useful for stepping through sources.

Starting with .NET 4.5.1, the symbol indexing and publishing process are changed to be in sync with the build process when updates are shipped, the corresponding PDBs are also updated to the reference source site appropriately.

So you should disable Microsoft Symbol server and change to change to use the new reference source site: http://referencesource.microsoft.com/

Please follow the steps:

1). Disable Microsoft Symbol Server lookup via Tools | Options | Debugging | Symbols. Ensure that the checkbox in front of Microsoft Symbol Server is unchecked.

2). Change Symbol file location to be http://referencesource.microsoft.com/

3). Configure .NET Reference Source for debugging: http://referencesource.microsoft.com/setup.html

For more detailed information, please take a look at the blog I provided above: http://blogs.msdn.com/b/dotnet/archive/2014/02/24/a-new-look-for-net-reference-source.aspx

Thanks.

来源:https://social.msdn.microsoft.com/Forums/vstudio/en-US/7bc17ae3-6480-439c-bec4-66be22dcfe02/obtaining-debug-symbol-pdb-files-for-net-framework-452?forum=clr

感谢@HansPassant 的帮助,我终于弄明白了。

原始图像文件存储在 C:\Windows\assembly\ 但有一个名为 shfusion.exe 的 windows 扩展名阻止正常访问此文件夹。这是通过 运行 来自提升的 cmd window...

的以下命令修复的
regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll

然后就可以看到Hans描述的内容了...

接下来,我通过使用进程 Hacker/Properties 上下文菜单检查 devenv 进程使用的 .NET 程序集,准确确认了 Visual Studio 使用了哪些版本的本机映像。它有一个 "Path" 和一个 "Native image path" 列,所以我可以准确地看到 VS 使用了哪些 NI。 然后我重命名了我不想优化的模块的文件夹...

确保我在 VS Options/Debugging 中有正确的设置,包括抑制 JIT 优化...

请注意,如果您按照我在禁用特定 MSIL 模块的 JIT 优化.[=17 中的问题中所述添加 ini 文件,则无需选中抑制 JIT 优化框=]

并且修复了对象被优化掉和跳过行的调试问题。
中所述,我可以将这样的表达式放在断点 Action 中,它每次都会起作用...

{((EventSetterNull_SO_41604891_2670182.MainWindow)System.Windows.Application.Current.MainWindow).Logger.LogMemberTry(data, new [] \{"Name", "_value"\}, "XamlNodeList.Add ")}