Getting started with WinDbg

 You can install it directly from the Windows Store using the guide here. If you are sitting behind a corporate proxy, then forget it. You can use old WinDbg for your job. I will cut back on a lot of talking and jump straight into debugging. 


I will start with creating an application. Nothing fancy. The code does not have to make any sense. I have pasted it here.


So, I will fire up the exe and wait for the program to naturally halt at Console.Readline. Now attach the debugger and press g. Now enter the following command. This will load sos extension that helps us a lot with debugging managed code.

.loadby sos clr
Use the below command to display the stack of all the managed threads in the process.
!EEStack

This should display the current stack trace.


The program has paused at Console.Readline in our Main method.

Let's now set a breakpoint at the method we want to look at: private static void Method1(string v)

In order to do that, let us look that up using the following command:


!name2ee DemoApp.exe DemoApp.Program.Method1


Now, let us set the breakpoint using !bpmd:

!bpmd -md 01434d5c

Now, let's continue the execution of the process by issuing the 'g' command. After doing that, the process will start and you will be prompted by Console.Readline to enter a line. After you enter something, the breakpoint we had set gets triggered. 


Now if we do a !CLRStack, it WinDbg tells us where we are. 

Comments

Popular posts from this blog

Viewing variables in a stackframe