Skip to content

Skip command has strange behavior when you skipAssignement #19

Closed

Description

@adri09070

In SindarinDebugger, when you skip an assignment, the skip command actually assigns nil to the variable instead.
This is not a behavior you'd be expecting as, if a variable a equals 1, and you skip: a:=3, you'd expect a to have the value 1 and not nil:

skip
	"If it is a message send or assignment, skips the execution of the current instruction, and puts nil on the execution stack."

	self skipWith: nil
skipWith: replacementValue
	"If it is a message-send or assignment, skips the execution of the current instruction, and puts the replacementValue on the execution stack."

	"If the current node is a message send or assignment"

	(self node isMessage not
		and: [ self node isAssignment not ])
		ifTrue: [ ^ self ].
	self node isMessage
		ifTrue: [ ^ self skipMessageNodeWith: replacementValue ].
	self node isAssignment
		ifTrue: [ ^	self skipAssignmentNodeWith: replacementValue ]
skipAssignmentNodeWith: replacementValue
	self context pop.
	"Pop the value to be assigned"
	"Push the replacement value on the context's value stack, to simulate that the assignment happened and had value nil"
	self context push: replacementValue.
	"Increase the pc to go over the assignment"
	self context pc: self context pc + 2.
	"Execute bytecodes the debugger usually executes without stopping the execution (for example popping the return value of the just executed message send if it is not used afterwards)"
	self debugSession
		stepToFirstInterestingBytecodeIn: self debugSession interruptedProcess

So, we should have a version of skip that completely skips an assignment (by default instead of assigning nil) and another version that assigns to the variable a replacement value that you can specify.

Furthermore, skipAssignmentNodeWith method increments pc by 2 to go over the assignment but an assignment doesn't necessarily involve two bytes.

Finally, some tests should be written again as there is a test in which an assignment of a is skipped with 3 as a replacement value but the test verifies that it is not 3:

testSkipWith
	| a p scdbg |
	self skipOnPharoCITestingEnvironment.
	a := 1.
	scdbg := SindarinDebugger
		debug: [ a := 2.
			p := Point x: 2 y: 3 ].
	scdbg skipWith: 3.
	self assert: a equals: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions