在更改vm原语时调试VM中的解释器

Use*_*ser 7 smalltalk squeak pharo vm-implementation

上下文

作为一个大学项目,我们想要改变pharo vm以使用对象表,看看会发生什么.

我们使用来自github和VMMaker 的pharo-vm克隆.构建VM工作正常.

为了开始,我们添加了一个返回增量Integer的原语:

InterpreterPrimitives>>primitiveIntegerIncrement
    "increments an integer"
    self pushInteger: self popInteger + 1 .
Run Code Online (Sandbox Code Playgroud)

StackInterpreter class>>initializePrimitiveTable据此修改

MaxPrimitiveIndex := 576.
"... and so on ..."
    (575 primitiveFail)
    (576 primitiveIntegerIncrement))
Run Code Online (Sandbox Code Playgroud)

它有效.

问题

当我们对VM进行更改时,我们想要在SmalltalkImage中进行测试运行,因此我们不需要编译并看到它不起作用.

就像是:

StackInterpreter test: '1 inc'
Run Code Online (Sandbox Code Playgroud)

如果原语错误或发生错误,我可以调试.当然需要做得更多,但我怎样才能做到这一点?

我们尝试了什么

  1. VMMaker-InterpreterSimulationStackInterpreterSimulator.尝试评论中的代码

    DoIt
        ^ (StackInterpreterSimulator new openOn: Smalltalk imageName) test 
    
    Run Code Online (Sandbox Code Playgroud)

    错误:

        displayForm := 'Display has not yet been installed' asDisplayText form.
    
    Run Code Online (Sandbox Code Playgroud)

    ByteString不明白 asDisplayText

  2. (CogVMSimulator new openOn: Smalltalk imageName) test 
    (InterpreterSimulator new openOn: Smalltalk imageName) test
    
    Run Code Online (Sandbox Code Playgroud)

    错误:

        PrimitiveFailed: primitive #basicNew: in Array class failed
    
    Run Code Online (Sandbox Code Playgroud)

我也找到了这个屏幕,但它只使用gbd从外部调试VM:http://vimeo.com/22485382#

我们的项目在这里举办:http://smalltalkhub.com/# !/~ kirstin/ PharoObjectTable

当前状态

我们开始实现一个对象表.属性的查找可以遍历对象表.完整的对象表支持和不使用直接指针是非常棘手的,因为指针到处都是.因此,我们使用指向对象表的指针来识别查找何时应该通过OT.我们还找到了所有对象创建原语并向表中添加了新对象.

小智 4

你的项目有多长,有多少人?对我来说,你尝试做的事情是相当艰巨的工作。您对低级行为有深入的了解吗?

为了回答你的问题,这里的主要问题是 cog 模拟器没有在 pharo vm fork 中维护。这是因为法罗团队中没有人使用模拟器。我们只使用 gdb 的外部调试。事实上,pharo 人员主要致力于 VM 插件,VM 的核心主要由 Eliot Miranda(在 Squeak 上工作)维护和开发。因此,当 VM 核心出现错误时,我们会向他报告。

对于您的项目,您必须将其至少分为两个步骤:

步骤1:使对象表与堆栈VM一起工作

第 2 步:使 JIT 与您的对象表一起工作

请注意,对于步骤 2,我建议不要更改对象访问其标头的方式,因此拥有一个类似 VW 的对象表,其中对象表中的标头具有固定大小的标头,并且对象的字段(也许还有标头扩展)在堆中。

So use the StackVMSimulator and build the StackVM first. When everything will work (including context), you can think about hacking the JIT. Recently Guillermo Polito ported the Stack VM to the build process (see PharoSVMBuilder instead of PharoVMBuilder), a guy reported problems with this builder but you could hack it a bit to make it work.

Now to make the simulator work on Pharo 2.0 (which is the Pharo version of the generator image you have), you have to open the monticello browser and merge from Eliot's branch the Cog package (repo MCHttpRepository location: 'http: //source. squeak. org/VMMaker'), but not the latest Cog, the one at around the same date as the current VMMaker package of pharo-vm because the latest Cog and VMMaker of Eliot's branch are not stable.

The alternative being to start from Eliot's build image and merge things from the pharo branch. Here are infos about how to build the squeak development image (http://www.mirandabanda.org/cogblog/build-image/).

Then Eliot gave me this script once:

| cos |
cos := CogVMSimulator newWithOptions: #(Cogit SistaStackToRegisterMappingCogit).
cos desiredNumStackPages: 8.
cos openOn: 'my/favourite.image'.
cos openAsMorph; toggleTranscript; halt; run
Run Code Online (Sandbox Code Playgroud)

You don't need the SistaStackToRegisterMappingCogit option. I guess some similar script with the StackVMSimulator should work.

Lastly there are some documentation about the simulator but it is only for the CogSimulator (these documentations expects you already knows how the StackSimulator works, and just give you hints about how to use it with the JIT): http://www.mirandabanda.org/cogblog/2008/12/12/simulate-out-of-the-bochs/ and in one of the video named "Cog VM (part x)", x being from 1 to 6, Eliot shows how he uses the simulator to disassemble x86, print the stack and inspect the heap.

Another tip, ask your questions on the pharo mailing list (pharo users or pharo dev), because here no one may notice your question (fortunately someone pointed me out your question this time).

And tell on the pharo mailing list if you managed to run the simulator in Pharo 2.0, some people (as me) are very interested in it. I was planning to do it at some point.

Good luck ! Nice project anyway.