使用Windows Debugger调试托管代码----引用自官方帮助文档
以下文字引用在Windbg的帮助文档。觉得对初次调试托管代码,非常有用,故粘贴至此。
=========================================================================================================
Debugging Managed Code Using the Windows Debugger
You can use the windows debuggers (WinDbg, CDB, and NTSD) to debug target applications that contain managed code. To debug managed code, you must load the SOS debugger extension (sos.dll) and a data access component (mscordacwks.dll).
The windows debuggers are separate from the Visual Studio debugger. For information about the distinction between the windows debuggers and the Visual Studio debugger, see Windows Debugging.
Introduction to Managed Code
Managed code is executed together with the Microsoft .NET common language runtime (CLR). In a managed-code application, the binary code that the compiler produces is in Microsoft intermediate language (MSIL), which is platform-independent.
When managed code is run, the runtime produces native code that is platform-specific. The process of generating native code from MSIL is called just-in-time (JIT) compiling. After the JIT compiler has compiled the MSIL for a specific method, the method's native code remains in memory. Whenever this method is later called, the native code executes and the JIT compiler does not have to be involved.
You can build managed code by using several compilers that are manufactured by a variety of software producers. In particular, Microsoft Visual Studio can build managed code from several different languages including C#, Visual Basic, JScript, and C++ with managed extensions.
The CLR is not updated every time the .NET Framework is updated. For example, versions 2.0, 3.0, and 3.5 of the .NET Framework all use version 2.0 of the CLR. The following table shows the version and filename of the CLR used by each version of the .NET Framework.
| .NET Framework version | CLR version | CLR filename | 
|---|---|---|
| 1.1 | 1.1 | mscorwks.dll | 
| 2.0 | 2.0 | mscorwks.dll | 
| 3.0 | 2.0 | mscorwks.dll | 
| 3.5 | 2.0 | mscorwks.dll | 
| 4.0 | 4.0 | clr.dll | 
| 4.5 | 4.0 | clr.dll | 
Debugging Managed Code
To debug managed code, the debugger must load these two components.
- Data access component (DAC) (mscordacwks.dll)
- SOS debugger extension (sos.dll)
Note For all versions of the .NET Framework, the filename of the DAC is mscordacwks.dll, and the filename of the SOS debugger extension is sos.dll.
Loading mscordacwks.dll and sos.dll (live debugging)
Assume that the debugger and the application being debugged are running on the same computer. Then the .NET Framework being used by the application is installed on the computer and is available to the debugger.
The debugger must load a version of the DAC that is the same as the version of the CLR that the managed-code application is using. The bitness (32-bit or 64-bit) must also match. The DAC (mscordacwks.dll) comes with the .NET Framework. To load the correct version of the DAC, attach the debugger to the managed-code application, and enter this command.
.cordll -ve -u -l
The output should be similar to this.
CLRDLL: Loaded DLL C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscordacwks.dll
CLR DLL status: Loaded DLL C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscordacwks.dllTo verify that the version of mscordacwks.dll matches the version of the CLR that the application is using, enter one of the following commands to display information about the loaded CLR module.
lmv mclr (for version 4.0 of the CLR)
lmv mscorwks (for version 1.0 or 2.0 of the CLR)
The output should be similar to this.
start             end                 module name
000007ff`26710000 000007ff`2706e000   clr        (deferred)
    Image path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
