VS2010下如何调试Framework源代码(即FCL)

简介: 怕忘记,重新记录一下。 有一种提高自己编程能力的好办法,就是看看.net framework的源码是如何写的?我们在追踪bug的时候,也往往需要追踪到.net framework的源码中去。按照如下方法设置vs2010,即可追踪到.net framwork的源代码中去。

怕忘记,重新记录一下。

有一种提高自己编程能力的好办法,就是看看.net framework的源码是如何写的?我们在追踪bug的时候,也往往需要追踪到.net framework的源码中去。按照如下方法设置vs2010,即可追踪到.net framwork的源代码中去。

image

image

可以看出,我将pdb文件放在了d:\msSource\MicrosoftPublicSymbols目录下面,这样在调试的时候,vs会自动去该目录下面找pdb文件。

我们可以看看这个目录下的文件

image

调试源码后,我们会找到一些平时不怎么写的东西。比如我追踪 IEnumerable<int>的扩展方法Sum,可以看到

如下的代码:

public static int Sum(this IEnumerable<int> source) {
            if (source == null) throw Error.ArgumentNull("source");
            int sum = 0;
            checked {
                foreach (int v in source) sum += v;
            }
            return sum;
        }

这样,我们就学会了一个扩展方法的写法,何乐而不为呢?

编程的快乐,往往在乎一念之间。 

PS:代码是从微软服务器上下载的,所以设置完毕后,第一次下载过程可能有点长。

更详细的文档如下:

Using the Microsoft Symbol Server to obtain symbol debugging information is now much easier in VS 2010. Microsoft gives you access to their internet symbol server that contains symbol files for most of the .NET framework including the recently announced availability of MVC 2 Symbols. 

SETUP 

In VS 2010 RTM, go to Tools –> Options –> Debugging –> General. Check “Enable .NET Framework source stepping” 
image 
We get the following dialog box

 image 
This automatically disables “Enable My Code” 
 image 
Go to Debugging –> Symbols and Check “Microsoft Symbol Servers”. You can selectively exclude modules if you want to. 
  image 
You will get a warning dialog like so: 
image 
Hitting OK will start the download process 
  image 
The setup is complete. You are now ready to start debugging!


DEBUGGING

Add a break point to your application and run the application in debug mode (F5 shortcut for me). Go to your call stack when you hit the break point. Right click on a frame that is grayed out. 
image 
Select “Load Symbols from” “Microsoft Symbol Servers”. VS will begin a one time download of that assembly. This assembly will be cached locally so you don’t have to wait for the download the next time you debug the app. 
image  
We get a one time license agreement dialog box 
image

You might see an error like the one below regarding different encoding (hopefully will be fixed). 
image   
Assemblies for which the symbols have been loaded are no longer grayed out. Double clicking on any entry in the call stack should now directly take you to the source code for that assembly.

image 

image

AFAIK, not all symbols are available on the MS symbol server. In cases like that you will see a tab like the one below and be given the option to “Show Disassembly”.

image

Enjoy!

Creative Commons License本文基于 Creative Commons Attribution 2.5 China Mainland License发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名 http://www.cnblogs.com/luminji(包含链接)。如您有任何疑问或者授权方面的协商,请给我留言。
目录
相关文章
|
4月前
|
存储 IDE 编译器
C++从入门到精通:1.3.1了解IDE与C++程序的编写、编译和运行
C++从入门到精通:1.3.1了解IDE与C++程序的编写、编译和运行
|
4月前
|
定位技术 数据处理 C++
Visual Studio软件调用已经配置、编译好的C++第三方库的方法
Visual Studio软件调用已经配置、编译好的C++第三方库的方法
136 1
|
iOS开发
Xcode设置编译链接-framework CoreFoundation
Xcode设置编译链接-framework CoreFoundation
87 0
Xcode设置编译链接-framework CoreFoundation
|
存储 JSON JavaScript
简说Visual Studio代码进行调试
前端编程很有趣,开发人员有能力创建他们想要的任何东西,任何效果。不幸的是,当遇到bug时,这种乐趣就会消失。JavaScript开发人员可能首先想到的是alert、console.log语句。添加console.log()是可视化代码状态的一种快速方法。
300 0
简说Visual Studio代码进行调试
|
编译器 Linux C语言
【C 语言】动态库封装与设计 ( Windows 动态库简介 | Visual Studio 调用动态库 )
【C 语言】动态库封装与设计 ( Windows 动态库简介 | Visual Studio 调用动态库 )
267 0
【C 语言】动态库封装与设计 ( Windows 动态库简介 | Visual Studio 调用动态库 )
|
缓存 IDE Ubuntu
yasd 调试器 v0.2.5 版本发布,支持 PHP8 以及在 IDE 中使用调试
有小伙伴提交 issue,询问是否支持 PhpStorm 以及 VScode,那么它来了
448 0
yasd 调试器 v0.2.5 版本发布,支持 PHP8 以及在 IDE 中使用调试
|
开发工具 C++
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(一)
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(一)
441 0
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(一)
|
架构师 IDE 开发工具
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(三)
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(三)
235 0
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(三)
|
XML 数据库连接 开发工具
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(二)
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(二)
143 0
Visual Studio Package 插件开发之自动生成实体工具(Visual Studio SDK)(二)
|
Unix 物联网 Linux
开源项目推荐:POCO C++ Libraries大全,含MFC的编译及使用
开源项目推荐:POCO C++ Libraries大全,含MFC的编译及使用
666 0
开源项目推荐:POCO C++ Libraries大全,含MFC的编译及使用