tode icon indicating copy to clipboard operation
tode copied to clipboard

[Enhancement] Select better stack frame for exceptions

Open rjsargent opened this issue 8 years ago • 2 comments

A number of Smalltalk implementations handle the signalling of some exceptions better by trimming the (shown) stack to the frame 'signalling' the exception. There is no need to show the exception handling frames in many common cases.

For example, when Pharo (3.0) detects a Halt, it shows the frame sending the #halt message as the top of the stack.

VA Smalltalk does similar, especially with MNU errors (which they call DNU).

rjsargent avatar Jun 16 '16 00:06 rjsargent

GBS for VA Smalltalk looks for the following selectors: (#pause #_doesNotUnderstand:args:envId:reason: #doesNotUnderstand: #halt #halt: #breakpointEncountered: #primitiveFailed #error:)

The list is used in the following way to select a "better" stack frame:

"The debugger has already selected a client frame, if it found one
     it preferred or left it nil otherwise. If we have server contexts on
     top, find a preferred frame there."
    top := stack first.
    (top isKindOf: GbxActivation) 
        ifTrue: 
            [priority := 999999.
            stackSearchSelectors := self serverStackSearchSelectors.
            1 to: stack size
                do: 
                    [:idx | 
                    | pri frame |
                    frame := stack at: idx.
                    pri := stackSearchSelectors indexOf: frame gbxSelector.
                    (pri > 0 
                        and: [(frame isKindOf: GbxActivation) 
                        and: [pri < priority 
                        and: [frame isExecutingBlock not
                        and: [frame isBottomOfStack not]]]]) 
                            ifTrue: 
                                [stack size > idx ifTrue: [top := stack at: idx + 1].
                                priority := pri]].
            self selectedFrame: top].

It looks for the frame with one of the special selectors and selects the next one down if it can. Otherwise, it continues with the top of the stack for its choice.

rjsargent avatar Jun 16 '16 01:06 rjsargent

(Well, so much for the "code" markup. Just run it through a formatter and you'll be able to read it.)

rjsargent avatar Jun 16 '16 17:06 rjsargent