当前位置:首页 >  开发者 >  调试Rotor:启动过程

调试Rotor:启动过程

引言:我已经深入一些书籍好长一段时间了,包括(Essential.Net,SharedSourceCLI,SharedSourceInternals,DistributedVirtualmachine,ECMA335

引言:

我已经深入一些书籍好长一段时间了, 包括(Essential.Net, Shared Source CLI, Shared Source Internals, Distributed Virtual machine, ECMA335), 然而纸上得来终觉浅,绝知此事要躬行, 我的默认试验环境是:

  • Windows 2008 / Visual Studio 2008 SP1 / .Net Framework 3.5 SP1 / SSCLI2.0

在本文中,我将在Visual Studio 2008中使用一个简单的例子来解释Rotor的启动过程

例子代码文件: %Rotor_DIR%/Samples/Hello/hello.cs

如何Debug?

如果您不知道,可以看这里, 简单的步骤如下面所示

  • cd E:/Research/MyRotor                  // 请根据您的Rotor目录修改
  • env                                                // 设置环境变量
  • cd samples/hello
  • csc /debug hello.cs                         // 编译代码
  • devenv /debugexe clix hello.exe      // 调试clix

按F11就可以到程序执行的第一行代码了

图 1: 调试的第一行代码

这个文件在 %Rotor_DIR%palrtincpalstartup.h

启动过程

Figure 2:  大概的启动过程

Figure 3: 启动中主要执行的过程

我已经进行一次启动过程的调试,启动过程如下图所示.

Figure 4: the loading process in sscli2.0

代码文件:

  • palwin32win32pal.c
  • clrsrc oolsclixclix.cpp
  • palrtsscoreesscoree_int.cpp
  • clrsrcvmceemain.cpp
  • clrsrcvmappdomain.cpp

ExecuteMainMethod中的一些执行过程放在了下面的代码中,有兴趣的读者不妨一读

Code
Thread *pThread = GetThread();

FrameWithCookie
<ContextTransitionFrame> frame;
pThread
->EnterContextRestricted(SystemDomain::System()->DefaultDomain()->GetDefaultContext(), &frame);

AppDomain 
*pDomain = GetAppDomain();

FrameWithCookie
<DebuggerClassInitMarkFrame> __dcimf;

PEImageHolder pTempImage(PEImage::OpenImage(path));
if (!pTempImage->CheckILFormat())
{
    ThrowHR(COR_E_BADIMAGEFORMAT);
}
PEFileHolder pTempFile(PEFile::Open(pTempImage.Extract()));

// Check for CustomAttributes - Set up the DefaultDomain and the main thread
// Note that this has to be done before ExplicitBind() as it
// affects the bind
mdToken tkEntryPoint = pTempFile->GetEntryPointToken();
    ReleaseHolder
<IMDInternalImport> scope(pTempFile->GetMDImportWithRef());


// This can potentially run managed code.
InitializeDefaultDomain(FALSE);


if((!IsNilToken(tkEntryPoint)) && (TypeFromToken(tkEntryPoint) == mdtMethodDef))
    SystemDomain::SetDefaultDomainAttributes(scope, tkEntryPoint);


NewHolder
<PEFileSecurityDescriptor> pSecDesc(new PEFileSecurityDescriptor(pDomain, pTempFile));
Security::Resolve(pSecDesc);
if (Security::AllowBindingRedirects(pSecDesc))
    pDomain
->TurnOnBindingRedirects();

SafeComHolder
<IAssembly> pFusionAssembly;
SafeComHolder
<IFusionBindLog> pFusionLog;

IfFailThrow(ExplicitBind(path, pDomain
->GetFusionContext(),
                     EXPLICITBIND_FLAGS_EXE,
                     NULL, 
&pFusionAssembly, NULL, &pFusionLog));
PEAssemblyHolder pFile(PEAssembly::Open(pFusionAssembly, NULL, pFusionLog));

pDomain
->m_pRootAssembly = GetAppDomain()->LoadAssembly(NULL, pFile, FILE_ACTIVE);
if (CorCommandLine::m_pwszAppFullName == NULL) {
    StackSString friendlyName;
    StackSString assemblyPath 
= pFile->GetPath();
    SString::Iterator i 
= assemblyPath.End();

    
if (PEAssembly::FindLastPathSeparator(assemblyPath, i)) {
        i
++;
        friendlyName.Set(assemblyPath, i, assemblyPath.End());
    }
    
else
        friendlyName.Set(assemblyPath);

    pDomain
->SetFriendlyName(friendlyName, TRUE);
}

__dcimf.Pop();

结语

本来想再细致点,慢慢来吧,累,而且俺还懒。还有很多东西值得深入,比如meta token的验证,cil代码的验证, Main 方法的即时编译(JIT),先留着,:)

参考:

distributed virtual machines - inside the rotor cli

Under the hood of the CLR Managed Execution

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,
如果涉及侵权请联系站长邮箱:support@yingtwo.com 进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:none

最近更新

68.C++中的const
68.C++中的const

编写程序过程中,我们有时不希望改变某个变量的值...

封神榜哪个版本游戏
封神榜哪个版本游戏

PC上的荡神志、刀剑封魔录、封神榜之英雄无敌P...

硬盘怎么清洁
硬盘怎么清洁

给笔记本电脑硬盘清理灰尘的方法如下:1、用螺丝...

410m和7670哪个好
410m和7670哪个好

首先三款笔记本的处理器都是i52450m,内存...

手机2k17乔丹怎么获得
手机2k17乔丹怎么获得

NBA2k17选择乔丹先创建MC人物,打三局大...

多态、抽象类、接口练习:愤怒的小鸟
多态、抽象类、接口练习:愤怒的小鸟

需求说明:模拟实现愤怒的小鸟,定义鸟叫的接口,...

rx480配什么amdcpu
rx480配什么amdcpu

rx480可以搭配酷睿i3-6100cpu,酷...

6s主要的指导是什么
6s主要的指导是什么

6s指的是什么6s指的是什么,在现实生活中,6...

手机里dst什么意思
手机里dst什么意思

将时间在正常情况下提前一小时,如果实行“夏令时...

斗鱼1鱼翅等于多少鱼丸
斗鱼1鱼翅等于多少鱼丸

100鱼丸=100g,1T=1000kg=10...