# 4 Execution Control

This chapter describes the various possibilities to execute only well defined parts of your program. First, the positions must be defined where the execution of a thread can be stopped.

## 4.1 Step Points

These positions are called step points. What follows is a list of all currently defined step points. Note that all such points are dual: Both entry and exit point of the corresponding syntactic construct actually constitute a step point. Emacs always highlights the whole line where the thread is currently stopped, together with a second mark which shows the column within this line where the syntactic construct starts or ends.

Definition

  A thread can be stopped just before and just after the definition of a procedure, function or class. Emacs highlights the `proc`, `fun`, `class` or `end` keyword, respectively. The stack view displays a stack frame containing the single word `definition`.

Application

  You can stop a thread right before and after a procedure, function or method application. Emacs highlights the opening and closing brace, respectively. The stack view displays a stack frame which contains the procedure, function or method name (if there exists any, $ otherwise), together which the argument list. All arguments can be inspected by clicking on them with the left mouse button.

Conditional

  You can stop a thread before entering and after leaving a conditional. This makes it possible to investigate the arbiter. Emacs highlights the `case` and `end` keyword, respectively. The stack view displays a stack frame containing the word `conditional`, followed by the clickable value of the arbiter.

Thread Creation

  A thread can be stopped whenever a new thread is created explicitely. Emacs highlights the `thread` and `end` keyword, respectively. The stack view displays a stack frame containing the single word `thread`.

Installation of Exception Handlers

  A thread can be stopped when an exception handler gets installed. Emacs highlights the `try` and `end` keyword, respectively. The stack view displays a stack frame containing `exception handler`. Moreover, when an exception is catched, the thread can stop on the corresponding `catch` clause, and in the stack window you see the single word `catch`, followed by the clickable pattern that matched.

Entering Locks

  Finally, you can stop a thread when a locked code block is entered or leaved. Emacs highlights the `lock` and `end` keyword, respectively. The stack view displays a stack frame containing the single word `lock`, followed by the clickable value of the lock.

## 4.2 Action Step Into

The simplest way how to control the execution of a thread is to single step from step point to step point. This is exactly what step into () is doing. You get a very detailed view of how your program is executing. Often, it will be too detailed; this is where step over and unleash enter the scene.

## 4.3 Action Step Over

Whenever execution has stopped on a step point, you can decide if you want to enter the corresponding inner block (i.e. the procedure body, the case clause, etc). If yes, you do a step into (see above). If not, you do a step over (). This continues execution until the corresponding block has been left again. Typically, Emacs will show you standing on an `end` keyword or a closing brace then.

## 4.4 Action Unleash

Actually, step over is a special case of a more generic action, which is called unleash (). It continues the execution of the thread until the currently marked stack frame is just to be removed from the stack, or until the thread has finished executing the whole stack if no stack frame is marked. Remember you can mark a stack frame by clicking on it or by walking to it using the up and down cursor keys.

## 4.5 Example

To illustrate the functionality, consider the following program which calculates the faculty:

> `local
> fun {Fac N}
> if N < 2 then 1 else
> N * {Fac N-1}
> end
> end
> in
> {Show {Fac 5}}
> end`

Suppose you already pressed the button some times, so that there was build a nice stack already, and that you have marked stack frame 5 by clicking on it. What you will see is something like this:

Picture 4.1: Before the action unleash 5

You decide to directly compute the value of `{Fac 3}`, so what Ozcar needs to do is to continue the thread's execution until stack frame 5 is just to be removed from the stack. Unleash 5, activated by clicking on the button, does exactly this:

Picture 4.2: After the action unleash 5

## 4.6 Breakpoints

Single stepping is nice, but often somewhat inconvenient, because you need a lot of steps until the interesting section of your program is reached. Breakpoints help you here. Ozcar supports two flavours of them: static and dynamic ones.

### 4.6.1 Static Breakpoints

Let's assume you need to debug the base case of the recursion. This can easily be achieved by inserting a special breakpoint procedure, like this:

> `local
> fun {Fac N}
> if N < 2 then
> {Ozcar.breakpoint} 1
> else
> N * {Fac N-1}
> end
> end
> in
> {Show {Fac 5}}
> end`

After feeding the code and pressing the button two times, you are directly at the desired position. Static breakpoints are useful if you want the breakpoint to survive multiple invokations of the mozart system. They are inserted before you feed your code.

On the other hand, you might decide to insert a breakpoint after you feeded the code. Then you need dynamic breakpoints.

### 4.6.2 Dynamic Breakpoints

This flavour of breakpoints can be set directly from Emacs: You position the cursor on the line and column where you want to change breakpoint information and press (C-x space) to set or (C-u C-x space) to delete a breakpoint.

Unfortunately, there is no information yet about all currently defined dynamic breakpoints. You just have to keep them in mind. This should be changed in the future.