Ian Boyd
Ian Boyd

Reputation: 256641

How to debug a process using Visual Studio?

If an application† crashes,

enter image description here

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

enter image description here

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

enter image description here

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.

How do you debug a program using Visual Studio?

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

† Not, necessarily, written in 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.

Upvotes: 5

Views: 4853

Answers (6)

i_am_jorf
i_am_jorf

Reputation: 54600

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).

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.

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

Upvotes: 1

John Smithers
John Smithers

Reputation: 1520

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.

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.

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.

Upvotes: 1

Steve Steiner
Steve Steiner

Reputation: 5359

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.

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.

Upvotes: 1

Justin
Justin

Reputation: 86729

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...

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).

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

  • 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 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.

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.

(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).

Upvotes: 3

Soundararajan
Soundararajan

Reputation: 2194

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

Upvotes: 0

GEOCHET
GEOCHET

Reputation: 21323

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.

Upvotes: 2

Related Questions