WinDbg安装入坑2(C#)

由于作者水平有限,如有写得不对的地方,请指正。

使用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无果 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zxy2847225301

测试使用

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值