Debugging .dmp files from WinDbg in Visual Studio 2008 for .Net managed applications

I am trying to find how to take a crash dump of a managed .Net executable and then open the resulting .dmp file in Visual Studio 2008. I want to see where the exception is generated in the source code, the call stack and the value of the variables in the functions on the stack.

To simplify the task, I wrote a gadget that crashes:

...

class Program
{
    static void Main(string[] args)
    {

        int a = 2;           //Variable I want to see value for when debugging

        if (!File.Exists(@"C:\Crasher\bin\Debug\file.txt")) //Doesn't exist
            throw new FileNotFoundException();     //Unhandled exception thrown
    }
}

...

I built DEBUG and ran it from outside Visual Studio. In windbg, I clicked "Attach to process" and selected my application. Then I typed the windbg command prompt window:

          .dump /ma C:\crasher\bin\debug\dump.dmp

Then I opened the .dmp file in Visual Studio. I went to Tools-> Options-> Debugging-> Symbols and added the following:

          http://msdl.microsoft.com/download/symbols  (saved to local folder)

DLL, "" (, Kernel32.dll, gdi32.dll - , ), mscorlib.ni.dll. Symbol Microsoft .pdbs mscorlib.dll, mscorlib.ni.dll.

.pdb .exe, , . , , .exe , - , pdb mscorlib.ni.dll, .

? - ?

, mscorlib.ni.dll Microsoft Symbol Server, , - , Visual Studio.

- .

+3
1

, VS2008, WinDbg.

, , - adplus ( Windows). ,

>adplus -crash -o c:\dumpdirectory -pn app.exe

. , . , , (.. , - ). .

, SOS, .loadby sos mscorwks.

!pe, ( ). :

0:000> !pe
Exception object: 024a5114
Exception type: System.IO.FileNotFoundException
Message: Unable to find the specified file.
InnerException: <none>
StackTrace (generated):
    SP       IP       Function
    0020F0F0 005100D6 TestBench!TestBench.Program.Main()+0x66

StackTraceString: <none>
HResult: 80070002

a, !clrstack -l, , - .

0:000> !clrstack -l
OS Thread Id: 0x1a50 (0)
ESP       EIP     
0020f04c 7571b727 [HelperMethodFrame: 0020f04c] 
0020f0f0 005100d6 TestBench.Program.Main()
    LOCALS:
        0x0020f0fc = 0x00000002  <--- the value of a
        0x0020f0f8 = 0x00000000

0020f328 51141b5c [GCFrame: 0020f328] 
+2

Source: https://habr.com/ru/post/1774915/


All Articles