how can I check which selector is the VM executing?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how can I check which selector is the VM executing?

Mariano Martinez Peck
 
Hi. Suppose I am doing something in #commonSend:

commonSend
    "Send a message, starting lookup with the receiver's class."
    "Assume: messageSelector and argumentCount have been set, and that
    the receiver and arguments have been pushed onto the stack,"
    "Note: This method is inlined into the interpreter dispatch loop."
    <sharedCodeNamed: 'commonSend' inCase: 131>
    self internalFindNewMethod.
    self internalExecuteNewMethod.
    self fetchNextBytecode


and somewhere there I want to do something like this:

(messageSelector = '#foo') ifTrue: [ self print: 'the message foo was called'; cr ].

messageSelector is the instVar of Interpreter and it is already in the stack.

Of course, the part that doesn't work is (messageSelector = '#foo')
I tried several things but I don't find how to do it.

Thank in advance

--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] how can I check which selector is the VM executing?

Yoshiki Ohshima-2

At Thu, 28 Apr 2011 12:22:33 +0200,
Mariano Martinez Peck wrote:

>
> Hi. Suppose I am doing something in #commonSend:
>
> commonSend
>     "Send a message, starting lookup with the receiver's class."
>     "Assume: messageSelector and argumentCount have been set, and that
> the receiver and arguments have been pushed onto the stack,"
> "Note: This method is inlined into the interpreter dispatch loop."
> <sharedCodeNamed: 'commonSend' inCase: 131>
> self internalFindNewMethod.
> self internalExecuteNewMethod.
> self fetchNextBytecode
>
> and somewhere there I want to do something like this:
>
> (messageSelector = '#foo') ifTrue: [ self print: 'the message foo was called'; cr ].
>
> messageSelector is the instVar of Interpreter and it is already in the stack.
>
> Of course, the part that doesn't work is (messageSelector = '#foo')
> I tried several things but I don't find how to do it.

  Perhaps something along the line of:

  (self cCode: 'stSizeOf(messageSelector) == sizeOf('foo') && (strncmp(firstIndexableField(messageSelector), 'foo',
     sizeOf('foo')) == 0)) ifTrue: [self print: 'the message foo was called': cr].

  (Not tested this particualr one, but have done similar thing
before.  This assumes that messageSelector is always a Symbol, which
may not be the case for you...)

-- Yoshiki
Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] how can I check which selector is the VM executing?

Mariano Martinez Peck
 


On Sat, Apr 30, 2011 at 4:23 AM, Yoshiki Ohshima <[hidden email]> wrote:

At Thu, 28 Apr 2011 12:22:33 +0200,
Mariano Martinez Peck wrote:
>
> Hi. Suppose I am doing something in #commonSend:
>
> commonSend
>     "Send a message, starting lookup with the receiver's class."
>     "Assume: messageSelector and argumentCount have been set, and that
> the receiver and arguments have been pushed onto the stack,"
> "Note: This method is inlined into the interpreter dispatch loop."
> <sharedCodeNamed: 'commonSend' inCase: 131>
> self internalFindNewMethod.
> self internalExecuteNewMethod.
> self fetchNextBytecode
>
> and somewhere there I want to do something like this:
>
> (messageSelector = '#foo') ifTrue: [ self print: 'the message foo was called'; cr ].
>
> messageSelector is the instVar of Interpreter and it is already in the stack.
>
> Of course, the part that doesn't work is (messageSelector = '#foo')
> I tried several things but I don't find how to do it.

 Perhaps something along the line of:

 (self cCode: 'stSizeOf(messageSelector) == sizeOf('foo') && (strncmp(firstIndexableField(messageSelector), 'foo',
    sizeOf('foo')) == 0)) ifTrue: [self print: 'the message foo was called': cr].

 (Not tested this particualr one, but have done similar thing
before.  This assumes that messageSelector is always a Symbol, which
may not be the case for you...)


Thanks Yoshiki. After I sent this mail, and with a help of a friend, I was also trying to do something similar to that. Just by coincidense, Eliot answered me in another thread, a way to solve this in Cog, and it is using the command line argument -breaksel.  With such parameter you can send a seletor as an argument, put a breakpoint with gdb, and the VM will stop in a place. It is not EXACTLY the same as what I was asking, but it is useful.

If you are interested, read his answer here: http://forum.world.st/Cog-and-commonSend-are-getting-me-crazy-td3480836.html

And yes, his code is similar to yours:

CoInterpreter >>  compilationBreak: selectorOop point: selectorLength
    <api>
    <cmacro: '(sel, len) do { \
    if ((len) == breakSelectorLength \
     && !strncmp((char *)((sel) + BaseHeaderSize), breakSelector, breakSelectorLength)) { \
        suppressHeartbeatFlag = 1; \
        compilationBreakpointFor(sel); \
    } \
} while (0)'>
    | i |
    breakSelectorLength = selectorLength ifTrue:
        [i := breakSelectorLength.
         [i > 0] whileTrue:
            [(self byteAt: selectorOop + i + BaseHeaderSize - 1) = (breakSelector at: i) asInteger
                ifTrue: [(i := i - 1) = 0 ifTrue:
                            [self compilationBreakpointFor: selectorOop]]
                ifFalse: [i := 0]]]


Once again, thanks for your help.

--
Mariano
http://marianopeck.wordpress.com