如何使用WinDbg分析VC的故障转储++ 应用?

发布于 2024-07-16 14:57:28 字数 93 浏览 8 评论 0原文

如何使用 WinDbg 分析转储文件?

How do I use WinDbg for analyzing a dump file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沦落红尘 2024-07-23 14:57:28

以下是一些可以帮助您入门的常规步骤:

首先,您必须更改编译器的设置,以便它创建 PDB 文件,即使对于发布版本也是如此。 更高版本的 Visual C++ 编译器默认执行此操作,但在许多版本的 Visual C++ 中,您必须你自己做吧。 创建程序数据库文件,然后将这些文件与应用程序的每个构建一起存档。 至关重要的是,应用程序的每个构建都有自己的一组 PDB。 例如,您不能仅仅重复使用在构建 10 中创建的相同内容来检查构建 15 生成的转储。 在项目的整个生命周期中,您最终将得到大量的 PDB,因此请为此做好准备。

接下来,您需要能够识别生成转储文件的应用程序的确切版本。 如果您要创建自己的 MiniDump(例如,通过调用 MiniDumpWriteDump() ),最简单的方法可能是简单地将 MiniDump 文件名的一部分作为应用程序的完整版本号。 您需要有一个合理的版本编号方案才能使其发挥作用。 在我的商店中,每次自动构建器创建构建时,我们都会将所有分支的构建号加一。

现在您已收到客户发来的转储文件,您知道创建转储的应用程序的精确版本,并且您已找到此构建的 PDB 文件。

现在,您需要浏览源代码管理的历史记录并找到该软件的确切版本的源代码。 最好的方法是在每次构建时将“标签”应用到您的分支。 将标签的值设置为准确的版本号,就可以很容易在历史记录中查找。

您几乎已准备好启动 WinDbg/Visual C++:

  1. 获取该版本应用程序的完整源代码树。 将其放在硬盘驱动器上的单独位置,例如应用程序版本 1.0 build #100 的 c:\app_build_1.0.100
  2. 获取应用程序的确切版本的二进制文件,并将它们放在硬盘驱动器上的某个位置。 最简单的方法可能是安装该版本的应用程序来获取二进制文件。
  3. 将 PDB 文件放在与步骤 2 中的二进制文件相同的位置。

现在您有两个选项用于查看转储文件。 您可以使用 Visual Studio 或 WinDbg。 使用 Visual Studio 更容易,但 WinDbg 更强大。 大多数时候,Visual Studio 中的功能就足够了。

要使用 Visual Studio,您所要做的就是像打开项目一样打开转储文件。 您提供调用堆栈等。

