pharo-contributions / MethodProxies

A library to decorate and control method execution.
6 stars 7 forks source link

Problem proxying BlockClosure >> #value #20

Open PalumboN opened 2 days ago

PalumboN commented 2 days ago

If I install a method proxy in BlockClosure >> #value:

handler :=  MpCountingHandler new.
p := MpMethodProxy 
    onMethod: BlockClosure >> #value 
    handler: handler.
p install.
p enableInstrumentation.

And then save the image.

I get this error (and the image is broken: it's impossible to close the debugger to escape the bug and the image was saved in this state):

image

It seems like the trapContext is not the expected...

PalumboN commented 2 days ago

I changed the method to find the correct context using:

            trapContext := thisContext findNextUnwindContextUpTo: nil.
            [
                trapContext ifNil: [ "Nothing to do here"
                    'Abort method proxy' traceCr.
                    ^ nil
                ]. 
                trapContext hasTemporaryVariableNamed: 'wasMeta'.
            ] whileFalse: [ trapContext := trapContext sender ].

It avoids the bug during the current session (no exception is thrown) 👍 But when you rerun the saved image this error appears 👎

image

Anyway, you can close this debugger and continue using the image normally... I'll send a PR.

Gabriel-Darbord commented 3 hours ago

I also get that same first error when closing a debugger after another error occured due to the instrumentation (e.g. #22, or when my own instrumentation code fails). I did not instrument blocks, and the debugger is not post-mortem. To close the debugger, I return an empty expression and proceed twice.