Hi all.
I run Squeak in debug mode. I put a breakpoint at function 'primitiveAdd'. By right when I print '3+4' in a workspace, Squeak will break. But, strangely, nothing happen, and the result returned. When I debug '3+4', the breakpoint triggered. What is the problem? Thanks a lot. Ang Beepeng |
Administrator
|
Please be clear step by step. What does "break" mean? What environment are you using?
Aik-Siong Koh
|
In reply to this post by Ang BeePeng
On 25.09.2009, at 15:37, Ang Beepeng wrote:
> > Hi all. > > I run Squeak in debug mode. I put a breakpoint at function > 'primitiveAdd'. > By right when I print '3+4' in a workspace, Squeak will break. But, > strangely, nothing happen, and the result returned. When I debug > '3+4', the > breakpoint triggered. > > What is the problem? SmallInteger addition is done in byte codes, not primitives, for speed. - Bert - |
In reply to this post by askoh
I'm running Squeak in debugging mode. I put a breakpoint at "primitiveAdd". I open a workspace and type "3+4", then I print it.
Message '+' should have cause execution of "primitiveAdd", which lead to Squeak stops at the breakpoint. Instead, the result return as 7, as if code execution do not reach "primitiveAdd" at all. I try again, typing in "3+4". This time, I choose to debug "3+4". I step into "+4", the program stops at breakpoint "primitiveAdd". Therefore, I'm wondering what are the differences between the two. And why, breakpoint at primitiveAdd not triggered? Thanks. Ang Beepeng |
On Fri, Sep 25, 2009 at 8:15 AM, Ang Beepeng <[hidden email]> wrote:
As Bert said, there are special bytecodes for sends of +, -, etc. See Smalltalk specialSelectors. Some of these bytecodes have code to perform the operations on typical types (SmallInteger, Float, 32-bit LargePositiveInteger) inlined into the bytecode implementations. This is a technique known as static receiver type prediction.
You need to put a breakpoint in bytecodePrimAdd
|
Well I'm not sure it question was really answered. So...
The squeak source code is compiled to byte codes. The byte codes are executed by the interpreter loop, one of the byte codes supported is "+" CASE(176) /* bytecodePrimAdd */ which if both values are small integers then performs the add operation within the case statement. Otherwise it has to invoke primitiveFloatAddtoArg to figure out how to add the two values together if they are large integers or floats. If they do not fit that pattern then the message selector "+" is sent. Over the years we have tried to drag logic into the interpreter loop, and reduce the amount of procedure calls needed to run things since making a procedure call is very expensive. When you are doing a print it, you execute the compiled byte codes so we execute the code in the interpreter loop, but when you debug it, then you actually execute individual message send since you are stepping thru the byte codes, which when you do the 3+4 that actually invokes the primitiveAdd method via InstructionStream>interpretNextInstructionFor: In this case the smalltalk stack trace is: 557745736 ContextPart>doPrimitive:method:receiver:args: 557745644 ContextPart>tryPrimitiveFor:receiver:args: 557745260 ContextPart>send:to:with:super: 557745160 ContextPart>send:super:numArgs: 557745068 InstructionStream>interpretNextInstructionFor: 557744976 ContextPart>step 557744884 Process>step 557744776 Process>step: 557724624 Debugger>send 557705372 PluggableButtonMorph>performAction 557705280 PluggableButtonMorph>mouseUp: 557705096 SequenceableCollection>do: 557667688 PluggableButtonMorph>mouseUp: 557667596 Morph>handleMouseUp: 557667504 MouseButtonEvent>sentTo: 557667412 Morph>handleEvent: 557667244 Morph>handleFocusEvent: 557667152 HandMorph>sendFocusEvent:to:clear: 557667060 PasteUpMorph>becomeActiveDuring: 557666968 BlockClosure>on:do: 557666876 PasteUpMorph>becomeActiveDuring: 557666744 HandMorph>sendFocusEvent:to:clear: 557666652 HandMorph>sendEvent:focus:clear: 557666476 HandMorph>sendMouseEvent: 557666384 HandMorph>handleEvent: 557661628 HandMorph>processEvents 557661536 WorldState>doOneCycleNowFor: 557661444 SequenceableCollection>do: 557661352 WorldState>handsDo: 557661260 WorldState>doOneCycleNowFor: 557655656 WorldState>doOneCycleFor: 557655564 PasteUpMorph>doOneCycle 547569852 >spawnNewProcess 547569724 BlockClosure>newProcess (gdb) bt #0 primitiveAdd () at /Users/johnmci/Documents/Squeak3.8.0/src/vm/ interp.c:13190 #1 0x000d6f0c in dispatchFunctionPointer (aFunctionPointer=0xeb754) at /Users/johnmci/Documents/Squeak3.8.0/src/vm/interp.c:4091 #2 0x000d6ef9 in dispatchFunctionPointerOnin (primIdx=1, primTable=0x123d40) at /Users/johnmci/Documents/Squeak3.8.0/src/vm/ interp.c:4087 #3 0x000f6a3b in primitiveResponse () at /Users/johnmci/Documents/ Squeak3.8.0/src/vm/interp.c:19075 #4 0x000eee8c in primitiveDoPrimitiveWithArgs () at /Users/johnmci/ Documents/Squeak3.8.0/src/vm/interp.c:14822 #5 0x000d6f0c in dispatchFunctionPointer (aFunctionPointer=0xeec2c) at /Users/johnmci/Documents/Squeak3.8.0/src/vm/interp.c:4091 #6 0x000e0902 in interpret () at /Users/johnmci/Documents/Squeak3.8.0/ src/vm/interp.c:8406 The difference in how execution happens sometimes exposes really obscure issues where running the code works/does not work, but in the debugger it does not work/work. That of course likely is a problem with the debugger. On 2009-09-25, at 10:52 AM, Eliot Miranda wrote: > > > On Fri, Sep 25, 2009 at 8:15 AM, Ang Beepeng <[hidden email]> > wrote: > > I'm running Squeak in debugging mode. I put a breakpoint at > "primitiveAdd". I > open a workspace and type "3+4", then I print it. > Message '+' should have cause execution of "primitiveAdd", which > lead to > Squeak stops at the breakpoint. > Instead, the result return as 7, as if code execution do not reach > "primitiveAdd" at all. > I try again, typing in "3+4". This time, I choose to debug "3+4". I > step > into "+4", the program stops at breakpoint "primitiveAdd". > Therefore, I'm wondering what are the differences between the two. > And why, > breakpoint at primitiveAdd not triggered? > > As Bert said, there are special bytecodes for sends of +, -, etc. > See Smalltalk specialSelectors. Some of these bytecodes have code > to perform the operations on typical types (SmallInteger, Float, 32- > bit LargePositiveInteger) inlined into the bytecode > implementations. This is a technique known as static receiver type > prediction. > > You need to put a breakpoint in bytecodePrimAdd > > > Thanks. > > Ang Beepeng > -- > View this message in context: http://www.nabble.com/breakpoint-at-primitiveAdd-tp25612297p25613917.html > Sent from the Squeak - Dev mailing list archive at Nabble.com. > > > > -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
Free forum by Nabble | Edit this page |