Skip to content

Commit bf45d29

Browse files
authored
Merge pull request #1259 from guillep/debuginfo3
Using DebugInfo
2 parents d44c279 + 4095df3 commit bf45d29

File tree

8 files changed

+165
-61
lines changed

8 files changed

+165
-61
lines changed

src/NewTools-Debugger-Tests/StDebuggerContextTest.class.st

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@ StDebuggerContextTest >> setUp [
6767
StDebuggerContextTest >> testArgumentsNodes [
6868
|nodes|
6969
debuggerContext context: self contextWithArgs.
70-
nodes := debuggerContext temporaryVariablesNodes select: [ :tempNode | tempNode tempVariable isArgumentVariable ].
70+
nodes := debuggerContext temporaryVariablesNodes select: [ :tempNode | tempNode isArgumentVariable ].
7171
self assert: nodes size equals: 2.
7272
self assert: nodes first key equals: 'i'.
7373
self assert: nodes first variableTag equals: 'arg'.
7474
self assert: nodes first rawValue equals: 4.
75-
self assert: nodes first class equals: StInspectorTempNode.
75+
self assert: nodes first class equals: StInspectorNewTempNode.
7676
self assert: nodes second key equals: 'j'.
7777
self assert: nodes second variableTag equals: 'arg'.
7878
self assert: nodes second rawValue equals: 2.
79-
self assert: nodes second class equals: StInspectorTempNode.
79+
self assert: nodes second class equals: StInspectorNewTempNode.
8080
self deny: (nodes anySatisfy: [:n| n key = 'self'])
8181
]
8282

8383
{ #category : 'tests' }
8484
StDebuggerContextTest >> testArgumentsNodesInBlock [
8585
|nodes|
8686
debuggerContext context: self contextWithArgsInBlock.
87-
nodes := debuggerContext temporaryVariablesNodes select: [ :tempNode | tempNode tempVariable isArgumentVariable ].
87+
nodes := debuggerContext temporaryVariablesNodes select: [ :tempNode | tempNode isArgumentVariable ].
8888
self assert: nodes size equals: 2.
8989
self assert: nodes first key equals: 'a'.
9090
self assert: nodes first variableTag equals: 'arg'.
@@ -254,11 +254,11 @@ StDebuggerContextTest >> testTemporaryVariablesNodes [
254254
self assert: nodes first key equals: 'a'.
255255
self assert: nodes first variableTag equals: 'temp. var'.
256256
self assert: nodes first rawValue equals: 0.
257-
self assert: nodes first tempVariable isTempVariable.
257+
self assert: nodes first isTempVariable.
258258
self assert: nodes second key equals: 'b'.
259259
self assert: nodes second variableTag equals: 'temp. var'.
260260
self assert: nodes second rawValue equals: nil.
261-
self assert: nodes first tempVariable isTempVariable.
261+
self assert: nodes first isTempVariable.
262262
self deny: (nodes anySatisfy: [:n| n key = 'self'])
263263
]
264264

src/NewTools-Debugger-Tests/StDebuggerInspectorTest.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ StDebuggerInspectorTest >> testUpdateLayoutForContextsWithAssertionFailure [
141141
self
142142
assert: assertionFailure actualObject
143143
equals:
144-
((session interruptedContext tempNamed: #aStringOrBlock) at: 2).
144+
((session interruptedContext tempNamed: #aStringOrBlock) at: 1).
145145
self
146146
assert: assertionFailure expectedObject
147147
equals:
148-
((session interruptedContext tempNamed: #aStringOrBlock) at: 1)
148+
((session interruptedContext tempNamed: #aStringOrBlock) at: 2)
149149
]
150150

151151
{ #category : 'tests' }

src/NewTools-Debugger-Tests/StDebuggerTest.class.st

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ StDebuggerTest >> testContextChangedAfterStepOverAndReturn [
330330
{ #category : 'tests - context inspector' }
331331
StDebuggerTest >> testContextTempVarList [
332332
| contextItems inspectorTable |
333-
333+
334334
dbg := self debuggerOn: session.
335335
inspectorTable := dbg inspector getRawInspectorPresenterOrNil attributeTable.
336336

@@ -342,10 +342,10 @@ StDebuggerTest >> testContextTempVarList [
342342
self assert: (contextItems at: 1) class equals: StInspectorSelfNode.
343343

344344
"Next nodes are temps"
345-
self assert: (contextItems at: 2) tempVariable isTempVariable.
346-
self assert: (contextItems at: 3) tempVariable isTempVariable.
347-
self assert: (contextItems at: 4) tempVariable isTempVariable.
348-
self assert: (contextItems at: 5) tempVariable isTempVariable.
345+
self assert: (contextItems at: 2) isTempVariable.
346+
self assert: (contextItems at: 3) isTempVariable.
347+
self assert: (contextItems at: 4) isTempVariable.
348+
self assert: (contextItems at: 5) isTempVariable.
349349

350350
"receiver"
351351
self assert: (contextItems at: 6) rawValue identicalTo: session shortStack first receiver session.
@@ -413,8 +413,8 @@ StDebuggerTest >> testContextTempVarListUpdatesTempsWhenEnteringOrLeavingInlined
413413
assert: (newContextItems at: i)
414414
identicalTo: (contextItems at: i) ].
415415

416-
self assert: (newContextItems at: 9) tempVariable isTempVariable.
417-
self assert: (newContextItems at: 9) tempVariable name equals: 'j'.
416+
self assert: (newContextItems at: 9) isTempVariable.
417+
self assert: (newContextItems at: 9) tempName equals: 'j'.
418418

419419
"We leave inlined block"
420420
2 timesRepeat: [ dbg stepOver ].
@@ -458,11 +458,10 @@ StDebuggerTest >> testContextTempVarListUpdatesTempsWhenEnteringOrLeavingInlined
458458
identicalTo: (contextItems at: i) ].
459459

460460
self assert:
461-
(newContextItems at: contextItems size + 1) tempVariable
462-
isTempVariable.
461+
(newContextItems at: contextItems size + 1) isTempVariable.
463462
self
464463
assert:
465-
(newContextItems at: contextItems size + 1) tempVariable name
464+
(newContextItems at: contextItems size + 1) tempName
466465
equals: 'list'.
467466

468467
"We leave inlined block"
@@ -621,7 +620,6 @@ StDebuggerTest >> testDiscardCodeChangesFor [
621620
{ #category : 'tests - code pane' }
622621
StDebuggerTest >> testDynamicVariableEvaluation [
623622
|activeProcess debuggedProcess|
624-
self skipOnPharoCITestingEnvironment.
625623
debugger := StTestDebuggerProvider new
626624
debuggerWithDynamicVariableSuspendedContext.
627625
debugger initializeCode.
@@ -1308,11 +1306,11 @@ StDebuggerTest >> testUpdateLayoutForContextsIfAssertionFailure [
13081306
self
13091307
assert: assertionFailure actualObject
13101308
equals:
1311-
((session interruptedContext tempNamed: #aStringOrBlock) at: 2).
1309+
((session interruptedContext tempNamed: #aStringOrBlock) at: 1).
13121310
self
13131311
assert: assertionFailure expectedObject
13141312
equals:
1315-
((session interruptedContext tempNamed: #aStringOrBlock) at: 1)
1313+
((session interruptedContext tempNamed: #aStringOrBlock) at: 2)
13161314
]
13171315

13181316
{ #category : 'tests - code pane' }

src/NewTools-Debugger-Tests/StTestDebuggerProvider.class.st

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,25 @@ StTestDebuggerProvider >> debuggerWithDNUContext [
4141

4242
{ #category : 'helpers' }
4343
StTestDebuggerProvider >> debuggerWithDynamicVariableSuspendedContext [
44-
|process|
44+
45+
| process progressSemaphore |
46+
progressSemaphore := Semaphore new.
4547
process := [
46-
TestDynamicVariable value: 42 during: [
47-
self assert:
48-
(thisProcess psValueAt: TestDynamicVariable soleInstance index) = 42.
49-
100 milliSeconds wait.
50-
thisProcess suspend ] ] fork.
51-
session := DebugSession
52-
named: 'test session providerSessionFor:'
53-
on: process
54-
startedAt: process suspendedContext.
55-
session exception:
56-
(OupsNullException fromSignallerContext: process suspendedContext).
57-
" self assert:
58-
(process psValueAt: TestDynamicVariable soleInstance index) = 42."
48+
TestDynamicVariable value: 42 during: [
49+
self assert: (thisProcess psValueAt: TestDynamicVariable soleInstance index) = 42.
50+
"Let's tell our owner that we are inside the block!"
51+
progressSemaphore signal.
52+
"And now we suspend ourselves"
53+
thisProcess suspend ] ] fork.
5954

55+
"We wait until the process reaches the block.
56+
Then we can continue"
57+
progressSemaphore wait.
58+
59+
session := DebugSession named: 'test session providerSessionFor:' on: process startedAt: process suspendedContext.
60+
session exception: (OupsNullException fromSignallerContext: process suspendedContext).
61+
self assert: (process psValueAt: TestDynamicVariable soleInstance index) = 42.
62+
6063
^ self newDebugger
6164
]
6265

src/NewTools-Debugger/StDebugger.class.st

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Class {
8787
'programmaticallyClosed',
8888
'stackAndCodeContainer',
8989
'toolbarPresenter',
90-
'previousASTScope'
90+
'namesVisibleInPreviousScope'
9191
],
9292
#classVars : [
9393
'EnableStackColoring'
@@ -1138,10 +1138,10 @@ StDebugger >> saveGeneratedCodeAndProceed [
11381138
{ #category : 'actions' }
11391139
StDebugger >> selectNextExecutedExpression [
11401140

1141-
| sourceNodeExecuted |
1142-
sourceNodeExecuted := self currentContext sourceNodeExecuted.
1143-
self code selectionInterval:
1144-
(sourceNodeExecuted start to: sourceNodeExecuted stop)
1141+
| interval previouslyExecutedPC |
1142+
previouslyExecutedPC := self currentContext executedPC.
1143+
interval := self currentContext method debugInfo rangeForPC: previouslyExecutedPC.
1144+
self code selectionInterval: (interval first to: interval last)
11451145
]
11461146

11471147
{ #category : 'stack' }
@@ -1555,8 +1555,7 @@ StDebugger >> updateInspectorFromContext: aContext [
15551555
isAssertionFailure:
15561556
self debuggerActionModel isInterruptedContextAnAssertEqualsFailure.
15571557
inspector updateWith: (self newDebuggerContextFor: aContext).
1558-
self flag: #DBG_INSPECTOR_UPDATE_BUG.
1559-
inspector getRawInspectorPresenterOrNil ifNotNil: [ :p | p update ]
1558+
self updateStep
15601559
]
15611560

15621561
{ #category : 'updating' }
@@ -1602,26 +1601,26 @@ StDebugger >> updateStackFromSession: aSession [
16021601
{ #category : 'updating' }
16031602
StDebugger >> updateStep [
16041603

1605-
| previousContext currentASTScope currentContext |
1604+
| previousContext currentlyVisibleNames currentContext |
16061605
previousContext := self currentContext.
16071606
self updateStackFromSession: self session.
16081607
self updateWindowTitle.
16091608
self updateExtensionsFromSession: self session.
16101609
self updateToolbar.
16111610

16121611
currentContext := self currentContext.
1613-
currentASTScope := (currentContext compiledCode sourceNodeForPC:
1614-
currentContext pc) scope.
1612+
currentlyVisibleNames := currentContext temporaryVariableNames.
16151613
self flag: #DBG_INSPECTOR_UPDATE_BUG.
1614+
16161615
inspector getRawInspectorPresenterOrNil ifNotNil: [ :p |
16171616
previousContext == currentContext ifTrue: [ "otherwise, if contexts have changed, updating the stack has already updated all nodes.""Here it is necessary to update temporary nodes if we are still in the same context but in a different scope. This is possible when leaving or entering an optimized block scope."
16181617
p
16191618
updateNodesFromScope:
1620-
(previousASTScope ifNil: [ currentASTScope ])
1621-
to: currentASTScope ].
1619+
(namesVisibleInPreviousScope ifNil: [ currentlyVisibleNames ])
1620+
to: currentlyVisibleNames ].
16221621
p update ].
16231622

1624-
previousASTScope := currentASTScope
1623+
namesVisibleInPreviousScope := currentlyVisibleNames
16251624
]
16261625

16271626
{ #category : 'toolbar' }

src/NewTools-Debugger/StDebuggerContext.class.st

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ StDebuggerContext >> buildInspectorNodes [
6060
nodes := OrderedCollection new.
6161
tempsAndArgs := self temporaryVariablesNodes.
6262
argsNodes := tempsAndArgs select: [ :tempNode |
63-
tempNode tempVariable isArgumentVariable ].
63+
tempNode isArgumentVariable ].
6464
tempsNodes := tempsAndArgs select: [ :tempNode |
65-
tempNode tempVariable isTempVariable ].
65+
tempNode isTempVariable ].
6666
nodes add: self selfNode.
6767
nodes addAll: argsNodes.
6868
nodes addAll: tempsNodes.
@@ -161,8 +161,8 @@ StDebuggerContext >> stackTopNode [
161161
{ #category : 'nodes' }
162162
StDebuggerContext >> temporaryVariablesNodes [
163163

164-
^ self context astScope allTemps collect: [ :temp |
165-
(StInspectorTempNode hostObject: self context) tempVariable: temp ]
164+
^ self context temporaryVariableNames collect: [ :arg1 |
165+
(StInspectorNewTempNode hostObject: self context) tempName: arg1 ]
166166
]
167167

168168
{ #category : 'nodes' }

src/NewTools-Debugger/StRawInspectionPresenter.extension.st

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,20 @@ StRawInspectionPresenter >> selectedPageName [
4444
]
4545

4646
{ #category : '*NewTools-Debugger' }
47-
StRawInspectionPresenter >> updateNodesFromScope: oldASTScope to: newASTScope [
47+
StRawInspectionPresenter >> updateNodesFromScope: oldTemps to: newTemps [
4848

49-
| nodes newTemps oldTemps tempsToRemove tempsToAdd |
50-
oldTemps := oldASTScope allTemps.
51-
newTemps := newASTScope allTemps.
49+
| nodes tempsToRemove tempsToAdd |
5250
tempsToRemove := oldTemps difference: newTemps.
5351
tempsToAdd := newTemps difference: oldTemps.
5452
nodes := self attributeTable roots.
55-
5653
nodes removeAllSuchThat: [ :node |
57-
node class = StInspectorTempNode and: [
58-
tempsToRemove includes: node tempVariable ] ].
54+
node class = StInspectorNewTempNode and: [
55+
tempsToRemove includes: node tempName ] ].
5956
tempsToAdd do: [ :temp |
6057
nodes add:
61-
((StInspectorTempNode hostObject:
58+
((StInspectorNewTempNode hostObject:
6259
self model inspectedObject context)
63-
tempVariable: temp;
60+
tempName: temp;
6461
yourself) ].
6562

6663
self attributeTable roots: nodes
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"
2+
I am a variable node for representing a temporary variable stored in a Context object that has a name attached.
3+
This includes local variables and method parameters.
4+
"
5+
Class {
6+
#name : 'StInspectorNewTempNode',
7+
#superclass : 'StInspectorNode',
8+
#instVars : [
9+
'debugInfo',
10+
'tempName'
11+
],
12+
#category : 'NewTools-Inspector-Model',
13+
#package : 'NewTools-Inspector',
14+
#tag : 'Model'
15+
}
16+
17+
{ #category : 'comparing' }
18+
StInspectorNewTempNode >> = anObject [
19+
20+
self == anObject ifTrue: [ ^ true ].
21+
nil.
22+
self class = anObject class ifFalse: [ ^ false ].
23+
^ tempName = anObject tempName and: [ hostObject = anObject hostObject ]
24+
]
25+
26+
{ #category : 'accessing' }
27+
StInspectorNewTempNode >> children [
28+
^ #()
29+
]
30+
31+
{ #category : 'accessing' }
32+
StInspectorNewTempNode >> debugInfo [
33+
34+
^ debugInfo
35+
]
36+
37+
{ #category : 'accessing' }
38+
StInspectorNewTempNode >> debugInfo: anObject [
39+
40+
debugInfo := anObject
41+
]
42+
43+
{ #category : 'accessing' }
44+
StInspectorNewTempNode >> debugScope [
45+
46+
^ debugInfo debugScopeAt:
47+
(self hostObject executedPC max: self hostObject method initialPC)
48+
]
49+
50+
{ #category : 'comparing' }
51+
StInspectorNewTempNode >> hash [
52+
53+
"Answer an integer value that is related to the identity of the receiver."
54+
55+
^ tempName hash bitXor: (hostObject hash)
56+
]
57+
58+
{ #category : 'accessing' }
59+
StInspectorNewTempNode >> hostObject: aContext [
60+
61+
super hostObject: aContext.
62+
debugInfo := aContext method debugInfo.
63+
]
64+
65+
{ #category : 'accessing' }
66+
StInspectorNewTempNode >> isArgumentVariable [
67+
68+
^ self debugScope isArgumentNamed: tempName
69+
]
70+
71+
{ #category : 'accessing' }
72+
StInspectorNewTempNode >> isTempVariable [
73+
74+
^ self isArgumentVariable not
75+
]
76+
77+
{ #category : 'accessing' }
78+
StInspectorNewTempNode >> key [
79+
80+
^ tempName
81+
]
82+
83+
{ #category : 'accessing' }
84+
StInspectorNewTempNode >> rawValue [
85+
86+
^ self debugScope
87+
readVariableNamed: tempName
88+
fromContext: self hostObject
89+
]
90+
91+
{ #category : 'accessing' }
92+
StInspectorNewTempNode >> tempName [
93+
94+
^ tempName
95+
]
96+
97+
{ #category : 'accessing' }
98+
StInspectorNewTempNode >> tempName: anObject [
99+
100+
tempName := anObject
101+
]
102+
103+
{ #category : 'accessing' }
104+
StInspectorNewTempNode >> variableTag [
105+
106+
^ self isArgumentVariable ifTrue: [ 'arg' ] ifFalse: [ 'temp. var' ]
107+
]

0 commit comments

Comments
 (0)