如何使用Visual Studio调试进程?

时间:2022-07-31 01:32:51

If an application† crashes,

如果应用程序†崩溃,

如何使用Visual Studio调试进程?

I hit "Debug" and Visual Studio is my currently registered Just-In-Time (JIT) debugger:

我点击“Debug”,Visual Studio是我当前注册的实时(JIT)调试器:

如何使用Visual Studio调试进程?

Visual Studio appears, but there's no way to debug anything:

Visual Studio出现,但没有办法调试任何东西:

如何使用Visual Studio调试进程?

  • I do not see any disassembly
  • 我没有看到任何反汇编

  • I do not see any registers (assuming it runs on a CPU with registers)
  • 我没有看到任何寄存器(假设它在带寄存器的CPU上运行)

  • The call stack is empty (assuming the CPU has a stack pointer)
  • 调用堆栈为空(假设CPU有堆栈指针)

  • I do not see any symbols (assuming it had any)
  • 我没有看到任何符号(假设它有任何符号)

  • I do not see reconstructed source code from reflection (assuming it was managed)
  • 我没有看到反射的重构源代码(假设它被管理)

Other JIT debugger products are able to show disassembly, but they are either command-line based (Debugging Tools for Windows), or do not support symbols (OllyDbg, Delphi). Additionally, my question is about debugging using Visual Studio, since I already have it installed, and it is already my registered JIT.

其他JIT调试器产品能够显示反汇编,但它们是基于命令行的(Windows调试工具),或者不支持符号(OllyDbg,Delphi)。另外,我的问题是关于使用Visual Studio进行调试,因为我已经安装了它,它已经是我注册的JIT了。

How do you debug a program using Visual Studio?

如何使用Visual Studio调试程序?

Alternatively: has anyone written a graphical debugger that supports the Microsoft symbol server?

或者:有没有人写过支持Microsoft符号服务器的图形化调试器?

† Not, necessarily, written in Visual Studio.

†不一定是用Visual Studio编写的。

Edit: Changes title to process rather than application, since the latter somehow implies "my application."

编辑:将标题更改为进程而不是应用程序,因为后者以某种方式暗示“我的应用程序”。

Edit: Assume the original application was written in assembly language by Steve Gibson. That is, there is no source code or debug information. Visual Studio should still be able to show me an assembly dump.

编辑:假设原始应用程序是由Steve Gibson用汇编语言编写的。也就是说,没有源代码或调试信息。 Visual Studio应该仍然能够向我显示程序集转储。

6 个解决方案

#1


3  

Looking at the screenshot it appears that Visual Studio is currently debugging in Run mode - you need to break execution of the process before it makes sense to look at things like the call stack, etc...

看一下截图,看来Visual Studio当前正在运行模式下进行调试 - 你需要在查看调用堆栈之类的东西之前中断进程的执行...

To break execution of the process you either need to hit a breakpoint, or you can break execution of the process at any time by using the Pause / Break all toolbar item (Control + Alt + Break).

要中断进程的执行,您需要点击一个断点,或者您可以通过使用Pause / Break all工具栏项(Control + Alt + Break)随时中断进程的执行。

Then you should be able to access the following windows under the Debug -> Windows menu:

然后你应该能够在Debug - > Windows菜单下访问以下窗口:

  • The disassembly window
  • 反汇编窗口

  • The registers window
  • 寄存器窗口

  • The call stack window
  • 调用堆栈窗口

  • The modules window shows a list of loaded modules along with where their corresponding symbols are loaded from (if loaded)
  • 模块窗口显示已加载模块的列表以及从中加载相应符号的位置(如果已加载)

Some other useful windows:

一些其他有用的窗口:

  • The processes window is useful if you are debugging more than one process at a time
  • 如果要一次调试多个进程,则进程窗口很有用

  • The Threads window
  • 线程窗口

  • The Memory window (there are four of them)
  • 内存窗口(有四个)

  • The Locals window
  • 本地窗口

Some of these might not be visible by default depending on which window configuration you selected when you first started Visual Studio - if you can't find them then right click on the toolbar and goto customise to add them.

默认情况下,其中一些可能不可见,具体取决于您第一次启动Visual Studio时选择的窗口配置 - 如果找不到它们,请右键单击工具栏并转到自定义以添加它们。

Visual studio doesn't reconstruct soucre code from disassembly - you really need to have the original source code available to you, otherwise the symbols almost certainly won't match the source code you are debugging.

Visual Studio不会从反汇编中重建soucre代码 - 您确实需要使用原始源代码,否则符号几乎肯定与您正在调试的源代码不匹配。

If you are debugging unmanaged modules without source code then I recommend you at least try WinDbg - its user interface is a bit clunky at times, and it does have a steep learning curve, however it is a very powerful debugger supporting many features that Visual Studio doesn't - it may be more suited to the sort of debugging you need to do.

