Stepping through Source Code using Windbg SOS Extension
Asked Answered
A

3

8

I have recently switched from native to managed code programming. I am using .NET.

Since i have been using Windbg for quite some time , i want to use it for managed code debugging as well.

My search has brought me to the SOS (Son of Strike) extension, which seems to have quite some powerful commands.

Even though i understand most of the commands being used in SOS, i am unable to find a way to properly step through source code, just as i could do using the p and t instructions for native code.

This makes the debugging experience difficult, and I really want to step through code while debugging it.

I researched a bit on this and found that this was possible using the 6.7.05.0 version of Windbg in which MS seemed to have released integrated managed debugging, but rolled back in the later versions.

Nevertheless, i am very interested in being able to step through "source" code live while debugging through SOS. Specially because it is really hindering my debugging experience right now.

Is there a way to achieve this?

Any help on how to do this (or practical workarounds) is appreciated.

Athlete answered 29/10, 2012 at 5:55 Comment(0)
T
6

Windbg shines at analyzing minidumps of a crashed process. It is however not a managed debugger.

You can have your cake and eat it too by loading SOS in Visual Studio. Which permits using the normal debugging tools you have available in the managed debugger, plus the diagnostics you can get out of SOS. A few restrictions apply:

  • You must enable unmanaged debugging, Project + Properties, Debug tab, tick the option
  • VS is a 32-bit process so you can only use the 32-bit version of SOS. Project + Properties, Build tab, ensure you've got x86 selected if you are using the 64-bit version of Windows.

Start debugging and switch to the Immediate Windows. Type .load sos.dll, you should see an message like extension C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll loaded. Type !help and verify that you see the SOS commands listed.

Terat answered 29/10, 2012 at 15:28 Comment(0)
C
8

Try using !sosex.mt and !sosex.mgu. The 'p' command should work as advertised.

Chickenhearted answered 29/10, 2012 at 13:13 Comment(5)
Hey Steve, It is cool to have a reply from the developer of SOSEX itself..! My main aim here is to make sure that as i step through code, i can see the correct line of code highlighted in the debugger. While i am unable to do this with SOS, and from you reply i gather that "!sosex.mt" and "!sosex.mgu" would be equivalents of t and gu for native code. But would executing these command also highlight the corresponding lines of code in the source window? Thanks again for your reply !Athlete
It may be that in later versions of WinDbg that the source syncing won't work correctly. Unfortunately, I have no control over that part. However, if you use the !muf extension, you can sync up with your source code pretty well. It's not as nice as the highlight in the code window, but it works.Chickenhearted
Thanks Steve. It'd help if you could quantify what " later versions of WinDbg" would exactly be?Athlete
I have no idea. It has been almost 5 years since I've used the public version of WinDbg. I do remember that when I originally wrote the breakpoint functionality of sosex that the source window integration "just worked".Chickenhearted
@SteveJohnson, in new WinDbg preview with its historical time-travel debugging it would allow to travel back to an object creation which could be especial useful in some debugging casesNorthey
T
6

Windbg shines at analyzing minidumps of a crashed process. It is however not a managed debugger.

You can have your cake and eat it too by loading SOS in Visual Studio. Which permits using the normal debugging tools you have available in the managed debugger, plus the diagnostics you can get out of SOS. A few restrictions apply:

  • You must enable unmanaged debugging, Project + Properties, Debug tab, tick the option
  • VS is a 32-bit process so you can only use the 32-bit version of SOS. Project + Properties, Build tab, ensure you've got x86 selected if you are using the 64-bit version of Windows.

Start debugging and switch to the Immediate Windows. Type .load sos.dll, you should see an message like extension C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll loaded. Type !help and verify that you see the SOS commands listed.

Terat answered 29/10, 2012 at 15:28 Comment(0)
T
0

If what you want is to hookup source code to windbg you could follow those steps:

  1. Go to File->Source File Path, select folder with source files.
  2. Go to View->Call Stack, it will open a new window.
  3. Navigate in the call stack and click on the relevant entry, it will open a window with the code browser.
Trehalose answered 16/10, 2013 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.