如何启用“启用 .NET Framework 源步进"? [英] How do you enable "Enable .NET Framework source stepping"?

查看:31
本文介绍了如何启用“启用 .NET Framework 源步进"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2013 年 2 月 22 日更新:Microsoft Connect 条目有来自 Alok Shriram(程序管理器、基类库、.NET Framework)的说明,该问题现在应该得到解决.Connect 条目被标记为Resolved (Fixed):

<块引用>

现在应该修复这个问题.我们发布了对参考来源的更新.如果您的问题仍未解决,请告诉我们.

一年半.

奖励链接

  • :

    <块引用>

    启用 .NET Framework 源代码调试

    1. 工具菜单上,点击选项.

    2. 选项对话框中,点击调试类别.

    3. 常规框中,选中以下复选框:

      • 启用 .NET Framework 源步进
      • 启用源服务器支持

    我这样做:

    注意:您会注意到,正如 MSDN 页面所指出的,并且正如我所注意到的,选中启用 .NET Framework 源步进 将自动取消选中 **Enable Just My代码(仅限托管).我还启用了源服务器支持的诊断消息.

    启用这些选项会自动为我设置符号缓存下载位置:

    注意:Microsoft Symbol Server 条目已经存在(并且无法删除).

    <小时>

    MSDN 页面说要加载符号:

    <块引用>

    使用模块窗口加载框架符号

    1. 模块窗口中,右键单击未加载符号的模块.您可以通过查看符号状态列来判断符号是否已加载.

    2. 指向从以下位置加载符号,然后单击Microsoft 符号服务器以从 Microsoft 公共符号服务器或符号路径下载符号以从您拥有的目录加载以前存储的符号.

    我试试这个:

    然后加载所有符号:

    我一直在断点,即将调用 .NET 框架代码:

    protected override void ScaleControl(SizeF factor, BoundsSpecified specified){base.ScaleControl(因子,指定);

    F11 会使调试器直接跳到下一行:

    protected override void ScaleControl(SizeF factor, BoundsSpecified specified){base.ScaleControl(因子,指定);//记录使用的运行比例因子this.scaleFactor = 新的 SizeF(this.scaleFactor.Width * factor.Width,this.scaleFactor.Height * factor.Height);

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    我正坐在我的代码中的断点处.我尝试双击调用堆栈中更上层的函数.我希望这能让我跳转到 .NET 代码:

    除了它不起作用:Visual Studio 告诉我没有可用的源:

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    如果我在尝试进入 .NET 代码之前切换到反汇编视图(调试 -> Windows -> 反汇编),我可以查看 .NET 代码中的 call:

    当我这样做时,我最终调试了 System.Windows.Forms.ScaleControl 的反汇编:

    这与能够进入 .NET Framework 源代码不一样,也不一样有用.

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    我电脑上配置的符号缓存路径确实包含符号缓存文件:

    所以它正在下载pdb符号文件,但拒绝使用它们.

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    Leppie 建议我检查 Debug 日志(打开调试日志窗口;否则它不会记录任何内容):

    Step into: Stepping over method without symbols 'System.Windows.Forms.Form.ScaleControl'

    在日志的前面我看到它为 System.Windows.Forms.dll 加载符号:

    加载C:WindowsassemblyGAC_MSILSystem.Windows.Forms2.0.0.0__b77a5c561934e089System.Windows.Forms.dll",符号加载.

    所以它找到了我的符号,但声称找不到它们.

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    来自意大利微软的一个人建议关闭要求源文件与原始版本完全匹配:

    那没有解决.

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    有人认为 .NET Framework 4.0 的 Microsoft 源服务器存在错误.按照这个建议,我将项目切换到面向 .NET Framework 3.5:

    那没有解决.

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    有人在某处闲逛想知道是否有其他人遇到了同样的问题

    这并没有解决它:

    Step into: Stepping over method without symbols 'System.Windows.Forms.Form.ScaleControl'

    如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?

    <小时>

    另见

    解决方案

    用于单步执行源代码的 PDB 仅针对 RTM 和 Service Pack 发布.因此,当安全更新发布并修改您尝试调试的 dll 时,它将导致源单步执行不起作用(也就是说,您将获得带有灰色浏览以查找源"的无源可用"").

    但是,在完成所有适当的设置后,您可以使用以下解决方法.解决方法本质上是找到导致 dll 更改的安全更新,然后将其删除.在您的计算机上删除这些安全更新具有明显的缺点.

    解决方法

    1. 确定要调试到哪个 dll(例如 System.Windows.Forms.dll)
    2. 调试时,在 Visual Studio 中打开 Modules 窗口,找到 Version 列.如果版本不是 RTM 或 Service Pack 版本,则您需要执行工作流.通常,RTM dll 会显示构建者:RTMRel".虽然作为安全更新一部分的 dll 会显示构建者:RTMGDR".请注意版本号(例如 4.0.30319.269 构建者:RTMGDR)
    3. 现在,我们要查找创建此版本的更新.通过在 support.microsoft.com/kb/上搜索 dll 和版本号来执行此操作例如,我做了以下谷歌搜索:site:support.microsoft.com/kb System.Windows.Forms.dll 4.0.30319.269
    4. 搜索应该会显示有关更新的信息.请注意地址栏中的 KB 编号.在我的例子中,地址是http://support.microsoft.com/kb/2604121,所以 KB2604121,是我们感兴趣的.
    5. 转到控制面板->程序和功能,然后单击查看已安装的更新"
    6. 查找列出 KB 编号的更新(您可以使用右上角框中的搜索).
    7. 卸载该更新.
    8. 对同一个 dll 重复此过程,直到 dll 恢复到其 RTMRel 版本或 SP 版本.例如,对于 System.Windows.Forms.dll,我必须删除 KB2686827、KB2604121、KB2518870 才能恢复到 RTMRel 版本.

    您需要为 .NET 框架中您关心调试的每个 dll 执行此操作.

    完成后,在 .net 源中设置一个断点(例如,转到 Breakpoints 选项卡,说 New->Break at Function,然后输入 System.Windows.Forms.Form.Form)或步入其中之一该 dll 中的 .net 方法.

    Update 22nd Feb 2013: The Microsoft Connect entry has note from Alok Shriram (Program Manager, Base Class Libraries, .NET Framework) that the issue should now be resolved. The Connect entry is marked as Resolved (Fixed):

    This issue should now be fixed. We published an update to reference sources. Please let us know in case your issue is still not fixed.

    Year and a half.

    Bonus Links

    Original Question

    How do I enable .NET framework source stepping in Visual Studio 2010?


    Note: This question is one piece of a larger whole:


    Visual Studio 2010 comes with a new feature:

    • Tools, Options, Debugging, General, Enable .NET Framework source stepping

    Following the instructions on the MSDN page How to: Debug .NET Framework Source:

    To enable .NET Framework source debugging

    1. On the Tools menu, click Options.

    2. In the Options dialog box, click the Debugging category.

    3. In the General box, select the following check boxes:

      • Enable .NET Framework source stepping
      • Enable source server support

    I do this:

    Note: You will note, as the MSDN page notes, and as I noticed, that checking Enable .NET Framework source stepping will automatically uncheck **Enable Just My Code (Managed only). I also enabled the diagnostic messages of source server support.

    Enabling those options automatically set a symbol cache download location for me:

    Note: The Microsoft Symbol Server entry is already present (and cannot be removed).


    The MSDN page says to load the symbols:

    To load Framework symbols using the Modules window

    1. In the Modules window, right-click a module for which symbols are not loaded. You can tell if symbols are loaded or not by looking at the Symbols Status column.

    2. Point to Load Symbols From and click Microsoft Symbol Servers to download symbols from the Microsoft public symbols server or Symbol Path to load from a directory where you have previously stored symbols.

    I try this:

    and then all the symbols are loaded:

    I’ve been sitting on a breakpoint, which is about to call into .NET framework code:

    protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
    {
        base.ScaleControl(factor, specified);
    

    Pushing F11 causes the debugger to simply skip to the next line:

    protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
    {
        base.ScaleControl(factor, specified);
    
        //Record the running scale factor used
        this.scaleFactor = new SizeF(
                this.scaleFactor.Width * factor.Width,
                this.scaleFactor.Height * factor.Height);
    

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    I am sitting at a breakpoint in my code. I try double-clicking on a function further up in the call stack. This would, I hope, allow me to jump to the .NET code:

    Except that it doesn’t work: Visual Studio tells me that there’s no source available:

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    If I switch to disassembly view before trying to step into .NET code (Debug -> Windows -> Disassembly), I can see a call into the .NET code:

    And when I do, I end up debugging a disassembly of System.Windows.Forms.ScaleControl:

    Which isn’t the same as, or as useful as, being able to step into the .NET Framework source.

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    The configured symbol cache path on my computer does contain symbol cache files:

    So it is downloading pdb symbol files, but refusing to use them.

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    Leppie suggested that I check the Debug log (with the debug log window open; otherwise it doesn’t log anything):

    Step into: Stepping over method without symbols 'System.Windows.Forms.Form.ScaleControl'
    

    Earlier in the log I see it loading symbols for System.Windows.Forms.dll:

    Loaded 'C:WindowsassemblyGAC_MSILSystem.Windows.Forms2.0.0.0__b77a5c561934e089System.Windows.Forms.dll', Symbols loaded.
    

    So it is finding my symbols, but claiming that it couldn’t find them.

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    A guy from Microsoft Italy suggests turning off Require source files to exactly match original version:

    That didn’t fix it.

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    It has been suggested that there’s a bug with Microsoft’s source server for .NET Framework 4.0. Following that suggestion, I switched the project to target .NET Framework 3.5:

    That didn’t fix it.

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    Someone somewhere idly wondered whether another person experiencing the same problem was using the 64-bit version of the debugger. Now, there’s no such thing as a 64-bit version of Visual Studio, but I tried switching my project from AnyCPU to x86 (it was being JITed to x64), in case Microsoft doesn’t support 64-bit processors:

    That didn’t fix it:

    Step into: Stepping over method without symbols 'System.Windows.Forms.Form.ScaleControl'
    

    How do I enable .NET Framework source stepping in Visual Studio 2010?


    See also

    解决方案

    The PDBs for stepping through the source code are only posted for RTM and Service Packs. As such, when security update comes out and it modifies the dll you are trying to debug, it will cause source stepping to not work (that is, you'll get the "No source Available" with a greyed out "Browse to find Source").

    However, once you've made all the appropriate settings, you can use the following workaround. The workaround is essentially to find the security updates that caused the dll to change, and then remove them. This has the obvious downside of having those security updates removed on your machine.

    Workaround

    1. Identify which dll you want to debug into (e.g. System.Windows.Forms.dll)
    2. While debugging, open the Modules window in Visual studio, find the Version column. If the version is not the RTM or Service pack version, then you'll need to do the workflow. Typically the RTM dll will say "built by: RTMRel". While a dll that was part of a security update will say "built by: RTMGDR". Note the version number (for example 4.0.30319.269 built by: RTMGDR)
    3. Now, we want to find the update that created this version. Do this by searching for the dll and version number at support.microsoft.com/kb/ For example, I did the following google search: site:support.microsoft.com/kb System.Windows.Forms.dll 4.0.30319.269
    4. The search should turn up information about an update. Note the KB number in the address bar. In my example the address was http://support.microsoft.com/kb/2604121, so KB2604121, is what we're interested in.
    5. Go to Control Panel->Programs and Features, and click "View Installed Updates"
    6. Find an update which lists the KB number (you can use the search in the upper right box).
    7. Uninstall that update.
    8. Repeat this process for this same dll until the dll is back to its RTMRel version or SP version. For example, for System.Windows.Forms.dll, I had to remove KB2686827, KB2604121, KB2518870 before it was back to the RTMRel version.

    You'll need to do this for each dll within the .NET framework that you care about debugging into.

    Once that's done, set a breakpoint within the .net source (for example, go to the Breakpoints tab, say New->Break at Function, and enter System.Windows.Forms.Form.Form) or step into one of the .net methods in that dll.

    这篇关于如何启用“启用 .NET Framework 源步进"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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