基本环境搭建及安装

安装

有2个方式可以安装WinDbg。

  1. 新版 安装WinDbg Preview

    在商店里搜WinDbg直接就可以安装,这里安装的版本是x64版本。x64版本的WinDbg其实是可以调试x86版本的程序,直接附加到进程就可以了,这也是我们推荐的方式。
  2. 旧版 安装windows sdk

这里建议新旧两个版本都安装,实际调试时候都可能需要用到。

配置与调试

  • 配置: 增加系统环境变量: _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。

特殊情况的处理

如果只调试自己电脑上的程序那么一般情况比较简单,但调试客户的程序会遇到各种各样的情况。例如如下两种最常见的场景。

1. 32位兼容程序的调试

有时我们在生成项目时,选择了优先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等字样就是遇到了这种问题。

我们可以通过如下方式解决:

    1. 使用32位的任务管理器重新抓dump。

      32位任务管理器位于 C:\Windows\SysWOW64\Taskmgr.exe下。参考链接:.Net Dump 的分析 I | 非洲海星的深海大鳳梨 (wordpress.com)
    1. 使用soswow64加载sos

      这里一定要使用旧版的windbg x86版本并下载soswow64放到指定目录下。

      使用 .load soswow64 加载后就能使用sos中的扩展命令。github中的readme说的非常清楚。

参考链接:poizan42/soswow64: windbg/dbgeng extension for debugging 64-bit dumps of 32-bit .NET processes. (github.com)

2. clr运行环境不符的调试

有时调试的目标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博客

Q&A

其他参考链接

  1. dotnet core下的配置。教你配置windows上的windbg,linux上的lldb,打入clr内部这一篇就够了 - 掘金 (juejin.cn)
  2. windbg - Failed to load data access DLL, 0x80004005 - Stack Overflow
  3. "Failed to load data access DLL, 0x80004005" when debugging a live process on local machine (microsoft.com)
  4. How to use Windbg to debug a dump of a 32bit .NET app running on a x64 machine - PKI Extensions (sysadmins.lv)
  5. visual studio 2010 - Debugging dump of 32-bit process captured on 64-bit machine - Stack Overflow
  6. 调试运行在Wow64子系统下的程序----x64版windbg调试win32程序_lixiangminghate的专栏-CSDN博客

最新文章

  1. js立即调用的函数表达式
  2. CSAPP学习笔记(异常控制流1)
  3. java:JDBC详解
  4. Framework7 – 赞!功能齐全的 iOS7 App 前端框架
  5. 航空货运:运价类别Rate Class
  6. 【BZOJ-3626】LCA 树链剖分
  7. Android签名总结
  8. 2016年11月25日 星期五 --出埃及记 Exodus 20:16
  9. spring boot 1.4默认使用 hibernate validator
  10. BZOJ_1833_[ZJOI2010]_数字计数_(数位dp)
  11. Linux系统编程(37)—— socket编程之原始套接字
  12. JDK源码学习--String篇(二) 关于String采用final修饰的思考
  13. 基于jQuery带标题的图片3D切换焦点图
  14. SignalR系列教程:服务器广播与主动数据推送
  15. 【转】哦,mysql 的其它发行版本Percona, mariadb
  16. Java经典案例之-“分解质因数”
  17. 多个 (li) 标签如何获取获取选中的里面的某个特定值??
  18. 学习CSS布局 - position
  19. js----DOM对象(3
  20. centos7 新装系统网络配置

热门文章

  1. new方法实现原理
  2. STP的究极进化MSTP
  3. k8s之Dashboard插件部署及使用
  4. Docker的数据管理、网络通信和dockerfile
  5. JUC并发包学习
  6. Linux 基础练习题
  7. Solution -「CF 232E」Quick Tortoise
  8. Vue脚手架报错 Component name &quot;Student&quot; should always be multi-word vue/multi-word-component-names
  9. Linux海王 之 pdsh (并行管理工具)
  10. Kubeadm部署-Kubernetes-1.18.6集群