[Pharo-dev] Debugging Morphs (was Re: Questions about Athens)

Camillo Bruni camillobruni at gmail.com
Fri Nov 1 12:06:56 EDT 2013


On 2013-11-01, at 16:44, btc at openinworld.com wrote:

> kilon alios wrote:
>> About the problem to recreate it all it takes is a demo := AthensDemoMorph
>> new openInWorld . It opens the morph with the Athens grey box, I save the
>> image , close pharo, open pharo which reloads the image automagically and
>> BOOM Red Box of Doom :) My other tries also are based on AthensDemoMorph
>> since I cant find documentation to do things differently.
>> 
>> So lets get to the questions
>> 
>> 6) Also why there is a Red Box of Doom in the first place ?
>>  
> 
> See #drawErrorOn: call from...
> 
> Morph>>fullDrawOn:
>   self visible ifFalse: [^ self].
>   (aCanvas isVisible: self fullBounds) ifFalse:[^self].    (self hasProperty: #errorOnDraw) ifTrue:[^self drawErrorOn: aCanvas].    [
>     "calls to each Morph's drawing stuff"
>   ] on: Error do:
>   [:err |
>       "Smalltalk at: #morphDebugOnce ifPresent: [ Smalltalk remove: #morphDebugOnce. self halt ].
>       self setProperty: #errorOnDraw toValue: true.
>       self setProperty: #drawError toValue: err freeze.
>       ^ self drawErrorOn: aCanvas      ]
> ---------------
> In the past I have successfully debugged a morph by adding something like the commented line.  Although I can't quite remember if 'self halt' is correct.  Perhaps it should be 'err raise'.   Perhaps others with more experience of the debugger internals can comment. 
> From a workspace just evaluate 'Smalltalk at: #morphDebugOnce put: #anything' before opening the morph. Or if the morph is already open and you have a reference theMorph, then you can try 'theMorph setProperty: #errorOnDraw toValue: false' to cause the bad morph code to run again.  You can get a reference to an existing morph by enabling 'Create textual references to dropped morphs' from the window menu of a Workspace - then from the window menu select 'inspect variables'
> 
> Now what would be really interesting is if in place of my commented line, the debugging context of the error was serialized using Fuel to a variable and then clicking on the red-square-of-death brought up a debugger on that.  Something like this...
> 
> Morph>>fullDrawOn:
>   self visible ifFalse: [^ self].
>   (aCanvas isVisible: self fullBounds) ifFalse:[^self].    (self hasProperty: #errorOnDraw) ifTrue:[^self drawErrorOn: aCanvas debugOn: (self property: #drawError) ].    [
>     "calls to each Morph's drawing stuff"
>   ] on: Error do:
>   [:err |
>       self setProperty: #errorOnDraw toValue: true.
>       self setProperty: #drawError toValue: (Fuel serializedDebuggingContextOf: err.  "***".
>       ^ self drawErrorOn: aCanvas      ]
> "*** Disclaimer: I haven't used Fuel yet, so I don't have the faintest idea what the proper method here should be."

You have in the halo menu an entry "debug drawing error" which does what you want. As you can see there is already the line: 
> 
>       self setProperty: #drawError toValue: err freeze.

which serializes the whole error (no need to use fuel as long as you stay in the image...).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 447 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20131101/0bb85090/attachment.asc>


More information about the Pharo-dev mailing list