The Inbox: Tools-ct.957.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Tools-ct.957.mcz

commits-2
Christoph Thiede uploaded a new version of Tools to project The Inbox:
http://source.squeak.org/inbox/Tools-ct.957.mcz

==================== Summary ====================

Name: Tools-ct.957
Author: ct
Time: 7 March 2020, 5:40:10.429886 pm
UUID: 0d857fa4-a591-e84c-a3a3-960812d52ffa
Ancestors: Tools-mt.955

Fixes a bug in DebuggerMethodMap's rangeForPC lookup

Steps to reproduce:

        c := Object newSubclass.
        c compile: 'foo: foo
                foo = #foo ifTrue: [^ true].
                ^ (foo ifNil: [^ false]) = #bar'.
        c new foo: #bar.
        "Debug it. Step into #foo:, step over #=.
        Before this commit, the selection was '^ true'"

The error was that #findNearbyBinaryIndex: uses to return the lower possible index if there is no exact match. For debugging, we cannot need this behavior, because we want to select the next operation to be executed.

Furthermore, this commit refactors some duplication with DebuggerMethodMapForFullBlockCompiledMethod. Please review!

Reuploaded due to wrong ancestry (lesson learnt: you must not press reparent during the save version dialog is open ...). Replaces Tools-ct.956.

=== text below is ignored ===
Ancestors: Tools-mt.955

=============== Diff against Tools-mt.955 ===============

Item was changed:
  ----- Method: DebuggerMethodMap>>rangeForPC:in:contextIsActiveContext: (in category 'source mapping') -----
  rangeForPC: contextsConcretePC in: method contextIsActiveContext: contextIsActiveContext
+ "Answer the indices in the source code for the supplied pc. If the context is the active context (is at the hot end of the stack) then its pc is the current pc. But if the context isn't, because it is suspended sending a message, then its current pc is the previous pc."
- "Answer the indices in the source code for the supplied pc.
- If the context is the actve context (is at the hot end of the stack)
- then its pc is the current pc.  But if the context isn't, because it is
- suspended sending a message, then its current pc is the previous pc."
 
+ | pc i end sortedMap |
- | pc i end |
  pc := method abstractPCForConcretePC: (contextIsActiveContext
+ ifTrue: [contextsConcretePC]
+ ifFalse: [(method pcPreviousTo: contextsConcretePC)
+ ifNil: [contextsConcretePC]]).
+ (self abstractSourceMapForMethod: method)
+ at: pc
+ ifPresent: [:range | ^ range].
+ sortedMap := self sortedSourceMapForMethod: method.
+ sortedMap isEmpty ifTrue: [^ 1 to: 0].
+ i := sortedMap
+ findBinaryIndex: [:assoc | pc - assoc key]
+ ifNone: [:lower :upper | upper].
+ i < 1 ifTrue: [^ 1 to: 0].
+ i > sortedMap size ifTrue: [
+ end := sortedMap inject: 0 into: [:prev :this |
+ prev max: this value last].
+ ^ end + 1 to: end].
+ ^ (sortedMap at: i) value!
- ifTrue: [contextsConcretePC]
- ifFalse: [(method pcPreviousTo: contextsConcretePC)
- ifNotNil: [:prevpc| prevpc]
- ifNil: [contextsConcretePC]]).
- (self abstractSourceMap includesKey: pc) ifTrue:
- [^self abstractSourceMap at: pc].
- sortedSourceMap ifNil:
- [sortedSourceMap := self abstractSourceMap associations
- replace: [ :each | each copy ];
- sort].
- sortedSourceMap isEmpty ifTrue: [^1 to: 0].
- i := sortedSourceMap findNearbyBinaryIndex: [:assoc| pc - assoc key].
- i < 1 ifTrue: [^1 to: 0].
- i > sortedSourceMap size ifTrue:
- [end := sortedSourceMap inject: 0 into:
- [:prev :this | prev max: this value last].
- ^end+1 to: end].
- ^(sortedSourceMap at: i) value
-
- "| method source scanner map |
- method := DebuggerMethodMap compiledMethodAt: #rangeForPC:in:contextIsActiveContext:.
- source := method getSourceFromFile asString.
- scanner := InstructionStream on: method.
- map := method debuggerMap.
- Array streamContents:
- [:ranges|
- [scanner atEnd] whileFalse:
- [| range |
- range := map rangeForPC: scanner pc in: method contextIsActiveContext: true.
- ((map abstractSourceMap includesKey: scanner abstractPC)
-  and: [range first ~= 0]) ifTrue:
- [ranges nextPut: (source copyFrom: range first to: range last)].
- scanner interpretNextInstructionFor: InstructionClient new]]"!

