VS2010下如何调试Framework源代码(即FCL)
2012-02-13 18:06
381 查看
/article/4286654.html
怕忘记,重新记录一下。
有一种提高自己编程能力的好办法,就是看看.net framework的源码是如何写的?我们在追踪bug的时候,也往往需要追踪到.net framework的源码中去。按照如下方法设置vs2010,即可追踪到.net framwork的源代码中去。
可以看出,我将pdb文件放在了d:\msSource\MicrosoftPublicSymbols目录下面,这样在调试的时候,vs会自动去该目录下面找pdb文件。
我们可以看看这个目录下的文件
调试源码后,我们会找到一些平时不怎么写的东西。比如我追踪 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”
We get the following dialog box
This automatically disables “Enable My Code”
Go to Debugging –> Symbols and Check “Microsoft Symbol Servers”. You can selectively exclude modules if you want to.
You will get a warning dialog like so:
Hitting OK will start the download process
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.
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.
We get a one time license agreement dialog box
You might see an error like the one below regarding different encoding (hopefully will be fixed).
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.
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”.
Enjoy!
怕忘记,重新记录一下。
有一种提高自己编程能力的好办法,就是看看.net framework的源码是如何写的?我们在追踪bug的时候,也往往需要追踪到.net framework的源码中去。按照如下方法设置vs2010,即可追踪到.net framwork的源代码中去。
可以看出,我将pdb文件放在了d:\msSource\MicrosoftPublicSymbols目录下面,这样在调试的时候,vs会自动去该目录下面找pdb文件。
我们可以看看这个目录下的文件
调试源码后,我们会找到一些平时不怎么写的东西。比如我追踪 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”
We get the following dialog box
This automatically disables “Enable My Code”
Go to Debugging –> Symbols and Check “Microsoft Symbol Servers”. You can selectively exclude modules if you want to.
You will get a warning dialog like so:
Hitting OK will start the download process
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.
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.
We get a one time license agreement dialog box
You might see an error like the one below regarding different encoding (hopefully will be fixed).
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.
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”.
Enjoy!
相关文章推荐
- VS2010下如何调试Framework源代码(即FCL)
- vs2010下如何调试带输入参数的程序
- VS2010下如何调试Framework源代码(即FCL)
- VS2010下如何调试Framework源代码(即FCL)
- VS2010下如何调试Framework源代码(即FCL)
- vs2010下如何调试带输入参数的程序
- 如何使用VS 2010进行远程调试:Attach
- VS2010下如何调试Framework源代码(即FCL)
- VS2010下如何调试Framework源代码(即FCL)
- VS2010下如何调试Framework源代码(即FCL)
- VS 2010 如何配置调试本地.net 4.0源代码
- VS2010下如何调试Framework源代码(即FCL)
- 如何使用VS 2008 打开VS 2010
- 在VS中调试C#程序,如何查看内存、寄存器、反汇编
- 如何在vs.net里调试脚本
- vs 2010中如何检查内存泄露
- VS2010中调试Silverlight Applicatoin时出现Bug
- 在VS中调试C#程序,如何查看内存、寄存器、反汇编
- 在 Visual Studio 2010 (vs)中启动 MPI 群集调试程序
- VS2010 + Sql Server Express 2008 R2 如何安装(兼谈错误:The database 'XXX' cannot be opened because it is version 661. This server support