Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler stack items #632

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 7 additions & 65 deletions src/NewTools-Debugger-Tests/StDebuggerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,16 @@ StDebuggerTest >> testNewDebuggerContextFor [

{ #category : 'tests - stack table' }
StDebuggerTest >> testPrintReceiverClassInContext [
|ctx result|
|ctx stream |
ctx := Context sender: nil receiver: Set new method: (Collection>>#add:) arguments: Array new.
result := self debugger printReceiverClassInContext: ctx.
self assert: result equals: 'Set (Collection)'.
stream := WriteStream on: String new.
StContextPrinter printReceiverClassInContext: ctx on: stream.
self assert: stream contents equals: 'Set (Collection)'.

ctx := Context sender: nil receiver: Set new method: (Set>>#add:) arguments: Array new.
result := self debugger printReceiverClassInContext: ctx.
self assert: result equals: 'Set'.
stream := WriteStream on: String new.
StContextPrinter printReceiverClassInContext: ctx on: stream.
self assert: stream contents equals: 'Set'.
]

{ #category : 'tests - receiver inspector' }
Expand Down Expand Up @@ -949,71 +951,11 @@ StDebuggerTest >> testStackTableAfterStepIn [
self assert: stackTableItems equals: session shortStack
]

{ #category : 'tests - stack table' }
StDebuggerTest >> testStackTableElementsPrinting [
| columns classColumn methodColumn method block context |

self debugger session: session.
columns := self initializedDebugger stackTable columns.
classColumn := columns second.
methodColumn := columns third.
"The following column was removed to experiment a new layout, just keeping the test in case of roolback."
"senderColumn := columns third."
method := self class >> #testStackTableElementsPrinting.
block := [ :a | a ].

context := (Context newForMethod: method) setSender: self receiver: self method: method arguments: #( ).
self assert: (classColumn evaluation value: context) equals: self class name.
self assert: (methodColumn evaluation value: context) equals: method selector.
"The following column was removed to experiment a new layout, just keeping the test in case of roolback."
"self assert: (senderColumn evaluation value: context) equals: self stDisplayString."

context := (Context newForMethod: method) setSender: self receiver: self method: block method arguments: #( ).
self assert: (classColumn evaluation value: context) equals: self class name.
self assert: (methodColumn evaluation value: context) equals: block sourceNode sourceCode.
"The following column was removed to experiment a new layout, just keeping the test in case of roolback."
"self assert: (senderColumn evaluation value: context) equals: self stDisplayString."
]

{ #category : 'tests - stack table' }
StDebuggerTest >> testStackTableInitialization [
self assert: self debugger stackTable isNil
]

{ #category : 'tests - stack table' }
StDebuggerTest >> testStackTablePackagesLabels [
|stackTable packageColumn ctx|
self debugger session: session.
stackTable := self initializedDebugger stackTable.
packageColumn := stackTable columns last.

"The method is defined in the same package as its class"
ctx := Context
sender: nil
receiver: nil
method: (StTestDebuggerProvider >> #debuggerWithDNUContext)
arguments: #().
self assert: (packageColumn readObject: ctx) equals: StTestDebuggerProvider package name.

"The extension method is defined in another package than its class"
ctx := Context
sender: nil
receiver: nil
method: (StDebugger >> #inspector)
arguments: #().
self assert: (packageColumn readObject: ctx) equals: StTestDebuggerProvider package name.

"Doit methods have no package."
ctx := Context
sender: nil
receiver: nil
method: (Smalltalk compiler compile: 'DoIt 1 + 1')
arguments: #().
self assert: (packageColumn readObject: ctx) equals: '-'


]

{ #category : 'tests - stack table' }
StDebuggerTest >> testStackTableSelectionChanged [

Expand Down
48 changes: 48 additions & 0 deletions src/NewTools-Debugger/StContextPrinter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Class {
#name : 'StContextPrinter',
#superclass : 'Object',
#category : 'NewTools-Debugger-Model',
#package : 'NewTools-Debugger',
#tag : 'Model'
}

{ #category : 'printing' }
StContextPrinter class >> printContext: aContext [

^ String streamContents: [ :stream |
self printPackage: aContext method package on: stream.
self printReceiverClassInContext: aContext on: stream.
self printMethod: aContext method on: stream ]
]

{ #category : 'printing' }
StContextPrinter class >> printMethod: aCompiledMethod on: aStream [
aStream << '>>'.
aStream << (aCompiledMethod isCompiledBlock
ifTrue: [ aCompiledMethod sourceNode sourceCode ]
ifFalse: [ aCompiledMethod selector ])
]

{ #category : 'printing' }
StContextPrinter class >> printPackage: aPackage on: aStream [

aPackage ifNil: [ ^ self ].
aStream << '['.
aStream << aPackage name asString.
aStream << ']'.
aStream space
]

{ #category : 'printing' }
StContextPrinter class >> printReceiverClassInContext: aContext on: aStream [

| receiverClass methodClass |
receiverClass := aContext receiver class.
methodClass := aContext method methodClass.
aStream << receiverClass name.
receiverClass == methodClass ifTrue: [ ^ self ].
aStream space.
aStream << '('.
aStream << methodClass name.
aStream << ')'
]
50 changes: 5 additions & 45 deletions src/NewTools-Debugger/StDebugger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -760,37 +760,13 @@ StDebugger >> initializeShortcuts: aWindowPresenter [
{ #category : 'stack' }
StDebugger >> initializeStack [

stackTable := self newTable.
stackTable := self newList.
stackTable
activateOnDoubleClick;
whenActivatedDo: [ :selection | self doBrowseClass ].
stackTable
addColumn: ((SpImageTableColumn title: '' evaluated: [ :context | self stackIconForContext: context ])
width: 8;
sortFunction: nil;
yourself);
addColumn: ((SpStringTableColumn title: 'Class' evaluated: [ :context | self printReceiverClassInContext: context ])
displayColor: [ :context | self stackColorForContext: context ];
sortFunction: nil;
yourself);
addColumn: ((SpStringTableColumn title: 'Method' evaluated: [ :context |
| method |
method := context method.
method isCompiledBlock
ifTrue: [ method sourceNode sourceCode ]
ifFalse: [ method selector ] ])
displayColor: [ :context | self stackColorForContext: context ];
sortFunction: nil;
yourself);
addColumn: ((SpStringTableColumn title: 'Package' evaluated: [ :context |
| package |
package := context method package.
package
ifNil: [ '-' ]
ifNotNil: [ package name asString ] ])
displayColor: [ :context | self stackColorForContext: context ];
sortFunction: nil;
yourself).
stackTable display:[:selection| StContextPrinter printContext: selection].
stackTable displayColor:[ :context | self stackColorForContext: context ].
stackTable displayIcon: [ :context| self stackIconForContext: context ].
stackTable transmitDo: [ :context |
stackTable selection isEmpty ifFalse: [
self updateInspectorFromContext: context.
Expand Down Expand Up @@ -935,22 +911,6 @@ StDebugger >> peelToFirstLike: aContext [
self code text: self currentContext sourceCode
]

{ #category : 'printing' }
StDebugger >> printReceiverClassInContext: aContext [

| receiverClass methodClass |
receiverClass := aContext receiver class.
methodClass := aContext method methodClass.
receiverClass == methodClass ifTrue: [ ^ receiverClass name ].
^ (WriteStream on: String new)
nextPutAll: receiverClass name;
space;
nextPut: $(;
nextPutAll: methodClass name;
nextPut: $);
contents
]

{ #category : 'actions' }
StDebugger >> proceedDebugSession [

Expand Down Expand Up @@ -1196,7 +1156,7 @@ StDebugger >> stackHeader [
StDebugger >> stackIconForContext: context [

self unsavedCodeChanges at: context ifAbsent: [ ^ nil ].
^ self iconNamed: #overlayDirty
^ self iconNamed: #repair
]

{ #category : 'specs' }
Expand Down