# 13.5 Observing execution

> Execution can be watched step by step: the engine emits a **trace** of events, and every event carries what changed in memory.

Web page: https://pseudolearn.app/en/spec/motor/observacion

> **In one sentence**
>
> Execution can be watched step by step: the engine emits a **trace** of events, and every event carries what changed in memory.

## 13.5.1 How it works

A **step** is the interval between two consecutive trace events: entering a statement, taking a decision, writing, calling, returning. Advancing one step delivers exactly the next event; there is nothing smaller.

The debugger's moves are built on events:

| Move | Until |
| --- | --- |
| next statement | the next statement of the same frame or an outer one |
| step into | the next statement, even inside a call |
| step out | the return that closes the current frame |

**Figure 13.5-1: Trace steps**

A line with five events: enter, decision, write, exit and end. An arc between two events marks a step. Below, a state change: n = 3.

Every trace event is a step. The memory state at any event is rebuilt by adding up the changes from the start.

### Program: A program to watch

```pseudolearn
Algorithm Observar
  Define n As Integer <- 3;
  If n > 2 Then
    Write "grande";
  EndIf
EndAlgorithm
```

**Output**

```text
grande
```

*The program finishes normally.*

**Trace**

| Line | Event |
| --- | --- |
| 2 | enters statement |
| 3 | enters statement |
| 3 | decision · true branch |
| 4 | enters statement |
| 4 | writes · grande |

Every event can carry the **state change**: written variables, created objects, frames pushed or popped. Adding up the changes from the start gives the full state at any event, and asking about a past event again always gives the same answer. Events are delivered in batches of whatever size the host prefers, without losses or duplicates.

**In short**
- The trace is the list of events; a step is an event.
- Next, step into and step out are defined on events.
- State changes rebuild memory at any point.

**See also**
- [13.1 The engine's layers](https://pseudolearn.app/en/spec/motor/capas.md)
- [13.6 Engine limits](https://pseudolearn.app/en/spec/motor/limites.md)
