1024programmer Asp.Net Net Advanced Debugging Part 2: Introduction to CLR, Windows Loader and Application Domain

Net Advanced Debugging Part 2: Introduction to CLR, Windows Loader and Application Domain

Net Advanced Debugging Part 2: Introduction to CLR, Windows Loader and Application Domain

1. Introduction
Today is the second article on Net advanced debugging. The first article records my learning of Net advanced debugging. The first step in debugging is to get to know some debugging tools. With the tools to rely on, we begin to travel to the ends of the world and start the official journey of Net advanced debugging. Let me start by saying that my article, [Debugging and Testing], is generally divided into two parts. The first part is all the test code samples to be used, and it is also for everyone’s convenience. The first time I did the test, I still left. Many detours. The second part is to use the Windbg debugger to debug the code. However, it needs to be explained that there are still some skills, or methods, in using Windbg. If you are not familiar with it, it is recommended to familiarize yourself with it in advance, because my testing process, I will not copy all the processes and will omit some less important steps. However, if it is the first time to use this software, the results you get during debugging may be different from mine. This is also mine. A step-by-step, painful experience.
If there is no explanation, the test environment for all codes is Net Framewok 4.8. However, sometimes in order to view the source code, you may need to use Net Core projects. I will explain it in the project chapter. Okay, without further ado, let’s start our debugging work today.
I need to explain the debugging environment in case everyone is unclear. I have listed the specific circumstances.
Operating system: Windows Professional 10
Debugging tool: Windbg Preview (you can go to Microsoft Store to download)
Development tool: Visual Studio 2022
Net version: Net Framework 4.8
CoreCLR source code: source code Download
2. Related concepts
 1 , Net framework
   Net is a virtual runtime environment, including a virtual execution engine (CLR) and a set of related framework libraries, as shown in the figure:
  
    1.1. Macro Concepts
      
      a), ECMA
                            
      a), ECMA
           The C# language and Common Language Infrastructure (CLI) specifications are standardized through Ecma International®. In layman’s terms, ECMA is a standard. It is a CLR development specification, or a design document.
          https://learn.microsoft.com/zh-cn/dotnet/fundamentals/standards

       b), CLR
   Common language runtime. It is the runtime environment of our C#, VB.Net, and F#. Of course, this is also the part that advanced debugging should focus on.
      The CLR handles memory allocation and management.
         The CLR is also a virtual machine that can not only execute applications, but also use a JIT compiler to quickly generate and compile code.
      Finally, let’s summarize that CLR is the implementation of the ECMA standard.

      c), NET framework
                                                                                   

d), Net applications
website system.

   1.2. Net program compilation process
                                                                           ccocess\ >>1.2. Compilation process of Net program
The first stage is compiler compilation, which compiles C# source code into IL code. The second stage is JIT compilation, which compiles IL code into machine code that can be run directly.
     a), compiler compilation
        Convert our C#, VB.Net, F# and other source codes into IL code using Visual Studio, or CSC and other similar tools. Of course, IL code cannot be run directly.
Of course, the IL code can also be seen. We can use ILSpy or DnSpy tools to load the corresponding assembly and view it. It is very simple, so I won’t go into details.

�color: rgba(128, 0, 128, 1)”>0:000> !dumpdomain (executed command)
2 —————— ——————-
3 System Domain: 7115caf8 (system level program domain)
4 LowFrequencyHeap: 7115ce1c (low frequency stack)
5 HighFrequencyHeap: 7115ce68 (High frequency stack)
6 StubHeap: 7115ceb4 (pile)
7 Stage: OPEN
8 Name: None
9 ———————– —————-
10 Shared Domain: 7115c7a8 (shared program area)
11 LowFrequencyHeap: 7115ce1c (low frequency stack)
12 HighFrequencyHeap: 7115ce68 (High frequency stack)
13 StubHeap: 7115ceb4 (pile)
14 Stage: OPEN
15 Name: None
16 Assembly: 00b4f3d8 [C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4 .0.0.0__b77a5c561934e089\mscorlib.dll ]
17 ClassLoader: 00b4de08
18 Module Name
19 6f531000 C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
20
21 ————————– ———-
22 Domain 1: 00b01518 (application area)
23 LowFrequencyHeap: 00b01984 (low frequency stack)
24 HighFrequencyHeap: 00b019d0 (High frequency stack)
25 StubHeap: 00b01a1c (pile)
26 Stage: OPEN
27 SecurityDescriptor: 00b02a58
28 Name: Example_2_1_1 .exe
29 Assembly: 00b4f3d8 [C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4 .0.0.0__b77a5c561934e089\mscorlib.dll ]
30 ClassLoader: 00b4de08
31 SecurityDescriptor: 00b4f340
32 Module Name
33 6f531000 C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
34
35 Assembly: 00b5b4d8 [E:\Visual Studio 2022\Source\Projects\AdvancedDebug.NetFramework.Test\Example_2_1_1\bin\Debug\Example_2_1_1.exe]
36 ClassLoader: 00b5afa8
37 SecurityDescriptor: 00b5aea0
38 Module Name
39 00d44044 E:\Visual Studio 2022\Source\Projects\AdvancedDebug.NetFramework.Test\Example_2_1_1\bin\Debug\Example_2_1_1.exe

   2.4. View the entry point through the command ? $exentry .

0:000> ? $exentry
 Evaluate expression: 5711746 = 00572782

3. Summary
There is a lot of content today, and it is quite difficult to record it all. As the saying goes, Where would the sweetness come from without the bitterness? The hard work of the day was still worth it, and I gained a lot. Learning is like sailing against the current. If you don’t advance, you will retreat. But there is another saying, the more you learn, the less you seem to understand. No matter what, don’t forget your original intention and keep working hard. God will not let down those who work hard.

All countries in the world can be equalized; honors and positions can be dismissed; swordsmanship can be practiced; moderation is impossible.ects\AdvancedDebug.NetFramework.Test\Example_2_1_1\bin\Debug\Example_2_1_1.exe]
36 ClassLoader: 00b5afa8
37 SecurityDescriptor: 00b5aea0
38 Module Name
39 00d44044 E:\Visual Studio 2022\Source\Projects\AdvancedDebug.NetFramework.Test\Example_2_1_1\bin\Debug\Example_2_1_1.exe

   2.4. View the entry point through the command ? $exentry .

0:000> ? $exentry
 Evaluate expression: 5711746 = 00572782

3. Summary
There is a lot of content today, and it is quite difficult to record it all. As the saying goes, Where would the sweetness come from without the bitterness? The hard work of the day was still worth it, and I gained a lot. Learning is like sailing against the current. If you don’t advance, you will retreat. But there is another saying, the more you learn, the less you seem to understand. No matter what, don’t forget your original intention and keep working hard. God will not let down those who work hard.

All countries in the world can be equalized; honors and positions can be dismissed; swordsmanship can be practiced; moderation is impossible.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/net-advanced-debugging-part-2-introduction-to-clr-windows-loader-and-application-domain/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索