In this video, I’d like to explain how
the debugger works and how you can use it
to identify bugs, and execute expressions,
and interact with objects.
So I want to do once more
the exercises that we had completed and done together on the
counter, so I use Monticello,
I go into the cache package, and
I see that there is a Counter package.
It enables me to also explain
this feature here. To be sure
this is the right package, I can browse, it is to say
that I’m going to look at the classes defined in the package.
So here, I see that I have a package called
MyCounter, containing 2 classes, Counter and
CounterTest, and if I look at all the operations
of Counter, I do have the 4 methods we had defined
together and in the same way for the test.
So now, I know that this is this package
I want to load, I’m gonna do load.
So now, I’m gonna browse the Counter class.
For the Counter class, the tests are green, so we can begin.
I’d like to show you
how we can use the debugger to execute an
expression step-by-step, and go or not in the
expressions we want to see in more details.
To do this, I take the TestDecrement
as an example, I do DebugTest.
Debug test, here it is, once more
what does the debugger show me?
The debugger shows the execution stack.
As in Pharo everything is a message, you see that
we can go deep in the stack, at first we
executed the Run method, Undo, lots of things like this.
For the moment, the system does it so we don’t really care.
Here we see the code being executed on the stack
and the system status.
Here, look, I have a local variable C. For the moment
it has not been assigned, so there is nil.
And here I see that Self is in fact a class of
CounterTest, this is the method CounterTest>>
#testDecrement.
When I click on “over” here,
I get on the first expression to execute.
Note that, if I want to,
I can create immediately, I can execute this
expression because it is complete,
the Counter class is defined and I can
send it the message New.
Here I see that C is always like this, so
now I’m going to say I want “Over”.
Over: what does it mean?
It means I want to execute the expression without going inside it.
Here I am on the second expression which is an
assignment, and I will click on “Over” once more and
all of a sudden my variable C points on a Counter
that I can see her. Here for the moment the counter value is nil.
If I wanted to know how count:
is implemented, instead of using “Over” I would
use “Into”.
“Into” will make me get inside the method,
like this. Here I can see the method definition and
once more, I can interact with the arguments.
Here I have anInteger, if I write Print, I can see
see that I get 7, and anyway anInteger
is here and count, for now,
the instance variable, its value is nil.
It’s also displayed there.
I continue, I click on “Over”, because
I mean I want to jump over it.
I want to continue the expression execution.
So there.
Now let’s imagine I want to go inside decrement,
I will do the same thing, I will click on “Into”,
decrement, I have decrement’s code and,
you understood the principle, this way I can do
the expression step by step .
So now Proceed, what does it enable to do?
It enables to say : “from this point continue
as if nothing had happened. So that’s what I’m going to do
and my test will be green. So now I could also
execute independently this
bit of code, this means
I can put it in a Playground like this,
and here I have Debug it, I get the same thing.
In this case it is compiled a little bit
differently but I have exactly the same
features, with my Counter value which is 7,
and if I click on the counter, I can see that I have 7
here and I click on “Into” for example,
I can go in decrement, “Over”, “Over”,
and the same thing on “Over”.
So here it returns the cascade value, so it returns
the C Counter.