...In the preceding example, notice that the version of the CLR (clr.dll) matches the version of the DAC (mscordacwks.dll): v4.0.30319. Also notice that both components are 64-bit.
When you use .cordll to load the DAC, the SOS debugger extension (sos.dll) might get loaded automatically. If sos.dll doesn't get loaded automatically, you can use one of these commands to load it.
.loadby sos clr (for version 4.0 of the CLR)
.loadby sos mscorwks (for version 1.0 or 2.0 of the CLR)
As an alternative to using .loadby, you can use .load. For example, to load version 4.0 of the 64-bit CLR, you could enter a command similar to this.
.load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll
In the preceding output, notice that the version of the SOS debugger extension (sos.dll) matches the version of the CLR and the DAC: v4.0.30319. Also notice that all three components are 64-bit.
Loading mscordacwks.dll and sos.dll (dump file)
Suppose you use the debugger to open a dump file (of a managed-code application) that was created on another computer.
The debugger must load a version of the DAC that is the same as the version of the CLR that the managed-code application was using on the other computer. The bitness (32-bit or 64-bit) must also match.
The DAC (mscordacwks.dll) comes with the .NET Framework, but let's assume that you do not have the correct version of the .NET Framework installed on the computer that is running the debugger. You have three options.
- Load the DAC from a symbol server. For example, you could include Microsoft's public symbol server in your symbol path.
- Install the correct version of the .NET Framework on the computer that is running the debugger.
- Get the correct version of mscordacwks.dll from the person who created the dump file (on another computer) and manually copy it to the computer that is running the debugger.
Here we illustrate using Microsoft's public symbol server.
Enter these commands.
.sympath+ srv* (Add symbol server to symbol path.)
!sym noisy
.cordll -ve -u -l
The output will be similar to this.
CLRDLL: Unable to get version info for 'C:\Windows\Microsoft.NET
   \Framework64\v4.0.30319\mscordacwks.dll', Win32 error 0n87
SYMSRV:  C:\ProgramData\dbg\sym\mscordacwks_AMD64_AMD64_4.0.30319.18010.dll
   \5038768C95e000\mscordacwks_AMD64_AMD64_4.0.30319.18010.dll not found
SYMSRV:  mscordacwks_AMD64_AMD64_4.0.30319.18010.dll from
   http://msdl.microsoft.com/download/symbols: 570542 bytes - copied
...
SYMSRV:  C:\ProgramData\dbg\sym\SOS_AMD64_AMD64_4.0.30319.18010.dll
   \5038768C95e000\SOS_AMD64_AMD64_4.0.30319.18010.dll not found
SYMSRV:  SOS_AMD64_AMD64_4.0.30319.18010.dll from
   http://msdl.microsoft.com/download/symbols: 297048 bytes - copied
...
Automatically loaded SOS Extension
...In the preceding output, you can see that the debugger first looked for mscordacwks.dll and sos.dll on the local computer in C:\Windows\Microsoft.NET and in the symbol cache (C:\ProgramData\dbg\sym). When the debugger did not find the correct versions of the files on the local computer, it retrieved them from the public symbol server.
To verify that the version of mscordacwks.dll matches the version of the CLR that the application was using, enter one of the following commands to display information about the loaded CLR module.
lmv -mclr (for version 4.0 of the CLR)
lmv -mscorwks (for version 1.0 or 2.0 of the CLR)
The output should be similar to this.
start             end                 module name
000007ff`26710000 000007ff`2706e000   clr        (deferred)
    Image path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
...In the preceding example, notice that the version of the CLR (clr.dll) matches the version of the DAC (mscordacwks.dll): v4.0.30319. Also notice that both components are 64-bit.
Using the SOS Debugger Extension
To verify that the SOS debugger extension loaded correctly, enter the .chain command.
0:000> .chain
Extension DLL search Path:
...
Extension DLL chain:
    C:\ProgramData\dbg\sym\SOS_AMD64_AMD64_4.0.30319.18010.dll\...
        ...
    dbghelp: image 6.13.0014.1665, API 6.2.6, built Wed Dec 12 03:02:43 2012
...To test the SOS debugger extension, enter !sos.help. Then try one of the command provided by the SOS debugger extension. For example, you could try !sos.DumpDomain or the !sos.Threads command.
Notes
Sometimes a managed-code application loads more than one version of the CLR. In that case, you must specify which version of the DAC to load. For more information, see .cordll.
The Windows 8 Debugging Tools for Windows package does not include any version of sos.dll. For version 1.x of the .NET Framework, sos.dll is not included in the .NET Framework installation. To get sos.dll for .NET Framework 1.x, download the Windows 7 Debugging Tools for Windows package. For later versions of .NET Framework , sos.dll is included in the .NET Framework installation.
Send comments about this topic to Microsoft
Build date: 7/8/2013
© 2013 Microsoft. All rights reserved.
使用Windows Debugger调试托管代码----引用自官方帮助文档的更多相关文章
- Git教程(2)官方命令文档及常用命令表
		http://www.cnblogs.com/angeldevil/archive/2013/11/26/3238470.html 1,官方命令文档 http://www.git-scm.com/do ... 