Item was added:
+ ----- Method: DebuggerMethodMap>>sortedSourceMap (in category 'private') -----
+ sortedSourceMap
+
+ ^ sortedSourceMap ifNil: [
+ sortedSourceMap := self abstractSourceMap associations
+ replace: [:each | each copy];
+ sort]!

Item was added:
+ ----- Method: DebuggerMethodMap>>sortedSourceMapForMethod: (in category 'source mapping') -----
+ sortedSourceMapForMethod: aCompiledMethod
+
+ ^ self sortedSourceMap!

Item was changed:
  ----- Method: DebuggerMethodMapForFullBlockCompiledMethods>>abstractSourceMap (in category 'source mapping') -----
  abstractSourceMap
+
+ ^ self shouldNotImplement!
- self shouldNotImplement!

Item was removed:
- ----- Method: DebuggerMethodMapForFullBlockCompiledMethods>>rangeForPC:in:contextIsActiveContext: (in category 'source mapping') -----
- rangeForPC: contextsConcretePC in: method contextIsActiveContext: contextIsActiveContext
- "Answer the indices in the source code for the supplied pc.
- If the context is the actve context (is at the hot end of the stack)
- then its pc is the current pc.  But if the context isn't, because it is
- suspended sending a message, then its current pc is the previous pc."
-
- | pc i end mapForMethod sortedMap |
- pc := method abstractPCForConcretePC: (contextIsActiveContext
- ifTrue: [contextsConcretePC]
- ifFalse: [(method pcPreviousTo: contextsConcretePC)
- ifNotNil: [:prevpc| prevpc]
- ifNil: [contextsConcretePC]]).
- ((mapForMethod := self abstractSourceMapForMethod: method) includesKey: pc) ifTrue:
- [^mapForMethod at: pc].
- sortedSourceMap ifNil:
- [sortedSourceMap := IdentityDictionary new].
- sortedMap := sortedSourceMap
- at: method
- ifAbsentPut: [mapForMethod associations
- replace: [ :each | each copy ];
- sort].
- sortedMap isEmpty ifTrue: [^1 to: 0].
- i := sortedMap findNearbyBinaryIndex: [:assoc| pc - assoc key].
- i < 1 ifTrue: [^1 to: 0].
- i > sortedMap size ifTrue:
- [end := sortedMap inject: 0 into:
- [:prev :this | prev max: this value last].
- ^end+1 to: end].
- ^(sortedMap at: i) value
-
- "| method source scanner map |
- method := DebuggerMethodMapForFullBlockCompiledMethods compiledMethodAt: #rangeForPC:in:contextIsActiveContext:.
- source := method getSourceFromFile asString.
- scanner := InstructionStream on: method.
- map := method debuggerMap.
- Array streamContents:
- [:ranges|
- [scanner atEnd] whileFalse:
- [| range |
- range := map rangeForPC: scanner pc in: method contextIsActiveContext: true.
- ((map abstractSourceMap includesKey: scanner abstractPC)
-  and: [range first ~= 0]) ifTrue:
- [ranges nextPut: (source copyFrom: range first to: range last)].
- scanner interpretNextInstructionFor: InstructionClient new]]"!

Item was added:
+ ----- Method: DebuggerMethodMapForFullBlockCompiledMethods>>sortedSourceMap (in category 'source mapping') -----
+ sortedSourceMap
+
+ ^ self shouldNotImplement!

Item was added:
+ ----- Method: DebuggerMethodMapForFullBlockCompiledMethods>>sortedSourceMapForMethod: (in category 'source mapping') -----
+ sortedSourceMapForMethod: method
+
+ sortedSourceMap ifNil: [
+ sortedSourceMap := IdentityDictionary new].
+ ^ sortedSourceMap
+ at: method
+ ifAbsentPut: [(self abstractSourceMapForMethod: method) associations
+ replace: [ :each | each copy ];
+ sort]!