visual-studio 为什么使用 WinDbg 与 Visual Studio (VS) 调试器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/105130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why use WinDbg vs the Visual Studio (VS) debugger?
提问by e k
回答by LanceSc
If you are wondering why you should use windbg over Visual Studio, then you need to read Advanced Windows Debugging. Any time you need to debug a truly ugly problem windbg has better technology to do it with than Visual Studio. Windbg has a more powerful scripting language and allows you to write DLLs to automate difficult problems. It will install gflags.exe, which gives you better control over the heap for debugging memory overwrites.
如果您想知道为什么应该在 Visual Studio 上使用 windbg,那么您需要阅读高级 Windows 调试。任何时候您需要调试一个真正丑陋的问题,windbg 都有比 Visual Studio 更好的技术来完成它。Windbg 拥有更强大的脚本语言,并允许您编写 DLL 来自动处理困难的问题。它将安装 gflags.exe,这使您可以更好地控制堆以调试内存覆盖。
You don't actually need to run the install, you can just copy the files over and be ready to go. Also it installs adsplus.vb, so you can take mini-dumps of running processes. It is also very easy to setup to perform remote debugging. There is nothing better than being able to debug a problem from your own desk instead of fighting the 15" monitor that flickers on a test PC.
您实际上并不需要运行安装,您只需将文件复制过来即可。它还安装了 adsplus.vb,因此您可以对正在运行的进程进行小型转储。设置执行远程调试也很容易。没有什么比在自己的办公桌上调试问题更好的了,而不是与在测试 PC 上闪烁的 15 英寸显示器作斗争。
For day to day code writing I use Visual Studio, but once you need to start debugging problems from other computers or find yourself in a very ugly situation, windbg is the only way to go. Spending some time learning windbg is a great investment. Also if you look at crash dumps there are two great resources, http://www.dumpanalysis.org/blogand http://blogs.msdn.com/ntdebugging/default.aspxthat do all their debugging using windbg.
对于日常代码编写,我使用 Visual Studio,但是一旦您需要从其他计算机开始调试问题或发现自己处于非常糟糕的情况,windbg 是唯一的出路。花一些时间学习windbg 是一项很好的投资。此外,如果您查看故障转储,有两个很棒的资源,http ://www.dumpanalysis.org/blog和http://blogs.msdn.com/ntdebugging/default.aspx,它们使用 windbg 进行所有调试。
回答by Hyman Bolding
Here are some further links to help with using WinDbg, most are .NET specific.
这里有一些进一步的链接来帮助使用WinDbg,大多数是 .NET 特定的。
- John Robbins talks about using cmdtreeto create a command window.
- Here is a quick WinDbg/SOS cheat sheet.
- If broken it is, fix it you shouldhas a bunch of WinDbg/Sosrelated articles, mainly around debugging ASP.NET.
- Hereis an old overview of SOS from MSDN mag. It is about .NET 1.1 so its age is showing.
- John Robbins 谈到使用cmdtree创建命令窗口。
- 这是一个快速的WinDbg/SOS 备忘单。
- 如果坏了,修复它你应该有一堆WinDbg/Sos相关的文章,主要是关于调试 ASP.NET。
- 这是 MSDN mag 中 SOS 的旧概述。它是关于 .NET 1.1 的,所以它的年龄正在显现。
回答by Martin
You don't specify whether you're debugging native or managed code. It doesn't affect the answer, WinDbg is extremely useful for both, but many people believe that WinDbg is somehow less relevant when debugging .NET apps. Not so. As a bonus, you can learn a lot about how the .NET platform works by debugging your .NET app in WinDbg with the SOS extension. Run up (or attach to) your .NET app in WinDbg and type...
您没有指定是调试本机代码还是托管代码。它不会影响答案,WinDbg 对两者都非常有用,但许多人认为 WinDbg 在调试 .NET 应用程序时不太相关。不是这样。作为奖励,您可以通过使用 SOS 扩展在 WinDbg 中调试 .NET 应用程序来了解 .NET 平台的工作原理。在 WinDbg 中运行(或附加到)您的 .NET 应用程序并键入...
.loadby sos mscorwks
...to be sure that you load the right extension for the version of the CLR in use. Then type...
...确保为正在使用的 CLR 版本加载正确的扩展。然后输入...
!help
... to see what commands are available in the SOS extension.
...查看 SOS 扩展中有哪些可用的命令。
I've heard it joked that Microsoft only has one developer tool, and it's WinDbg. Everything you could possibly want for debugging is in there, or in an extension. Sure, a subset of those things are also available in VS with a friendlier UI... :-)
我听说有人开玩笑说微软只有一个开发者工具,那就是 WinDbg。您可能需要用于调试的所有内容都在那里,或在扩展中。当然,这些东西的一个子集也可以在具有更友好 UI 的 VS 中使用... :-)
回答by Rob
I have used it when I've been sent .dmp files from an NT4.0 server - MSVC won't load these old format files.
我在收到来自 NT4.0 服务器的 .dmp 文件时使用过它 - MSVC 不会加载这些旧格式文件。
回答by JeffJ
Mixing kernel-debugging plus remote-user-mode-debugging.
混合内核调试和远程用户模式调试。
AFAIK, visual studio stillcannot do remote debugging in the mode I describe as "solution". That's a darn good reason to use windbg.
AFAIK,visual studio仍然无法在我描述为“解决方案”的模式下进行远程调试。这是使用windbg的一个很好的理由。
Problem:
问题:
- Set up windbg across 1394. Your app runs on the "target". Windbg runs on the "host".
- Run visual studio on the host
- Have visual studio launch your app on the target using the remote tools.
- Break into the kernel mode windbg to halt the target
- Wait long enough for visual studio's TCP connection to timeout
- "g" in windbg to un-halt the target
- observe your app "pop" when the remote monitor realizes the network connection is gone
- restart your app :(
- 跨 1394 设置 windbg。您的应用程序在“目标”上运行。Windbg 在“主机”上运行。
- 在主机上运行visual studio
- 让 Visual Studio 使用远程工具在目标上启动您的应用程序。
- 闯入内核模式windbg停止目标
- 等待足够长的时间让 Visual Studio 的 TCP 连接超时
- 在windbg中使用“g”来停止目标
- 当远程监视器意识到网络连接消失时,观察您的应用程序“弹出”
- 重新启动您的应用程序:(
Solution:
解决方案:
- Don't use visual studio.
- Run a user mode windbg on the target with "-server"
- Have the target's windbg launch your app.
- On the host, start a 2nd windbg that connects to target with "-remote".
- If the TCP connection dies just start another windbg instance on the host and nothing is lost. Your app didn't die because the controlling user mode windbg process is running on the target.
- 不要使用视觉工作室。
- 使用“-server”在目标上运行用户模式windbg
- 让目标的 windbg 启动您的应用程序。
- 在主机上,启动第二个使用“-remote”连接到目标的 Windbg。
- 如果 TCP 连接终止,只需在主机上启动另一个 windbg 实例,不会丢失任何内容。您的应用程序没有死,因为控制用户模式的 Windbg 进程正在目标上运行。
Also, I find it easier to use the same debugger for both kernel mode and user mode, windbg is very powerful even in user mode, and I can leverage my own windbg extensions in both kernel mode and user mode instances.
此外,我发现在内核模式和用户模式下使用相同的调试器更容易,即使在用户模式下,windbg 也非常强大,而且我可以在内核模式和用户模式实例中利用我自己的 Windbg 扩展。
回答by JeffJ
Is the latest visual studio still missing an equivalent to windbg's "-o" that makes the debugger automatically attach to child processes? Very useful for apps that must be run from a complicated .bat file, or apps that fork and exit the parent process.
最新的visual studio 是否仍然缺少与windbg 的“-o”等效的使调试器自动附加到子进程的功能?对于必须从复杂的 .bat 文件运行的应用程序或 fork 并退出父进程的应用程序非常有用。
回答by Nemanja Trifunovic
Lightweight, can be run without installing it on a client's machine, fast, can debug kernel mode.
轻量级,无需在客户端机器上安装即可运行,速度快,可调试内核模式。
回答by C Johnson
I always liked the watch and trace feature: 'wt' -> It prints to the output window all the function calls as they happen. That was pretty cool stuff!
我一直很喜欢监视和跟踪功能:'wt' -> 它会在所有函数调用发生时将它们打印到输出窗口。那是很酷的东西!

