10.3 Halt!

A breakpoint is a place in code where one wishes to pause code processing and look around. One does not always want to single step to find a problem, especially one that occurs only once in a while. A breakpoint set where the problem occurs is quite handy.

In Smalltalk, one uses the halt method to set a breakpoint. The message #halt is sent to an object which is the debugger’s initial focus.

Please change the Workspace code to add a #halt as follows.

| fileNames |
fileNames := OrderedCollection new.
(DirectoryEntry smalltalkImageDirectory) 
    childrenDo: [ :f | fileNames add: f name. fileNames halt ].
fileNames asArray.

Example 10.4: Halt: Set a Breakpoint

 note The object which receives the #halt message becomes the focus object of the debugger.

Let’s again Ctrl-a (select All) and Ctrl-p (select Print-it).

ch10-06-Halt

Figure 10.6: Halt

Press Over twice to step over the breakpoint.

ch10-07-Over

Figure 10.7: Step Over Breakpoint

Well, this looks familiar. I know what to do here.

Note that the halt is inside a loop. While in the loop, each time you press Proceed you will hit the breakpoint in the next iteration of the loop.

In many programming envionments, to make a change you need to kill a process, recompile code, then start a new process.

Smalltalk is a live environment. You can break, then change or write code (the Create button at mid-right), restart the stack frame, and continue processing – all without unwinding the context stack!

As an analogy, in many programming languages, it is like you stub your toe and visit a physician. The doctor says “Yes. you stubbed your toe.” then takes out a gun, shoots you, and sends your mother a note “have another child.” Smalltalk is much more friendly!

Note that with great power comes great responsibility28. In an open system, you can place a breakpoint anywhere, including places which can break the user interface! For example, it could be a bad thing to put a breakpoint in the code for the Debugger!


Footnotes

(28)

https://quoteinvestigator.com/2015/07/23/great-power/