由于作者水平有限,如有写得不对的地方,请指正。
使用WinDbg的过程中,坑特别的多,对版本要求比较严格,如:
1 32位应用程序导出的Dump文件要用32位的WinDbg打开,想要没有那么多的问题,还得要求用32位的任务管理器导出Dump文件,32位的任务管理器的路径如下:C:\Windows\SysWOW64\taskmgr.exe
2 64位应用程序导出的Dump文件要用64位的WinDbg打开
3 没指定位数的程序(如AnyCPU)导出的文件要用64位的WinDbg打开
本文目的:
使用C#编写一段程序,并用64位的任务管理器导出为AnyCPU的Dump文件,试一下WinDbg Preview和老版的WinDbg在使用过程中的坑
本文测试环境:
.net framework 3.5
vistual studio 2017
win10 64位操作系统
步骤如下:
1 新增C# .net framework 控制台程序,选择.net framework 3.5 ,项目名称为:WindbgDemo,并编写代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace WindbgDemo
{
class Program
{
private static string _csdnUrl = "https://www.csdn.net/";
public static string BaiDuUrl = "https://www.baidu.com/";
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem((a) => {
new DownLoadBp().DownLoadOperation(BaiDuUrl);
});
//堵塞主线程
string readRet=Console.ReadLine();
Console.WriteLine("主线程读取到的结果:" + readRet);
Console.ReadKey(true);
}
}
public class DownLoadBp
{
public void DownLoadOperation(string url)
{
Console.WriteLine("子线程:url地址:"+url);
string readRet = Console.ReadLine();
//堵塞子线程
Console.ReadKey(true);
Console.WriteLine("子线程读取到的结果:" + readRet);
}
}
}
2 生成程序,先打开任务管理器(由于是win10的64位操作系统,所以默认打开的是64位的任务管理器),再打开应用程序,Dump出转储文件,如下图:
2.1 使用WinDbg Preview打开Dump文件
目标平台这里我们选择Autodetect(自动检测)
输入.load sos和!threads后,还是会提示No export threads found,如下图:
从网上了解到,可能是sos.dll的版本不对,那么我们手工导入sos.dll
当我们输入:
.load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll
没有报错,再次输入!threads会看到报如下的错误:
Failed to find runtime DLL (clr.dll), 0x80004005 Extension commands need clr.dll in order to have something to do.
不管是使用.load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll还是使用
.load C:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll 都会报这个错误。
可能是我们导入的sos版本不对,由于我们的应用程序是.net framework 3.5 的,可以试试
.load C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll
发现还是不行:
只能退出重新选择目标平台再进来,这次选择x64
当输入:.load C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll
会报如下的错误:
The call to LoadLibrary(C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll) failed, Win32 error 0n193
"%1 不是有效的 Win32 应用程序。"
Please check your debugger configuration and/or network access.
如下图:
当我们输入:
.load C:\Windows\Microsoft.NET\Framework64\v2.0.50727\SOS.dll
!threads
可以看到线程输出信息了,如下图:
利用命令:
~~[28a8]s
切换到28a8线程,如下图:
利用!clrstack查看该线程的堆栈,如下图:
当我们以x86的方式进入:
当我们输入:
.load C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll
!threads
后发现会报如下的错误:
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.
碰到这个错误网上的说法是,使用32位的任务管理器导出dump文件或者切换windbg的位数
2.2 使用老版的WinDbg(32位的)来测试
输入:
.load C:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll
!threads
后会报如下的错误:
SOS does not support the current target architecture.
网上有博主给出这样的解决方案:
从提示信息中可以看出,当前的sos并不支持目标架构,只能输入2.0版本的sos
输入:
.load C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll
!threads
再次出现错误:
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.
使用 .load soswow64命令(后面的文章有介绍)和!wow64exts.sw问题一样存在
使用老版32位的WinDbg无果