- FMDB官方使用文档-GCD的使用-提高性能(翻译)
		FMDB官方使用文档-GCD的使用-提高性能(翻译) 发布于:2013-08-19 10:01阅读数:13395 由于FMDB是建立在SQLite的之上的,所以你至少也该把这篇文章从头到尾读一遍.与此 ... 
- Umbraco官方技术文档 中文翻译
		Umbraco 官方技术文档中文翻译 http://blog.csdn.net/u014183619/article/details/51919973 http://www.cnblogs.com/m ... 
- Azkaban2官方配置文档
		最近工作实在是太忙了,我把之前翻译的官方的文档先放上来吧,希望对大家有所帮助~ 介绍 Azkaban2新功能: 1.Web UI 2.简单工作流上传 3.更容易设置job的依赖关系 4.调度工作流 5 ... 
- .Net 官方学习文档
		.Net 官方学习文档:https://docs.microsoft.com/zh-cn/dotnet/articles/welcome 
- pycharm中查看快速帮助和python官方帮助文档
		把光标放在要查询的对象上,打开视图菜单,quick definition查看对象的定义,quick documentation 快速文档,这个是jet brains自己对python的解释文档,第三个 ... 
- Java日志框架-Logback手册中文版以及官方配置文档教程
		Logback手册中文版:(链接: https://pan.baidu.com/s/1bpMyasR 密码: 6u5c),虽然版本有点旧,但是大体意思差不多,先用中文版了解个大概,然后一切最新的配置以 ... 
- Ext js-02 -官方API文档使用
		官方API文档地址: http://docs.sencha.com/extjs/6.5.3/classic/Ext.html 打开网页如下: 1.选择所使用的Ext js版本,后面offline do ... 
- hugo官方相关文档地址
		+++ date="2020-10-17" title="hugo官方相关文档地址" tags=["hugo"] categories=[& ... 
随机推荐
- 洛谷 [P2964] 硬币的游戏
			博弈论+dp 依旧是博弈论的壳子,但问的是最大值,所以要dp 设 dp[i][j] 表示该取 i 号硬币,上一次取了 j 个的先手能取的最大值, 因为每次从小到大枚举复杂度太高,所以我们要从 dp[i ... 
- float类型的使用
			将身高字段设置为float类型,保留一位小数: ALTER TABLE `user` CHANGE `height` `height` FLOAT(4,1) UNSIGNED NOT NULL DEF ... 
- ZOJ - 4019 Schrödinger's Knapsack (背包,贪心,动态规划)
			[传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5747 [题目大意]:薛定谔的背包.薛定谔的猫是只有观测了才知道猫的死 ... 
- 内核调试 SystemTap
			http://www.cnblogs.com/wangkangluo1/archive/2012/06/26/2562971.html 相关技术:utrace, probe, ftrace, dt ... 
- tcp ip协议讲解
			http://blog.csdn.net/zhangskd/article/details/7174682 
- 老系统优化同步导入10w+Excel数据 秒级
			背景:老系统asp.net 2.0项目使用客户反应,某个业务每个月导入数据操作很慢,大致需要15-30分钟才会导入完毕: 分析:导入慢的原因: .数据量过大,且采用的是同步,单个excel shee ... 
- linux命令stat,查看文件详细信息
			可以查看文件的各类具体信息:文件权限的数字形式0664:uid.gid的权限的数字形式等 更多用法参考stat --help lsattr test.sh 查看文件的其他属性:只读属性.只可以追加写属 ... 
- MongoDB下配置用户权限
			MongoDB默认设置为无权限訪问限制 注:研究成果基于Windows平台 在部署mongodb成功后.进入控制台: 输入命令:mongod use admin,你会发现该DB下包括了一个syste ... 
- Js学习第十天----函数
			函数 什么是函数?函数是由事件驱动的或者当他被调用时运行的可反复使用代码块.预计没明确,个人觉得函数就是能完毕一个功能的代码块. 看个案例: <!DOCTYPE html> <htm ... 
- 第二种BitBand操作的方式 - 让IDE来帮忙算地址
			要使用Bitband来訪问外设,一定要得出相应的映射地址.人工计算肯定是不靠谱的,并且也没人想这么干.因此能够通过Excel,拉个列表来计算.想想,这也是一个不错的招数.可是后来想想,还是嫌麻烦,毕竟 ... 
