📜 ⬆️ ⬇️

In each .net application, memory is reserved for three exceptions.

At the weekend I went to visit my friend new_s and he showed me an interesting thing. He needed to analyze the memory dump of the .net application, where he looked for memory leaks and other abnormal behavior and showed me that when starting any .net application, the environment reserves memory for three exceptions:

And this is normal behavior. Why?

I decided to conduct an experiment, and, downloading Visual Studio, I created the simplest console application Hello world:

 using System; namespace HelloWorld { class Program { static void Main() { Console.Write("Hello world!"); Console.ReadKey(); } } } 


We compile this case either, we can download the same thing here .
')
Now download the Debuggin Tools For Windows . We need the WinDbg utility.

Open it and add symbols (pdb file): File -> Symbol File Path and specify our .pdb file HelloWorld.pdb . You also need to load symbols for other assemblies, so create a temp directory and in the Symbol File Path window specify something similar to

D:\WORK\Projects\Own\HelloWorld\HelloWorld\bin\Debug; SRV*D:\Temp\Symbols*http://msdl.microsoft.com/download/symbols

Then we run our application (if from Visual Studio, then not in Debug Mode) and in WinDbg we join the process: File-> Attach to a Process

image

Execute the command:

 .loadby sos mscorwks 


in order to download the sos.dll extension and allow debugging managed code.

Let's dump the memory by executing the following command:

 .dump /ma D:\Temp\HelloWorld.dmp 


You can stop Debug: Debug -> Stop Debuggin

And open our memory dump: File -> Open Crash Damp and select our HelloWorld.dmp

Filter the dump to see the exceptions with the command:

 !dumpheap -type Exception 


And what do we see? Here are our exceptions:

 7093fd68 1 84 System.ExecutionEngineException 7093fd1c 1 84 System.StackOverflowException 7093fcd0 1 84 System.OutOfMemoryException 


image

findings

These three exceptions ( ExecutionEngineException, StackOverflowException OutOfMemoryException ) were specifically created when the application ExecutionEngineException, StackOverflowException OutOfMemoryException to cover a situation such as when you already run out of memory and do not even have enough to create an OutOfMemory exception, as this would lead to another OOM exception. Similarly, if you already have a stack overflow, you cannot create a StackOverflowException , since you would need to call its constructor, which is impossible if the stack is already full.

So if ever you have to work with a memory dump of .net applications, do not be intimidated by these exceptions, the .net environment itself will forward them when there is not enough memory or the buffer is full.

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


All Articles