Test And Debug¶
Memory Marker Counter¶
Memory Marker Counter: Runtime I/O + Debugging Tutorial¶
Docs category: docs/public/examples/test-and-debug.md
This tutorial teaches the scan-cycle memory model and shows how to inspect it in both the Runtime Panel and debugger.
Learning Goal¶
Understand exactly when %M values are read and written in one cycle:
- cycle start:
%M-> bound ST variable - logic execution: program updates values
- cycle end: updated ST variable ->
%M
Project Files¶
src/Main.stsrc/Configuration.sttrust-lsp.toml.vscode/launch.json
Step 1: Open and Build¶
From repository root:
code examples/memory_marker_counter
trust-runtime build --project examples/memory_marker_counter --sources src
trust-runtime validate --project examples/memory_marker_counter
Step 2: Start Runtime + Panel¶
- In VS Code:
Ctrl+Shift+P->Structured Text: Open Runtime Panel - Start runtime (Local mode) or connect to running runtime.
- Open the panel sections:
I/O -> Inputsfor writing%MvaluesI/O -> Outputsfor reading%Qvalues- cycle/heartbeat area to confirm scans are progressing
Step 3: Core Experiment (Annotated)¶
Bindings (src/Configuration.st):
%MW0<->Counter%QW0<->CounterLatched
Procedure:
- Write
%MW0 = Word(41). - Wait one cycle.
Expected after first cycle:
%QW0 = Word(41)(latched cycle-start value)%MW0 = Word(42)(incremented writeback at cycle end)
Expected after more cycles:
%MW0increments by 1 per cycle.
Step 4: Debugger Integration¶
- Open
src/Main.st. - Set breakpoint on
Counter := Counter + 1;. - Press
F5using.vscode/launch.json. - In Variables panel, inspect
CounterandCounterLatched. - Step over and observe value transitions.
- Confirm inline values in editor match debugger state.
Step 5: Modify and Re-Test¶
Change:
Counter := Counter + 1;->Counter := Counter + 5;
Repeat Step 3 and confirm %MW0 jumps by 5 each cycle.
Automated Check¶
./scripts/test_memory_marker_sync.sh
Pitfalls and Fixes¶
- Writing
%Qand expecting it to behave like input memory: - fix: write
%MW0, observe%QW0as output evidence. - Runtime panel not connected:
- fix: start runtime or verify endpoint in
trust-lsp.toml. - Values not updating:
- fix: confirm cycle is running and writes are applied (not staged only).