打开后,“运行”转储文件(默认情况下为 F5),如果所有路径设置正确,它将带您直接到达崩溃的代码,为 WinDbg,您必须跳过几个环节:

  1. 启动 WinDbg
  2. 打开转储文件。 (默认情况下Ctrl + D
  3. 告诉WinDbg去获取正确的MicroSoft符号文件。 输入.symfix。 这可能需要一些时间,因为它会从互联网上下载大量内容。
  4. 告诉 WinDbg 符号(PDB 文件)在哪里。 键入 .sympath+ c:\pdblocation,将路径名替换为 PDB 文件所在的位置。 确保在 .sympath+ 符号之间添加加号,否则您将搞砸第 3 步。
  5. 告诉 WinDbg 源代码在哪里。 键入 .srcpath c:\app_build_1.0.100 替换您从该版本软件的源代码管理中获取代码的路径。
  6. 告诉 WinDbg 分析转储文件。 输入 !analyze -v

几分钟后,如果一切配置正确,WinDbg 将带您直接到达崩溃的位置。 此时,您有一百万个选项可以深入了解应用程序的内存空间、关键部分的状态、窗口等。但这方式超出了本文的范围。

祝你好运!

Here are some general steps that will get you on your way:

First, you must change your compiler's settings so that it creates PDB files, even for release builds. Later versions of the Visual C++ compiler do this by default, but in many versions of Visual C++ you must do this yourself. Create program database files, and then keep an archive of those files along with each build of your application. It is critical that every build of your applications has its own set of PDBs. You can't just reuse the same ones you made with build 10 to examining the dumps generated by build 15, for example. Over the life of your project, you will end up with a ton of PDBs, so be prepared for that.

Next, you need to be able to identify the exact version of your application which generated the dump file. If you are creating your own MiniDumps (by calling MiniDumpWriteDump() for example), probably the easiest way to do this is to simply make part of the filename of the MiniDump the complete version number of your application. You'll need to have a reasonable version numbering scheme in place for this to work. In my shop, we increment the build number across all branches by one every time the autobuilder creates a build.

Now that you have received the dump file from the customer, you know the precise version of the application that created the dump, and you have found the PDB files for this build.

Now you need to go through your source control's history and find the source code for this exact version of the software. The best way to do this is to apply 'labels' to your branches every time you make a build. Set the value of the label to the exact version number, and it becomes easy to find in the history.

You're almost ready to fire up WinDbg/Visual C++:

  1. Get the complete source tree for that version of your application. Put it in a separate place on your hard drive, say c:\app_build_1.0.100 for application version 1.0 build #100.
  2. Get the binaries for that exact version of your application and put them somewhere on your hard drive. It might be easiest simply to install that version of your application to get the binaries.
  3. Put the PDB files in the same location as the binaries in step 2.

Now you have two options for viewing the dump file. You can use Visual Studio or WinDbg. Using Visual Studio is easier, but WinDbg is much more powerful. Most of the time the functionality in Visual Studio will suffice.

To use Visual Studio, all you have to do is open the dump file like it is a project. Once opened, "run" the dump file (F5 by default) and if all the paths are set correctly it will take you right to the code that crashed, give you a call stack, etc.

To use WinDbg, you have to jump through a couple of hoops:

  1. Start WinDbg
  2. Open the dump file. (Ctrl + D by default)
  3. Tell WinDbg to go get the correct MicroSoft symbol files. Type .symfix. This may take a few moments as it will pull a ton of stuff down from the Internet.
  4. Tell WinDbg where the symbols (PDB files) are. Type .sympath+ c:\pdblocation, substituting wherever you put the PDB files for the pathname. Make sure you get the plus sign in there with no whitespace between .sympath and the + sign or else you'll screw up step 3.
  5. Tell WinDbg where the source code is. Type .srcpath c:\app_build_1.0.100 substituting the path where you got code from source control for this version of the software.
  6. Tell WinDbg to analyze the dump file. Type !analyze -v

After a few moments, if everything is configured correctly, WinDbg will take you right to the location of your crash. At this point you have a million options for digging deep into your application's memory space, the state of critical sections, windows, etc. But that is way beyond the scope of this post.

Good luck!

尝蛊 2024-07-23 14:57:28

(请参阅下面的“转储”部分)

使用 WinDbg 的基本教程和演示

“启动”/附加 WinDBG 的不同方式

工作区

了解工作区的工作原理...

Cmdtree

“cmdtree”允许您轻松定义调试器命令的“菜单”访问常用命令而无需记住简洁的命令名称。

您不必将所有命令定义放入同一个 cmdtree 文本文件中...您可以将它们分开并根据需要加载多个命令(然后它们会获得自己的窗口)。

启动脚本

您可以在命令行上使用 -c 选项启动 WinDBG 时自动运行 WinDBG 脚本。

提供打开 DML(调试器标记语言)模式、加载特定扩展、设置 .NET 异常断点、设置内核标志的机会(例如,当内核调试时,您可能需要更改 DbgPrint 掩码,以便看到跟踪信息....ed nt !Kd_DEFAULT_Mask 0xffffffff),加载cmdtree等

示例脚本:

$ Include a directory to search for extensions
$ (point to a source controlled or UNC common directory so that all developers get access)
.extpath+"c:\svn\DevTools\WinDBG\Extensions"
$ When debugging a driver written with the Windows Driver Framework/KMDF
$ load this extension that comes from the WinDDK.
!load C:\WinDDK\7600.16385.1\bin\x86\wdfkd.dll
!wdftmffile C:\WinDDK\7600.16385.1\tools\tracing\i386\wdf01009.tmf
$ load some extensions
.load msec.dll
.load byakugan.dll
.load odbgext.dll
.load sosex
.load psscor4
$ Make commands that support DML (Debugger Markup Language) use it
.prefer_dml 1
.dml_start
$ Show NTSTATUS codes in hex by default
.enable_long_status 1
$ Set default extension
.setdll psscor4
$ Show all loaded extensions
.chain /D
$ Load some command trees
.cmdtree c:\svn\DevTools\WinDBG\cmdtree\cmdtree1.txt
.cmdtree c:\svn\DevTools\WinDBG\cmdtree\cmdtree2.txt
$ Show some help for the extensions
!wdfkd.help
!psscor4.help
.help /D

命令备忘单

扩展

“扩展”允许您扩展 WinDBG 内部支持的命令/功能的范围。

编写自己的扩展

使用 WinDBG 调试托管代码

脚本(C#、PS、Python、WinDBG)

使用 dbgeng.dll API/WinDBG 工具的调试器/工具

生成故障转储文件以进行事后分析的不同方法

转储分析工具

转储相关工具

  • Citrix dumpcheck - 检查转储文件的一致性(看起来已被放弃链接 + 链接)
  • dumpchk(调试工具的一部分) - 检查转储文件的一致性
  • MoonSols Windows 内存工具包(以前的 windd) - 将各种原始内存转储文件转换为 WinDBG 兼容的 dmp 文件
  • vm2dmp - Microsoft Hyper-V VM 状态到内存转储转换器
  • vmss2core - 将 VMWare 快照文件转换为核心转储文件 (下载), (说明)

内核调试虚拟机

  • VMKD - 虚拟机 KD 扩展
  • VirtualKD -(对 VMWare/VirtualBox 中托管的操作系统的内核调试器支持)

视频

博客

一些博客(本机和托管代码调试的混合)。

高级文章和教程资源

替代调试器

其他链接

(see the "Dump" sections below)

Basic Tutorials and Demonstrations of Using WinDbg

Different Ways to "Start"/Attach WinDBG

Workspaces

Understanding how Workspaces work...

Cmdtree

A "cmdtree" allows you to define a "menu" of debugger commands for easy access to frequently used commands without having to remember the terse command names.

You don't have to put all the command definitions into the same cmdtree text file....you can keep them separate and load multiple ones if you wish (they then get their own window).

Startup Script

You can use the -c option on the command line to automatically run a WinDBG script when you start WinDBG.

Gives opportunity to turn on DML (Debugger markup language) mode, load particular extensions, set .NET exception breakpoints, set kernel flags (e.g. when kernel debugging you might need to change the DbgPrint mask so you see tracing information....ed nt!Kd_DEFAULT_Mask 0xffffffff), load cmdtrees, etc.

An example script:

$ Include a directory to search for extensions
$ (point to a source controlled or UNC common directory so that all developers get access)
.extpath+"c:\svn\DevTools\WinDBG\Extensions"
$ When debugging a driver written with the Windows Driver Framework/KMDF
$ load this extension that comes from the WinDDK.
!load C:\WinDDK\7600.16385.1\bin\x86\wdfkd.dll
!wdftmffile C:\WinDDK\7600.16385.1\tools\tracing\i386\wdf01009.tmf
$ load some extensions
.load msec.dll
.load byakugan.dll
.load odbgext.dll
.load sosex
.load psscor4
$ Make commands that support DML (Debugger Markup Language) use it
.prefer_dml 1
.dml_start
$ Show NTSTATUS codes in hex by default
.enable_long_status 1
$ Set default extension
.setdll psscor4
$ Show all loaded extensions
.chain /D
$ Load some command trees
.cmdtree c:\svn\DevTools\WinDBG\cmdtree\cmdtree1.txt
.cmdtree c:\svn\DevTools\WinDBG\cmdtree\cmdtree2.txt
$ Show some help for the extensions
!wdfkd.help
!psscor4.help
.help /D

Command Cheat Sheets

Extensions

"Extensions" allow you to extend the range of commands/features supported inside WinDBG.

Write your own extension

Using WinDBG to Debug Managed Code

Scripting (C#, PS, Python, WinDBG)

Debuggers/Tools that use the dbgeng.dll API/WinDBG Tools

Different Ways to Generate Crash Dump Files for Post-Mortem Analysis

Dump Analysis Tools

Dump related Tools

  • Citrix dumpcheck - checks consistency of dump file (looks like it's been abandoned link + link)
  • dumpchk (part of Debugging Tools) - checks consistency of a Dump file
  • MoonSols Windows Memory Toolkit (formerly windd) - converts various raw memory dump files into WinDBG compatible dmp files
  • vm2dmp - Microsoft Hyper-V VM State to Memory Dump Converter
  • vmss2core - converts VMWare snapshot file into a core dump file (download), (instructions)

Kernel Debugging Virtual Machines

  • VMKD - Virtual Machine KD Extensions
  • VirtualKD - (kernel debugger support for OS's hosted in VMWare/VirtualBox)

Videos

Blogs

Some blogs (mixture of native and managed code debugging).

Advanced Articles and Tutorial Resources

Alternative Debuggers

Other Links

司马昭之心 2024-07-23 14:57:28

这是一个非常广泛的问题。

  1. 第一步是将转储文件加载到 WinDbg 实例中。
  2. 接下来,您需要确保您有符号设置。
  3. 最后,您可以运行命令 !analyze -v 对其进行基本分析。 您需要为您的代码提供可用的符号信息,以使转储文件有价值。

网站内存转储、软件跟踪、调试、恶意软件、受害者软件和情报分析门户 对我来说信息非常丰富。 我也非常喜欢这本书,高级 Windows 调试 作者:马里奥·休沃特和丹尼尔·普拉瓦特。

This is a really broad question.

  1. The first step is to load the dump file into a WinDbg instance.
  2. Next, you need to make sure you have a symbols setup.
  3. Finally, you can run the command !analyze -v to get a basic analysis performed on it. You need to have symbol information available for your code to make dump files worthwhile.

The website Memory Dump, Software Trace, Debugging, Malware, Victimware and Intelligence Analysis Portal has been very informative for me. I also really enjoyed the book, Advanced Windows Debugging by Mario Hewardt and Daniel Pravat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文