有2个方式可以安装WinDbg。
新版 安装WinDbg Preview
在商店里搜WinDbg直接就可以安装,这里安装的版本是x64版本。x64版本的WinDbg其实是可以调试x86版本的程序,直接附加到进程就可以了,这也是我们推荐的方式。
旧版 安装windows sdk
由于官方不提供独立的旧的WinDbg安装方式,需要安装Windows sdk。
参考链接:
Download the Windows Driver Kit (WDK) - Windows drivers | Microsoft Docs
或者可以直接下载6.0打包好的版本云盘:pan.baidu.com/s/1VqXVIGVH… 提取码:mahg
这里建议新旧两个版本都安装,实际调试时候都可能需要用到。
配置: 增加系统环境变量: _NT_SYMBOL_PATH
对应的值为:
SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols
加载SOS.dll
SOS是在ntsd或windbag下调试.Net程序的扩展。有两种方式可以加载。
.loadby
一般使用.loadby sos clr
(针对.net framework 4.x)没有报错就代表正确加载了。实际上根据情况有如下几种选择:
.loadby sos mscorsvr
.loadby sos mscorwks
.loadby sos clr
.loadby sos coreclr
.loadby sos <somethingelse>
如何选择参考链接: .net - Cannot .loadby sos mscorwks or .loadby sos clr - Stack Overflow
.loadby
对第一种方式的不能正确加载的情况,可以自行加载,使用方式如下:
.load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll
接下来就能愉快的使用!eeheap等命令调试了。
注意:不要在.net clr还没有加载的时候就尝试加载sos 键入g
直到clr加载后再中断重新加载sos.dll。
如果只调试自己电脑上的程序那么一般情况比较简单,但调试客户的程序会遇到各种各样的情况。例如如下两种最常见的场景。
有时我们在生成项目时,选择了优先32位。生成32的程序在我们现在的64位环境下,会运行在wow64下。
这个时候我们是可以直接使用x64版本的windbg直接附加到进程调试的,但是对客户的机器上的程序,我们很多时候都需要生成dump来分析当时的问题。直接用默认的64位任务管理器生成的dump并不能直接分析,给bug的分析带来很多困难。我们可能会看到如下提示信息。
0:000> !eeheap
SOS does not support the current target architecture.
或者,
Failed to load data access DLL, 0x80004005
Verify that 1) you have a recent build of the debugger (6.2.14 or newer)
2) the file mscordacwks.dll that matches your version of mscorwks.dll is
in the version directory
3) or, if you are debugging a dump file, verify that the file
mscordacwks_<arch>_<arch>_<version>.dll is on your symbol path.
4) you are debugging on the same architecture as the dump file.
For example, an IA64 dump file must be debugged on an IA64
machine.
You can also run the debugger command .cordll to control the debugger's
load of mscordacwks.dll. .cordll -ve -u -l will do a verbose reload.
If that succeeds, the SOS command should work on retry.
If you are debugging a minidump, you need to make sure that your executable
path is pointing to mscorwks.dll as well.
按照提示输入.cordll -ve -u -l
后有如下提示。
.cordll -ve -u -l
CLR DLL status: No load attempts
使用windbg preview时可以在堆栈中看到wow64等字样就是遇到了这种问题。
我们可以通过如下方式解决:
有时调试的目标dump的clr版本与本地并不相符,使用 .cordll -ve -u -l
命令有如下类似提示。
unable to find mscordacwks_x86_x86_4.7.3110.00.dll by mscorwks search
可以按提示拷贝目标机器上的相应dll,重命名后放到windbg的目录下。
参考:
Windbg调试SOS.DLL和CLR 不匹配问题_SpringDou的博客-CSDN博客
能在vs下使用sos扩展么?
现在版本的vs已经不支持加载sos了,但是可以使用稍旧版本vs并配合如下扩展。(未测试过)
可以使用哪些sos命令?
参考官方文档:SOS.dll (SOS Debugging Extension) - .NET Framework | Microsoft Docs
手机扫一扫
移动阅读更方便
你可能感兴趣的文章