Fwd: Oops - I put a halt in a startup method

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

Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
From http://forum.world.st/Oops-I-put-a-halt-in-a-startup-method-td3800163.html :
    My image appears for an instant and then crashes. Is there any way to recover from this?

I made some progress, but I'm not sure I'm on the right track...
  I built a debug VM and found primitivePerform, which is apparently called by the following:
    FeaturesDB perform: #startUp: with: resuming

  How will I know which call to skip/break on? Maybe there is there a way, from the VM side, to get the receiver class name as a string? If I knew that the receiver was FeaturesDB, that would be the one...

And then once I have the right call, can I just skip over it?

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Mariano Martinez Peck
Sean: it may be difficult/impossible. But....you may want to try invoking the function say printOop() from the XCode console.
If you read my post:  http://marianopeck.wordpress.com/2011/04/23/how-to-debug-the-vm/

Then instead of doing "(gdb) call printAllStacks()"  you can try something like "(gdb) call printOop(526237628)"  and that will print something like "an XXX class".
Of course, you need to replace 526237628  with the real OOP of your receiver object.

Good luck!

On Fri, Sep 9, 2011 at 5:35 AM, Sean P. DeNigris <[hidden email]> wrote:
From
http://forum.world.st/Oops-I-put-a-halt-in-a-startup-method-td3800163.html :
   My image appears for an instant and then crashes. Is there any way to
recover from this?

I made some progress, but I'm not sure I'm on the right track...
 I built a debug VM and found primitivePerform, which is apparently called
by the following:
   FeaturesDB perform: #startUp: with: resuming

 How will I know which call to skip/break on? Maybe there is there a way,
from the VM side, to get the receiver class name as a string? If I knew that
the receiver was FeaturesDB, that would be the one...

And then once I have the right call, can I just skip over it?

Sean


--
View this message in context: http://forum.world.st/Fwd-Oops-I-put-a-halt-in-a-startup-method-tp3800729p3800729.html
Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners



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


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
Okay, I have the class name. Now, the big question (I went down the rabbit hole and got lost): where/how exactly do I skip just this one method invocation? I looked from executeNewMethod to activateCoggedNewMethod and I'm not sure how to jump out and leave everything (pushes, pops) clean.

Thanks.
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Thanks Igor and Mariano. I recovered the image. Just in case anyone ever has a similar problem, the solution was:

1. Test for selector in CoInterpreter>>commonSend
       ...
       (messageSelector = #halt) ifFalse: [ "the conditional was added"
       self internalFindNewMethod.
       self internalExecuteNewMethod  ].

       self fetchNextBytecode.

