小目的:我们的目标是用.Net
Core 2.0 SDK编写翻译二个小调整台程序 test_core.dll ,然后用VS2017
Debug coreclr
源码 ,接下去就能够详细调节和测试、查看test_core.dll
中IL代码是怎么一步步jit成Native代码的。**
1.下载最新 coreclr
源码并切换成release/2.0.0分支 ,本小说首要指标是上学coreclr源码,由于主Master代码一直在立异,许多新主题材料并不曾应声修复,选择release分支能够幸免过多编写翻译难点,相同的时间也很平稳。
2.准备coreclr编写翻译意况 ,此番选拔Win10类别,VS2017编写翻译及调节和测试(本机VS2014,VS2017都安装了)。
3.全方位筹划就绪coreclr目录张开调整台 .\build
skiptests,持久等待,编写翻译实现如下:
4.配置Debug,Github上有相关描述,可是比较老,并不完全好用,下边进入作者个人掌握,重新整理如下:
- a. 找到文件夹 coreclr\bin\obj\Windows_NT.x64.Debug
,VS2017打开 CoreCLR.sln - b.设置 INSTALL工程为运转项目。
- c.设置 INSTALL工程->右键properties ->Debugging。
- d.设置
Command=$(SolutionDir)..\..\product\Windows_NT.$(Platform).$(Configuration)\corerun.exe。
- e.设置 Command Arguments=
<managed app you wish to run>
(e.g.
test_core.dll)。 - f.设置
Directory=$(SolutionDir)..\..\product\Windows_NT.$(Platform).$(Configuration)
本条文件夹包蕴了编译CoreCL宝马7系 生成的dll和pdb文件。 - g.设置 Environment=CORE_LIBRARIES=C:\Program
Files\dotnet\shared\Microsoft.NETCore.App\2.0.3
(此布署告诉CoreCLKoleos去此路线去找基础托管类库,不布置debug会抛错,为了便利直接指向本机.Net
Core SDK内文件夹)。
全体配置如下:
小总结:明日结束一共涉及到3方dll(托管和非托管):
- 大家温馨编写翻译的托管 test_core.dll ,也是第一实验目的。
- .NET Core
SDK的托管基础类库System.Runtime.dll、System.Threading.dll、、、等(test_core.dll
相关托管依赖)。 - 咱俩编写翻译的CoreClr非托管dll,coreclr.dll、clrjit.dll、CoreRun.exe、、等,是大家器重的Debug对象。
5.用编译test_core.dll
用.Net Core2.0 SDK编写翻译如下代码,怎么着编写翻译自行脑补
1 using System;
2 using System.Runtime.CompilerServices;
3
4 namespace test_core
5 {
6 class Program
7 {
8 const int Pass = 100;
9 const int Fail = -1;
10 [MethodImplAttribute(MethodImplOptions.NoInlining)]
11 public static void DblRoots(double a, double b, double c, ref double r1, ref double r2)
12 {
13 r1 = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
14 r2 = (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
15 return;
16 }
17 static int Main(string[] args)
18 {
19 double x1 = 0;
20 double x2 = 0;
21 DblRoots(1d, -5d, 6d, ref x1, ref x2);
22 Console.WriteLine(x1 + "," + x2);
23 if (System.Math.Abs(x1 - 3d) > Double.Epsilon) return Fail;
24 if (System.Math.Abs(x2 - 2d) > Double.Epsilon) return Fail;
25 string str = Console.ReadLine();
26 return Pass;
27
28 }
29 }
30 }
将编写翻译生成内容总体copy到coreclr\bin\Product\Windows_NT.x64.Debug目录中
6.VS2017中装置断点并运营查看test_core.dll的运作结果
7.接下来正是发挥想象力的时候了,能够参见 GitHub coreclr
文书档案,关键地方下断点,调节和测试爱博体育app,ryujit大旨代码。
8.期望此文能支持我们更便于的Debug CoreClr,迎接各路大牛指点。