Using windbg from Visual Studio
Asked Answered
E

3

7

Is it possible to use windbg commands like !locks and .loadby sos mscorwks from the Visual Studio command window (in a debug session)? I've noticed I can use eg k to print a stack trace, so I was wondering if there is some way to get access to the other commands.

Eichman answered 9/8, 2010 at 8:42 Comment(0)
O
8

Yes you can do this.

  1. Attach Visual studio 2008 to your process for debugging.
  2. Break at some code.
  3. Go to immediate window
  4. type !load sos
  5. Now you are free to use any of the windbg commands like !EEHeap,!DumpHeap

There are some conditions. You need to enable unmanaged code debugging in your project properties. Normally in 64 bit version studio doesn't support this.

Have fun.

Oubliette answered 9/8, 2010 at 8:55 Comment(5)
cool, thanks for that. Any idea if I can get access to the unmanaged windbg calls like locks or analyze?Eichman
@ngoozeff:I think only the sos commands are possible here!!Someone correct me if I am wrongOubliette
Sorry to be nitpicking here, but those are not WinDbg commands, but SOS commands. Unfortunately the regular WinDbg commands are not available from VS afaik, which makes it a bit harder to use SOS. Also, VS doesn't support all the necessary IDebugClient interfaces, so output from SOS is a bit noisy in VS.Jeane
Brian is Right, the strict answer to the question is NO. SOS is NOT WinDbg. Besides, WinDbg has a x64 version, whereas SOS has not, i.e, if you want to debug x64 apps without recompiling them into 32bit then WinDbg, Outside VS, is the only way to goReel
!load sos fails on VS2013: 'identifier "load" is undefined'.April
C
4

Visual Studio 2012 has the "Windows User Mode Debugger" transport in the "Attach to Process" dialog. This allows you to use windbg commands in the immediate window.

Source: Use the WinDbg Engine in Visual Studio User-Mode Debugging

Candycandyce answered 24/6, 2013 at 14:36 Comment(4)
I have Visual Studio 2012 Professional (Update 4) installed. However, the Windows User Mode Debugger transport does not show up for me. Some sources claim that you have to install the WDK on top of a VS installation, but reliable information doesn't appear to be readily available. So, what's the deal?Elliellicott
From the link: Another caveat is that currently you need to install the WDK on top of Visual Studio 11 to get the debugger integration. It didn't work for me either until I installed the WDK.Candycandyce
I can confirm that installing the Windows 8.0 WDK on top of Visual Studio did install the Visual Studio integration as well. I can now pick Windows User Mode Debugger as the transport (or pick another debugger from a project's Debugger settings). It appears to work reliably, even though it is slow for me. Some features from the VS debugger are missing (e.g. Tracepoints), while others have changed (e.g. different syntax for setting function breakpoints). The powerful WinDbg extension commands like !handle or !locks are now available from the VS GUI (Debugger Immediate Window).Elliellicott
Note: For Visual Studio 2015, WDK 10 is required for the "Windows User Mode Debugger" transport.Candycandyce
E
2

Starting with Windows Driver Development Kit (WDK) 8.0 the Windows debugger is integrated into Visual Studio (see Debugging Environments). Installing the WDK on top of a Visual Studio installation will enable a developer to pick a number of debuggers from the Attach to Process dialog, or set the debugging engine in a project's Debugger settings. This has been verified for Visual Studio 2012 and 2013. The way I read the MSDN link above, this should also work for any other IDE that is supported by the WDK 8.0 and above.

While WinDbg offers a lot of powerful commands, there are some drawbacks as well. This list is not exhaustive, and merely contains those issues I did encounter:

  • Cannot attach to more than one process at a time. While not generally an issue, this is quite unfortunate, if you do need to debug more than one process at a time. The Visual Studio debugger can attach to any number of processes simultaneously.
  • WinDbg will not use the symbol settings from your Visual Studio IDE (tested on VS 2012 Update 4). While you can configure the IDE where to look for debugging symbols, WinDbg will not honor those settings. WinDbg will use the _NT_SYMBOL_PATH environment variable, and/or the configuration set through .sympath.
  • Different syntax for function breakpoints. This is a minor annoyance, since you cannot use Visual Studio's syntax to specify function breakpoints. This also means, that function breakpoints are ignored that have been set using the Visual Studio syntax. What's more annoying, though, you do get a warning dialog for each when launching a debuggee.
  • No support for Tracepoints. I've been using tracepoints extensively, to unintrusively insert tracing into a debuggee. If you are using tracepoints as well, this may prove to be more than just an annoyance.
Elliellicott answered 26/12, 2014 at 15:39 Comment(2)
windbg's bp command accepts a command to run when the breakpoint is hit, so you can emulate a tracepoint. For example, bp combase!CoSetErrorInfo "dt combase!CErrorObject %edx; g"Candycandyce
Were you able to use this method with VS 2017, and WDK (esp. version 1507+)? Debugging a User-Mode Process Using Visual Studio page says "This feature is not available" for that combination, and when I tried (after changing the target to "Localhost") I kept getting an E_FAIL with "unable to connect / operation not supported"! I'm trying to make sure it's not just a configuration issue on my end.Rattlehead

© 2022 - 2024 — McMap. All rights reserved.