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: Ladislav Marek
Subject: Re: [Help-smalltalk] ContextPart>>printOn: prints incorrect line
Date: Fri, 15 Jul 2011 18:03:33 +0200

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 <address@hidden> wrote:
> Thanks. Nice explanation.
>
> On Fri, Jul 15, 2011 at 09:52, Paolo Bonzini <address@hidden> 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
>>
>



reply via email to

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