2. Manually edit the condition in gcc3x-cointerp.c:
       char* realSelector = GIV(messageSelector) + BaseHeaderSize;
       if (strncmp(realSelector, "halt", 4) == 0)
              puts("Skipping halt...");
       else { ...

Although I lost the better part of a day, it's a very powerful feeling to start building basic VM skills and know that errors that used to be magical and fatal can now be resolved...

Cheers,
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

David T. Lewis
On Fri, Sep 09, 2011 at 03:17:39PM -0700, Sean P. DeNigris wrote:

> Thanks Igor and Mariano. I recovered the image. Just in case anyone ever has
> a similar problem, the solution was:
>
> 1. Test for selector in CoInterpreter>>commonSend
>        ...
>        (messageSelector = #halt) ifFalse: [ "the conditional was added"
>        self internalFindNewMethod.
>        self internalExecuteNewMethod  ].
>
>        self fetchNextBytecode.
>
> 2. Manually edit the condition in gcc3x-cointerp.c:
>        char* realSelector = GIV(messageSelector) + BaseHeaderSize;
>        if (strncmp(realSelector, "halt", 4) == 0)
>               puts("Skipping halt...");
>        else { ...
>
> Although I lost the better part of a day, it's a very powerful feeling to
> start building basic VM skills and know that errors that used to be magical
> and fatal can now be resolved...

Nice job Sean! Not a bad day's work for a "VM beginner" :-)

Dave

_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
David T. Lewis wrote
Nice job Sean! Not a bad day's work for a "VM beginner" :-)
I had a lot of help!
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote
2. Manually edit the condition in gcc3x-cointerp.c:
I needed to skip a message send from the VM again, so I updated the conditional to be more general:
                char* realSelector = GIV(messageSelector) + BaseHeaderSize;
                char* selectorToSkip = "restoreFrom:";
                int selectorLength = lengthOf(messageSelector);
                int sameSize = selectorLength == strlen(selectorToSkip);
                int matches = strncmp(realSelector, selectorToSkip, selectorLength) == 0;
                if (sameSize && matches)
                    printf("Skipping %s...", selectorToSkip);
                else {

Also at https://gist.github.com/1434683
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
The full procedure I followed was:
1. Download (from Jenkins):
  a. the cog source code from Jenkins https://ci.lille.inria.fr/pharo/view/Cog/job/Cog%20Git%20Tracker%20(blessed)/lastSuccessfulBuild/artifact/cog.tar.gz
  b. the vmmaker image https://ci.lille.inria.fr/pharo/view/Cog/job/Cog%20Git%20Tracker%20(blessed)/lastSuccessfulBuild/artifact/vmmaker-image.zip
2. Setup folders
  a. Unzip cog
  b. Extract the vmmaker image files (image, changes, source) to cog/image
3. Create (Smalltalk part of) hook to skip selector - CoInterpreter>>commonSend should look like https://gist.github.com/1434823
4. Generate (Slang and CMake configuration info)
  In the vmmaker image, doIt:
        CogCocoaIOSConfig new "Cocoa Jit"
                addExternalPlugins: #( FT2Plugin );
                generateForDebug; "will be a debug build"
                generateSources; "Slang -> C"
                generate. "CMake configuration"
4. Configure (in this case for Xcode)
  a. From command line, "cd cog/build; cmake -G Xcode"
  b. For Lion: In Xcode, choose gcc as project compiler (project will be in pwd when you did the CMake i.e. cog/build)

5. Create (C part of) hook to skip selector
  a. In Xcode, do a text search for "skipMe", which you'll find in gcc3x-cointerp.c
  b. Replace the first branch of the boilerplate conditional to look like https://gist.github.com/1434683 (replace selectorToSkip with your selector)
6. Build & Run
  a. Select CogVM from the "Scheme" dropdown
  b. Click the "Run" button

Your image should run normally (but slowly), skipping the requested selector. You can even put in some breakpoints and play.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Luc Fabresse
Really nice!
Thanks Sean.

#Luc


2011/12/5 Sean P. DeNigris <[hidden email]>
The full procedure I followed was:
1. Download (from Jenkins):
 a. the cog source code from Jenkins
https://ci.lille.inria.fr/pharo/view/Cog/job/Cog%20Git%20Tracker%20(blessed)/lastSuccessfulBuild/artifact/cog.tar.gz
 b. the vmmaker image
https://ci.lille.inria.fr/pharo/view/Cog/job/Cog%20Git%20Tracker%20(blessed)/lastSuccessfulBuild/artifact/vmmaker-image.zip
2. Setup folders
 a. Unzip cog
 b. Extract the vmmaker image files (image, changes, source) to cog/image
3. Create (Smalltalk part of) hook to skip selector -
CoInterpreter>>commonSend should look like https://gist.github.com/1434823
4. Generate (Slang and CMake configuration info)
 In the vmmaker image, doIt:
       CogCocoaIOSConfig new "Cocoa Jit"
               addExternalPlugins: #( FT2Plugin );
               generateForDebug; "will be a debug build"
               generateSources; "Slang -> C"
               generate. "CMake configuration"
4. Configure (in this case for Xcode)
 a. From command line, "cd cog/build; cmake -G Xcode"
 b. For Lion: In Xcode, choose gcc as project compiler (project will be in
pwd when you did the CMake i.e. cog/build)
http://forum.world.st/file/n4161823/Screen_Shot_2011-12-05_at_1.52.24_PM.png
5. Create (C part of) hook to skip selector
 a. In Xcode, do a text search for "skipMe", which you'll find in
gcc3x-cointerp.c
 b. Replace the first branch of the boilerplate conditional to look like
https://gist.github.com/1434683 (replace selectorToSkip with your selector)
6. Build & Run
 a. Select CogVM from the "Scheme" dropdown
 b. Click the "Run" button

Your image should run normally (but slowly), skipping the requested
selector. You can even put in some breakpoints and play.

--
View this message in context: http://forum.world.st/Fwd-Oops-I-put-a-halt-in-a-startup-method-tp3800729p4161823.html
Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Mariano Martinez Peck
You are lucky that since your problem is in the startup list, then the CompiledMethod was not yet converted to machine code. Because if it was, then the method execution does NOT go by #commonSend: but rather from a different place. So be careful that that way you are NOT intercepting all times such method is executed :)

On Mon, Dec 5, 2011 at 9:37 PM, Luc Fabresse <[hidden email]> wrote:
Really nice!
Thanks Sean.

#Luc


2011/12/5 Sean P. DeNigris <[hidden email]>

The full procedure I followed was:
1. Download (from Jenkins):
 a. the cog source code from Jenkins
https://ci.lille.inria.fr/pharo/view/Cog/job/Cog%20Git%20Tracker%20(blessed)/lastSuccessfulBuild/artifact/cog.tar.gz
 b. the vmmaker image
https://ci.lille.inria.fr/pharo/view/Cog/job/Cog%20Git%20Tracker%20(blessed)/lastSuccessfulBuild/artifact/vmmaker-image.zip
2. Setup folders
 a. Unzip cog
 b. Extract the vmmaker image files (image, changes, source) to cog/image
3. Create (Smalltalk part of) hook to skip selector -
CoInterpreter>>commonSend should look like https://gist.github.com/1434823
4. Generate (Slang and CMake configuration info)
 In the vmmaker image, doIt:
       CogCocoaIOSConfig new "Cocoa Jit"
               addExternalPlugins: #( FT2Plugin );
               generateForDebug; "will be a debug build"
               generateSources; "Slang -> C"
               generate. "CMake configuration"
4. Configure (in this case for Xcode)
 a. From command line, "cd cog/build; cmake -G Xcode"
 b. For Lion: In Xcode, choose gcc as project compiler (project will be in
pwd when you did the CMake i.e. cog/build)
http://forum.world.st/file/n4161823/Screen_Shot_2011-12-05_at_1.52.24_PM.png
5. Create (C part of) hook to skip selector
 a. In Xcode, do a text search for "skipMe", which you'll find in
gcc3x-cointerp.c
 b. Replace the first branch of the boilerplate conditional to look like
https://gist.github.com/1434683 (replace selectorToSkip with your selector)
6. Build & Run
 a. Select CogVM from the "Scheme" dropdown
 b. Click the "Run" button

Your image should run normally (but slowly), skipping the requested
selector. You can even put in some breakpoints and play.

--
View this message in context: http://forum.world.st/Fwd-Oops-I-put-a-halt-in-a-startup-method-tp3800729p4161823.html
Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners




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


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
Mariano Martinez Peck wrote
You are lucky that since your problem is in the startup list, then the
CompiledMethod was not yet converted to machine code.
Will you explain further? I don't understand.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Luc Fabresse

2011/12/6 Sean P. DeNigris <[hidden email]>

Mariano Martinez Peck wrote
>
> You are lucky that since your problem is in the startup list, then the
> CompiledMethod was not yet converted to machine code.
>

Will you explain further? I don't understand.

IIUC, he meant that it worked the method has not been jitted yet.

#Luc
 

--
View this message in context: http://forum.world.st/Fwd-Oops-I-put-a-halt-in-a-startup-method-tp3800729p4162880.html
Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Mariano Martinez Peck


On Tue, Dec 6, 2011 at 9:22 AM, Luc Fabresse <[hidden email]> wrote:

2011/12/6 Sean P. DeNigris <[hidden email]>


Mariano Martinez Peck wrote
>
> You are lucky that since your problem is in the startup list, then the
> CompiledMethod was not yet converted to machine code.
>

Will you explain further? I don't understand.

IIUC, he meant that it worked the method has not been jitted yet.

Exactly. Beacuse since it is in the startup list, I guess it hasn't yet been jitted (normally, a method is jitted the second time it is used, that is, when it is found in the method cache).
Do a test: once the image has started, send (by hand) such message you were avoiding in the startup list and you will see it won't stop ;)

Once a method has been jitted, the VM doesn't go by #normalSend but rather from something like #ceSend: selector super: superNormalBar to: rcvr numArgs: numArgs
or friends.

If you want to be able to intercep MOST of the method execution, you have to at least trace in the same places of the senders of #sendBreak: selectorString point: selectorLength receiver: receiverOrNil

Cheers



#Luc
 

--
View this message in context: http://forum.world.st/Fwd-Oops-I-put-a-halt-in-a-startup-method-tp3800729p4162880.html
Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners




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


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
In reply to this post by Mariano Martinez Peck
Mariano Martinez Peck wrote
You are lucky that since your problem is in the startup list, then the
CompiledMethod was not yet converted to machine code. Because if it was,
then the method execution does NOT go by #commonSend: but rather from a
different place.
Eliot suggested in http://forum.world.st/Weird-problem-when-adding-a-method-to-StackInterpreter-tp4223429p4237801.html :
Eliot Miranda-2 wrote
But given that the stack vm and the cog vm are semantically equivalent do
you even need to add tracing code to the jit?... why not just use the stack vm...?
Would using the StackVM catch all sends?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Mariano Martinez Peck


Eliot Miranda-2 wrote
>
> But given that the stack vm and the cog vm are semantically equivalent do
> you even need to add tracing code to the jit?... why not just use the
> stack vm...?
>

Would using the StackVM catch all sends?


99%  ;)   If I understand right, in #commonSend you should be trapping all common cases, but you will still be missing some of the special selectors that have special bytecodes associated. Those which are in Smalltalk specialSelectors. Some will finally delegate to #commonSend so no problem. Some will not and hence you won't catch them.
You will be missing (I think) those send from #primitivePerform  #primitiveExecuteMethod,  etc..

 
--
View this message in context: http://forum.world.st/Fwd-Oops-I-put-a-halt-in-a-startup-method-tp3800729p4239755.html
Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners



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


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Oops - I put a halt in a startup method

Sean P. DeNigris
Administrator
Mariano Martinez Peck wrote
99%  ;)   If I understand right, in #commonSend you should be trapping all
common cases
This seems to be the case. I had to bypass some startup items again when my image mysteriously wouldn't successfully start. I followed the same steps as last time, using the StackCocoa VM, and commonSend caught all the sends that I was interested in.

Sean
Cheers,
Sean