如果您正在调试没有源代码的非托管模块,那么我建议您至少尝试WinDbg - 它的用户界面有时候有点笨拙,而且确实有一个陡峭的学习曲线,但它是一个非常强大的调试器,支持Visual Studio的许多功能不 - 它可能更适合您需要做的调试。

(Visual Studio is a fantastic debugger, however it's primarily used to debug modules where the source code is available and so it lacks certain features in favour of a better user experience).

(Visual Studio是一个很棒的调试器,但它主要用于调试源代码可用的模块,因此它缺少某些功能,有利于提供更好的用户体验)。

#2


2  

Assuming this is your application that you wrote in VS, just press F5 to run the program and either use a breakpoint, or manually break the program to start debugging.

假设这是您在VS中编写的应用程序,只需按F5运行程序并使用断点,或手动中断程序以开始调试。

#3


1  

The problem in the last screenshot is that Visual Studio did not enter break mode automatically. That seems like a bug. If you hit the 'pause' button on the toolbar, it would enter break mode, giving you disassembly, and a callstack.

最后一个屏幕截图中的问题是Visual Studio没有自动进入中断模式。这似乎是一个错误。如果按下工具栏上的“暂停”按钮,它将进入中断模式,为您提供反汇编和一个callstack。

According to that last screenshot you were actually attached to the program ... the output windows shows it loaded stripped symbols for OLE and the crt.

根据最后一个截图,你实际上是附加到程序...输出窗口显示它加载了OLE和crt的剥离符号。

#4


1  

You can debug a program with Visual Studio if you have the debug information available for this program. It's the difference between compiling a Release version (normally without debug information) and compiling a Debug version.

如果您有可用于此程序的调试信息,则可以使用Visual Studio调试程序。编译Release版本(通常没有调试信息)和编译Debug版本之间的区别。

This dialog to debug a program is handy if you are testing the debug version of your self-written program. You can attach it "on-the-fly" to your Visual Studio debugger and look for the problem.

如果您正在测试自编程序的调试版本,则此调试程序对话框很方便。您可以“即时”将它附加到Visual Studio调试器并查找问题。

If it is not your program or it is your program, but does not provide debugging information which Visual Studio can understand, then you are out of luck.

如果它不是您的程序或它是您的程序,但不提供Visual Studio可以理解的调试信息,那么您运气不好。

#5


1  

Use menu Debug -> Windows -> Disassembly (I think the keyboard shortcut is Alt + 8, but I am configured for VC 6.0 bindings, because that's how I roll, and it may have changed).

使用菜单Debug - > Windows - > Disassembly(我认为键盘快捷键是Alt + 8,但是我配置了VC 6.0绑定,因为这是我滚动的方式,它可能已经改变了)。

You can get public symbols for the operating system from http://msdl.microsoft.com/download/symbols. Add it to the list in menu Tools -> Options -> Debugging -> Symbols -> Symbol file locations.

您可以从http://msdl.microsoft.com/download/symbols获取操作系统的公共符号。将其添加到菜单工具 - >选项 - >调试 - >符号 - >符号文件位置的列表中。

Also, make sure you are running in the same integrity level as the application. Or always run Visual Studio as Administrator.

此外,请确保您以与应用程序相同的完整性级别运行。或者始终以管理员身份运行Visual Studio。

#6


0  

I guess you are already in the Debug mode. The "Run" button is disabled. Just go to Debug -> windows -> Disassembly to view disassembly.

我猜你已经处于调试模式。 “运行”按钮被禁用。只需转到Debug - > windows - > Disassembly即可查看反汇编。

#1


3  

Looking at the screenshot it appears that Visual Studio is currently debugging in Run mode - you need to break execution of the process before it makes sense to look at things like the call stack, etc...

看一下截图,看来Visual Studio当前正在运行模式下进行调试 - 你需要在查看调用堆栈之类的东西之前中断进程的执行...

To break execution of the process you either need to hit a breakpoint, or you can break execution of the process at any time by using the Pause / Break all toolbar item (Control + Alt + Break).

要中断进程的执行,您需要点击一个断点,或者您可以通过使用Pause / Break all工具栏项(Control + Alt + Break)随时中断进程的执行。

Then you should be able to access the following windows under the Debug -> Windows menu:

然后你应该能够在Debug - > Windows菜单下访问以下窗口:

  • The disassembly window
  • 反汇编窗口

  • The registers window
  • 寄存器窗口

  • The call stack window
  • 调用堆栈窗口

  • The modules window shows a list of loaded modules along with where their corresponding symbols are loaded from (if loaded)
  • 模块窗口显示已加载模块的列表以及从中加载相应符号的位置(如果已加载)

Some other useful windows:

一些其他有用的窗口:

  • The processes window is useful if you are debugging more than one process at a time
  • 如果要一次调试多个进程,则进程窗口很有用

  • The Threads window
  • 线程窗口

  • The Memory window (there are four of them)
  • 内存窗口(有四个)

  • The Locals window
  • 本地窗口

Some of these might not be visible by default depending on which window configuration you selected when you first started Visual Studio - if you can't find them then right click on the toolbar and goto customise to add them.

默认情况下,其中一些可能不可见,具体取决于您第一次启动Visual Studio时选择的窗口配置 - 如果找不到它们,请右键单击工具栏并转到自定义以添加它们。

Visual studio doesn't reconstruct soucre code from disassembly - you really need to have the original source code available to you, otherwise the symbols almost certainly won't match the source code you are debugging.

Visual Studio不会从反汇编中重建soucre代码 - 您确实需要使用原始源代码,否则符号几乎肯定与您正在调试的源代码不匹配。

If you are debugging unmanaged modules without source code then I recommend you at least try WinDbg - its user interface is a bit clunky at times, and it does have a steep learning curve, however it is a very powerful debugger supporting many features that Visual Studio doesn't - it may be more suited to the sort of debugging you need to do.

如果您正在调试没有源代码的非托管模块,那么我建议您至少尝试WinDbg - 它的用户界面有时候有点笨拙,而且确实有一个陡峭的学习曲线,但它是一个非常强大的调试器,支持Visual Studio的许多功能不 - 它可能更适合您需要做的调试。

(Visual Studio is a fantastic debugger, however it's primarily used to debug modules where the source code is available and so it lacks certain features in favour of a better user experience).

(Visual Studio是一个很棒的调试器,但它主要用于调试源代码可用的模块,因此它缺少某些功能,有利于提供更好的用户体验)。

#2


2  

Assuming this is your application that you wrote in VS, just press F5 to run the program and either use a breakpoint, or manually break the program to start debugging.

假设这是您在VS中编写的应用程序,只需按F5运行程序并使用断点,或手动中断程序以开始调试。

#3


1  

The problem in the last screenshot is that Visual Studio did not enter break mode automatically. That seems like a bug. If you hit the 'pause' button on the toolbar, it would enter break mode, giving you disassembly, and a callstack.

最后一个屏幕截图中的问题是Visual Studio没有自动进入中断模式。这似乎是一个错误。如果按下工具栏上的“暂停”按钮,它将进入中断模式,为您提供反汇编和一个callstack。

According to that last screenshot you were actually attached to the program ... the output windows shows it loaded stripped symbols for OLE and the crt.

根据最后一个截图,你实际上是附加到程序...输出窗口显示它加载了OLE和crt的剥离符号。

#4


1  

You can debug a program with Visual Studio if you have the debug information available for this program. It's the difference between compiling a Release version (normally without debug information) and compiling a Debug version.

如果您有可用于此程序的调试信息,则可以使用Visual Studio调试程序。编译Release版本(通常没有调试信息)和编译Debug版本之间的区别。

This dialog to debug a program is handy if you are testing the debug version of your self-written program. You can attach it "on-the-fly" to your Visual Studio debugger and look for the problem.

如果您正在测试自编程序的调试版本,则此调试程序对话框很方便。您可以“即时”将它附加到Visual Studio调试器并查找问题。

If it is not your program or it is your program, but does not provide debugging information which Visual Studio can understand, then you are out of luck.

如果它不是您的程序或它是您的程序,但不提供Visual Studio可以理解的调试信息,那么您运气不好。

#5


1  

Use menu Debug -> Windows -> Disassembly (I think the keyboard shortcut is Alt + 8, but I am configured for VC 6.0 bindings, because that's how I roll, and it may have changed).

使用菜单Debug - > Windows - > Disassembly(我认为键盘快捷键是Alt + 8,但是我配置了VC 6.0绑定,因为这是我滚动的方式,它可能已经改变了)。

You can get public symbols for the operating system from http://msdl.microsoft.com/download/symbols. Add it to the list in menu Tools -> Options -> Debugging -> Symbols -> Symbol file locations.

您可以从http://msdl.microsoft.com/download/symbols获取操作系统的公共符号。将其添加到菜单工具 - >选项 - >调试 - >符号 - >符号文件位置的列表中。

Also, make sure you are running in the same integrity level as the application. Or always run Visual Studio as Administrator.

此外,请确保您以与应用程序相同的完整性级别运行。或者始终以管理员身份运行Visual Studio。

#6


0  

I guess you are already in the Debug mode. The "Run" button is disabled. Just go to Debug -> windows -> Disassembly to view disassembly.

我猜你已经处于调试模式。 “运行”按钮被禁用。只需转到Debug - > windows - > Disassembly即可查看反汇编。