第三十篇:Windbg的基础知识

来源:互联网 发布:java包装简历 编辑:程序博客网 时间:2024/05/17 07:56

Windbg是一个非常强大的工具.


刚刚开始,是为了替代SoftICE调试自己开发的AVStream/BDA驱动程序,以及分析由此驱动软件产生的Kernel Dump.


之后,参与xHCI USB3.0/3.1 IP的开发,Windbg主要用来分析该硬件产生的Kernel Dump.

第二篇:欲善其事,先利其器-USB3.0 Kernel debug extension

第五篇:风起于青萍之末-电源管理请求案例分析(上, 中, 下)

第十三篇:无征不信,不信民弗从--USB-IF官方驱动BSOD案例分析

这五篇博文是对其中几个实例的分析过程。


最近,参与了一个用户模式的DLL的开发,虽然是用户模式的DLL,但由于涉及到显示驱动、显示后台服务程序方面的相关联的操作,于是,又开始使用了Windbg.

通过Windbg的NET方式双机调试DLL。

使用Windbg来分析DLL产生的user mode application dump.

以及通过Windbg来产生kernel dump,以便进一步分析显示服务&DLL crash时的系统状态与原因。


Windbg调试在实际工作中的需要,加上朋友的推荐, 买了两本张银奎的调试方面的书籍

《Software debugging》, 《格蠹汇编》, 有兴趣的朋友,可以借以参考。


这篇博文,主要将一些基本概念作一梳理:

第一方面,关于modes与targets

大家在看Windbg的帮助文档的时候,每一条命令都会包括modes, targets.

这里所说的modes包括user mode与kernel mode。

典型的user mode为,在Windbg--> File--> Open Executable与Windbg-->File-->Attach to a Process, 调试目标(debugee)是应用程序,此时调试器(debugger)运行在user mode下。

所有双机调试(包括USB2,USB3,1394,NET,COM)以及Local(debugger, debugee运行在同一系统中)都是在kernel mode下。

注:本人没用过虚拟机的双机调试


kernel mode与user mode的差别:

部分命令只能运行在KERNEL MODE,部分命令只能运行在USER MODE, 还有其它部分则在两种MODE下都能运行。

除了Local kernel mode debug(另当别论,可以认为是双机调式下的KERNEL MODE的一个子集功能), 其它双机联调方式在目标系统中断到调试器后,则整个目标系统都处于停止状态; 而user mode下针对于一个Application的调试,在目标进程中断到调试器时,只是调试目标处于停止状态,系统中的其它进程仍然在正常运行。


再说一下Targets

这里所指的targets可以分成两类

一类为live,另一类为crash dump.

所谓的live,则包括了双机调试,local kernel debug, 与user mode debug, 可以理解为一个动态的概念。

而crash dump,无论是kernel dump,还是user application dump,都归到crash dump一类,这是对静态系统的分析。


第二,关于32bit与64bit Windbg的使用选择。

这里参照Windbg帮助文档的:

Choosing the 32-Bit or 64-Bit Debugging Tools

Host computer running a 32-bit version of Windows

If your host computer is running a 32-bit version of Windows, use the 32-bit debugging tools. (This situation applies to both x86-based and x64-based targets.)

x64-based host computer running a 64-bit version of Windows

If your host computer uses an x64-based processor and is running a 64-bit version of Windows, the following rules apply:

  • If you are analyzing a dump file, you can use either the 32-bit debugging tools or the 64-bit debugging tools. (It is not important whether the dump file is a user-mode dump file or a kernel-mode dump file, and it is not important whether the dump file was made on an x86-based or an x64-based platform.)

  • If you are performing live kernel-mode debugging, you can use either the 32-bit debugging tools or the x64 debugging tools. (This situation applies to both x86-based and x64-based targets.)

  • If you are debugging live user-mode code that is running on the same computer as the debugger, use the 64-bit tools for debugging 64-bit code and 32-bit code running on WOW64. To set the debugger for 32-bit or 64-bit mode, use the .effmach command.

  • If you are debugging live 32-bit user-mode code that is running on a separate target computer, use the 32-bit debugging tools.


这里作了比较清楚的说明,首先,如果主机运行的是32位WINDOWS系统,则只有X86 WINDBG可以使用。

如果主机是X64 CPU, 而且运行的是64位WINDOWS系统(X86硬件不能安装64位系统,但X64硬件可以安装32位系统),则有如下情况:

对于dump file分析,无论该DUMP FILE是KERNEL还是USER, 也不管该DUMP产生的目标机是X86还是X64(这个PLATFORM如何理解?), X86 X64 WINDBG都可以用来分析该DUMP.

对于live kernel mode, 也是不管目标是X86还是X64(这个TARGETS如何理解?),都可以使用。

对于live user mode, 使用64 WINDBG调试64BIT代码(与运行在WOW64位上的32BIT代码),使用32 WINDBG调试运行在目标机上的32BIT代码。


不过,按照实际的试验,存在以下有待考证的地方:

1. 在LOCAL KERNEL DEBUG情况下, 笔者的主机是WIN7 64系统, 笔者发现,只能运行X64, 不能运行X86。(与上文第二点有出入)

2. 在WIN7 64系统下,USER MODE DEBUGGING, 无论是X86还是X64 WINDBG都可以调试Windows/system32目录下的calc.exe.(与上文第三点有出入)








0 0
原创粉丝点击