Hi,
I have observe strange behavior of MethodContext>>printOn: and ContextPart>>currentLineInFile Eval [ thisContext print. 1. ] This code outputs: UndefinedObject>>executeStatements (test.st:3), line is incorrect, I think it should be 2. Eval [ thisContext currentLineInFile printNl. 1. ] This code outputs: 2, as expected. I look at the MethodContext>>printOn: method and there is ContextPart>>currentLineInFile called, so why it outputs different line number? _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
On 07/14/2011 08:25 PM, Ladislav Marek wrote:
> I have observe strange behavior of MethodContext>>printOn: and > ContextPart>>currentLineInFile > > Eval [ > thisContext print. > 1. > ] > > This code outputs: UndefinedObject>>executeStatements (test.st:3), > line is incorrect, I think it should be 2. > > Eval [ > thisContext currentLineInFile printNl. > 1. > ] > > This code outputs: 2, as expected. I look at the > MethodContext>>printOn: method and there is > ContextPart>>currentLineInFile called, so why it outputs different > line number? It's an off-by-one error. This is the compiled bytecode for your first example: 0: source line 2 push Global Variable[0] = ContextPart 2: send special message #thisContext 4: send selector 1, 0 args = #printNl 6: source line 2 pop stack top 8: push 1 return stack top The instruction pointer when sending #printNl is already 6. The call to #currentLineInFile prints erroneously takes the "source line" bytecode at address 6 into account, and prints 2+2-1 = 3. This patch fixes it: diff --git a/kernel/ContextPart.st b/kernel/ContextPart.st index bfcf8d5..dc11dd3 100644 --- a/kernel/ContextPart.st +++ b/kernel/ContextPart.st @@ -125,7 +125,7 @@ methods that can be used in inspection or debugging.'> thus making the implementation faster." <category: 'debugging'> - ^self method sourceCodeMap at: self ip + 1 ifAbsent: [1] + ^self method sourceCodeMap at: self ip - 1 ifAbsent: [1] ] debugger [ Thanks for reporting it! Paolo _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Thanks. Nice explanation.
On Fri, Jul 15, 2011 at 09:52, Paolo Bonzini <[hidden email]> wrote: > On 07/14/2011 08:25 PM, Ladislav Marek wrote: >> I have observe strange behavior of MethodContext>>printOn: and >> ContextPart>>currentLineInFile >> >> Eval [ >> thisContext print. >> 1. >> ] >> >> This code outputs: UndefinedObject>>executeStatements (test.st:3), >> line is incorrect, I think it should be 2. >> >> Eval [ >> thisContext currentLineInFile printNl. >> 1. >> ] >> >> This code outputs: 2, as expected. I look at the >> MethodContext>>printOn: method and there is >> ContextPart>>currentLineInFile called, so why it outputs different >> line number? > > It's an off-by-one error. This is the compiled bytecode for your first > example: > > 0: source line 2 > push Global Variable[0] = ContextPart > 2: send special message #thisContext > 4: send selector 1, 0 args = #printNl > 6: source line 2 > pop stack top > 8: push 1 > return stack top > > The instruction pointer when sending #printNl is already 6. The call to > #currentLineInFile prints erroneously takes the "source line" bytecode at > address 6 into account, and prints 2+2-1 = 3. > > This patch fixes it: > > diff --git a/kernel/ContextPart.st b/kernel/ContextPart.st > index bfcf8d5..dc11dd3 100644 > --- a/kernel/ContextPart.st > +++ b/kernel/ContextPart.st > @@ -125,7 +125,7 @@ methods that can be used in inspection or debugging.'> > thus making the implementation faster." > > <category: 'debugging'> > - ^self method sourceCodeMap at: self ip + 1 ifAbsent: [1] > + ^self method sourceCodeMap at: self ip - 1 ifAbsent: [1] > ] > > debugger [ > > Thanks for reporting it! > > Paolo > _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Patch should be applied in DebugTools package too (just saying to be sure).
diff --git a/packages/debug/DebugTools.st b/packages/debug/DebugTools.st index cb41c3b..f7f8695 100644 --- a/packages/debug/DebugTools.st +++ b/packages/debug/DebugTools.st @@ -48,7 +48,7 @@ pointer bytecodes to line numbers.'> ifTrue: [MethodLineMapCache := WeakKeyIdentityDictionary new]. lineMap := MethodLineMapCache at: method ifAbsentPut: [method sourceCodeMap]. - ^lineMap at: aContext ip + 1 ifAbsent: [1] + ^lineMap at: aContext ip - 1 ifAbsent: [1] ] Debugger class >> on: aProcess [ On Fri, Jul 15, 2011 at 10:20, Ladislav Marek <[hidden email]> wrote: > Thanks. Nice explanation. > > On Fri, Jul 15, 2011 at 09:52, Paolo Bonzini <[hidden email]> wrote: >> On 07/14/2011 08:25 PM, Ladislav Marek wrote: >>> I have observe strange behavior of MethodContext>>printOn: and >>> ContextPart>>currentLineInFile >>> >>> Eval [ >>> thisContext print. >>> 1. >>> ] >>> >>> This code outputs: UndefinedObject>>executeStatements (test.st:3), >>> line is incorrect, I think it should be 2. >>> >>> Eval [ >>> thisContext currentLineInFile printNl. >>> 1. >>> ] >>> >>> This code outputs: 2, as expected. I look at the >>> MethodContext>>printOn: method and there is >>> ContextPart>>currentLineInFile called, so why it outputs different >>> line number? >> >> It's an off-by-one error. This is the compiled bytecode for your first >> example: >> >> 0: source line 2 >> push Global Variable[0] = ContextPart >> 2: send special message #thisContext >> 4: send selector 1, 0 args = #printNl >> 6: source line 2 >> pop stack top >> 8: push 1 >> return stack top >> >> The instruction pointer when sending #printNl is already 6. The call to >> #currentLineInFile prints erroneously takes the "source line" bytecode at >> address 6 into account, and prints 2+2-1 = 3. >> >> This patch fixes it: >> >> diff --git a/kernel/ContextPart.st b/kernel/ContextPart.st >> index bfcf8d5..dc11dd3 100644 >> --- a/kernel/ContextPart.st >> +++ b/kernel/ContextPart.st >> @@ -125,7 +125,7 @@ methods that can be used in inspection or debugging.'> >> thus making the implementation faster." >> >> <category: 'debugging'> >> - ^self method sourceCodeMap at: self ip + 1 ifAbsent: [1] >> + ^self method sourceCodeMap at: self ip - 1 ifAbsent: [1] >> ] >> >> debugger [ >> >> Thanks for reporting it! >> >> Paolo >> > _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
On 07/15/2011 06:03 PM, Ladislav Marek wrote:
> Patch should be applied in DebugTools package too (just saying to be sure). > > diff --git a/packages/debug/DebugTools.st b/packages/debug/DebugTools.st > index cb41c3b..f7f8695 100644 > --- a/packages/debug/DebugTools.st > +++ b/packages/debug/DebugTools.st > @@ -48,7 +48,7 @@ pointer bytecodes to line numbers.'> > ifTrue: [MethodLineMapCache := WeakKeyIdentityDictionary new]. > lineMap := MethodLineMapCache at: method > ifAbsentPut: [method sourceCodeMap]. > - ^lineMap at: aContext ip + 1 ifAbsent: [1] > + ^lineMap at: aContext ip - 1 ifAbsent: [1] > ] > > Debugger class>> on: aProcess [ > Right, thanks! Paolo _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
On 07/15/2011 06:33 PM, Paolo Bonzini wrote:
> On 07/15/2011 06:03 PM, Ladislav Marek wrote: >> Patch should be applied in DebugTools package too (just saying to be >> sure). >> >> diff --git a/packages/debug/DebugTools.st b/packages/debug/DebugTools.st >> index cb41c3b..f7f8695 100644 >> --- a/packages/debug/DebugTools.st >> +++ b/packages/debug/DebugTools.st >> @@ -48,7 +48,7 @@ pointer bytecodes to line numbers.'> >> ifTrue: [MethodLineMapCache := WeakKeyIdentityDictionary new]. >> lineMap := MethodLineMapCache at: method >> ifAbsentPut: [method sourceCodeMap]. >> - ^lineMap at: aContext ip + 1 ifAbsent: [1] >> + ^lineMap at: aContext ip - 1 ifAbsent: [1] >> ] >> >> Debugger class>> on: aProcess [ >> > > Right, thanks! Actually, the following fix is needed: diff --git a/kernel/ContextPart.st b/kernel/ContextPart.st index dc11dd3..9f69d60 100644 --- a/kernel/ContextPart.st +++ b/kernel/ContextPart.st @@ -125,7 +125,7 @@ methods that can be used in inspection or debugging.'> thus making the implementation faster." <category: 'debugging'> - ^self method sourceCodeMap at: self ip - 1 ifAbsent: [1] + ^self method sourceCodeMap at: (self ip - 1 max: 1) ifAbsent: [1] ] debugger [ diff --git a/packages/debug/DebugTools.st b/packages/debug/DebugTools.st index f7f8695..49033bd 100644 --- a/packages/debug/DebugTools.st +++ b/packages/debug/DebugTools.st @@ -48,7 +48,7 @@ pointer bytecodes to line numbers.'> ifTrue: [MethodLineMapCache := WeakKeyIdentityDictionary new]. lineMap := MethodLineMapCache at: method ifAbsentPut: [method sourceCodeMap]. - ^lineMap at: aContext ip - 1 ifAbsent: [1] + ^lineMap at: (aContext ip - 1 max: 1) ifAbsent: [1] ] Debugger class >> on: aProcess [ Otherwise the DebugTools testsuite (correctly) fails. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |