help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] ContextPart>>printOn: prints incorrect line


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] ContextPart>>printOn: prints incorrect line
Date: Fri, 15 Jul 2011 09:52:45 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc15 Mnenhy/0.8.3 Thunderbird/3.1.10

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]