>From c1d8920083202bff2a3e39eaea55460c6446dabe Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio
Date: Wed, 16 Oct 2013 20:43:00 +0200
Subject: [PATCH] Fix an issue in the current line number
---
ChangeLog | 10 ++++++++++
kernel/CompildCode.st | 39 ++++++++++++++++++++------------------
kernel/ContextPart.st | 15 +++++++++------
packages/debug/ChangeLog | 4 ++++
packages/debug/DebugTools.st | 19 +++++++++++--------
packages/debug/debugtests.st | 45 ++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 100 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cd33f5d..23791f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-10-15 Gwenael Casaccio
+
+ * kernel/ContextPart.st: Fix >>#currentLine the previous
+ implementation had a bad ip index and diddn't raise an exception
+ if the instruction pointer was incorrect.
+ * kernel/CompildCode.st: Fix >>#sourceCodeMap since ip points to
+ the next bytecode which could be a line number, there could be a off
+ by one error. Thus when the line number bytecode is met it's stored on
+ the next bytecode.
+
2013-10-07 Paolo Bonzini
* kernel/BlkClosure.st: Fix off-by-one using the sp variable
diff --git a/kernel/CompildCode.st b/kernel/CompildCode.st
index f42034f..fd3f1b8 100644
--- a/kernel/CompildCode.st
+++ b/kernel/CompildCode.st
@@ -458,24 +458,27 @@ superclass for blocks and methods'>
]
sourceCodeMap [
- "Answer an array which maps bytecode indices to source code
- line numbers. 0 values represent invalid instruction
- pointer indices."
-
-
- | map line first |
- map := ByteArray new: self size.
- line := 1.
- first := true.
- self allByteCodeIndicesDo:
- [:each :byte :operand |
- (self class bytecodeInfoTable at: byte * 4 + 4) >= 128
- ifTrue:
- [first ifFalse: [line := operand].
- first := false.
- operand > 255 ifTrue: [map := map asArray]].
- map at: each put: line].
- ^map
+ "Answer an array which maps bytecode indices to source code
+ line numbers. 0 values represent invalid instruction
+ pointer indices."
+
+
+ | map line first next |
+ map := ByteArray new: self size.
+ next := -1.
+ line := 1.
+ first := true.
+ self allByteCodeIndicesDo:
+ [ :each :byte :operand |
+ (self class bytecodeInfoTable at: byte * 4 + 4) >= 128
+ ifTrue:
+ [ first ifFalse: [ next := operand ].
+ first := false.
+ operand > 255 ifTrue: [ map := map asArray ] ].
+ map at: each put: line.
+ next = -1 ifFalse: [ line := next.
+ next := -1. ] ].
+ ^ map
]
jumpDestinationAt: anIndex forward: aBoolean [
diff --git a/kernel/ContextPart.st b/kernel/ContextPart.st
index 2c6d5e8..55411c6 100644
--- a/kernel/ContextPart.st
+++ b/kernel/ContextPart.st
@@ -244,12 +244,15 @@ methods that can be used in inspection or debugging.'>
]
currentLine [
- "Answer the 1-based number of the line that is pointed to by the receiver's
- instruction pointer. The DebugTools package caches information,
- thus making the implementation faster."
-
-
- ^self method sourceCodeMap at: (self ip - 1 max: 1) ifAbsent: [1]
+ "Answer the 1-based number of the line that is pointed to by the receiver's
+ instruction pointer. The DebugTools package caches information,
+ thus making the implementation faster."
+
+
+ | res |
+ res := self method sourceCodeMap at: self ip + 1.
+ ^ res = 0 ifTrue: [ self error: 'IP is not correct' ]
+ ifFalse: [ res ]
]
debugger [
diff --git a/packages/debug/ChangeLog b/packages/debug/ChangeLog
index e91de3f..b660c9a 100644
--- a/packages/debug/ChangeLog
+++ b/packages/debug/ChangeLog
@@ -1,3 +1,7 @@
+2013-10-15 Gwenael Casaccio
+
+ * debugtests.st: Add test for currentLineInFile.
+
2013-06-18 Gwenael Casaccio
* DebugTools.st: Add >>#receiver for VisualGST.
diff --git a/packages/debug/DebugTools.st b/packages/debug/DebugTools.st
index b7d4b78..b2c7b65 100644
--- a/packages/debug/DebugTools.st
+++ b/packages/debug/DebugTools.st
@@ -41,14 +41,17 @@ pointer bytecodes to line numbers.'>
MethodLineMapCache := nil.
Debugger class >> currentLineIn: aContext [
-
- | lineMap method |
- method := aContext method.
- MethodLineMapCache isNil
- ifTrue: [MethodLineMapCache := WeakKeyIdentityDictionary new].
- lineMap := MethodLineMapCache at: method
- ifAbsentPut: [method sourceCodeMap].
- ^lineMap at: (aContext ip - 1 max: 1) ifAbsent: [1]
+
+ | lineMap method res |
+ method := aContext method.
+ MethodLineMapCache isNil
+ ifTrue: [MethodLineMapCache := WeakKeyIdentityDictionary new].
+ lineMap := MethodLineMapCache at: method
+ ifAbsentPut: [method sourceCodeMap].
+ res := lineMap at: (aContext ip + 1).
+ ^ res = 0
+ ifTrue: [ self error: 'IP is not correct' ]
+ ifFalse: [ res ]
]
Debugger class >> on: aProcess [
diff --git a/packages/debug/debugtests.st b/packages/debug/debugtests.st
index c1d142a..c306047 100644
--- a/packages/debug/debugtests.st
+++ b/packages/debug/debugtests.st
@@ -29,6 +29,38 @@
+SmallInteger extend [
+
+ dbgPrintNl [
+
+ ^ self dbgPrintString
+ ]
+
+ dbgPrintString [
+ "Return the base 10 representation of the receiver"
+
+
+ ^self dbgPrintString: 10
+ ]
+
+ dbgPrintString: baseInteger [
+ "Return the base baseInteger representation of the receiver"
+
+
+ | num string |
+ ^self < self zero
+ ifFalse:
+ [string := String new: (self floorLog: baseInteger) + 1.
+ self replace: string withStringBase: baseInteger]
+ ifTrue:
+ [num := self negated.
+ string := String new: (num floorLog: baseInteger) + 2.
+ string at: 1 put: $-.
+ num replace: string withStringBase: baseInteger]
+ ]
+]
+
+^L
TestCase subclass: DebuggerTest [
@@ -264,6 +296,19 @@ TestCase subclass: DebuggerTest [
self deny: notReached
]
+ testRegressionCurrentLine [
+
+
+ | debugger |
+ debugger := self debuggerOn: [ 1 dbgPrintNl ].
+ debugger step.
+
+ #(34 36 39 43 46 51 53) doWithIndex: [ :each :i |
+ self assert: debugger suspendedContext currentLineInFile == each.
+ debugger step.
+ ]
+ ]
+
w [
self x: [:foo | ^foo]
--
1.8.1.2