feat(runtime): implement debugger STRING / WSTRING read/write/force/unforce#162
Merged
Conversation
…nforce
The four `*_string_stub` placeholders in debug_dispatch.hpp returned
zero for read and no-op'd for write/force/unforce. Net effect: every
STRING / WSTRING pin in a project showed as "-" in the editor's debug
watch panel because `handle_read()` saw a `type_ops[].size == 0` entry
and short-circuited with zero bytes, and `handle_set` / `handle_write`
rejected any payload with STATUS_DATA_TOO_LARGE.
Implement the real ops against `IECStringVar<254>` / `IECWStringVar<254>`,
matching the `len8-utf8` / `len8-utf16le` wire format that the editor's
decoder (`src/frontend/utils/variable-sizes.ts:decodeWireValue`) already
expects:
STRING wire shape: [ uint8 length ][ 126 bytes UTF-8 payload ] (127 B)
WSTRING wire shape: [ uint8 length ][ 126 char16_t LE code units ] (253 B)
Force-aware:
- read uses `length()` / `c_str()` on the wrapper, which the
earlier proxy additions route through `forced_value_` when
forcing is active.
- write uses `IECStringVar::set` which itself is a no-op when
forced (correct OPC-UA / debug-soft-write semantics).
- force pins the value via `IECStringVar::force`; unforce clears
via `IECStringVar::unforce`.
WSTRING serialises char16_t as explicit little-endian byte pairs so
the wire format stays host-endianness-independent.
The trailing window past `length` is zero-filled on read so stale bus
contents from a previous read can't leak through the fixed-width
window into the editor's display.
Verified end-to-end with a direct C++ smoke test:
STRING read 'hello' → len=5 bytes='hello' ✓
WSTRING read 'hi' → len=2 bytes=68 00 69 00 (UTF-16LE 'h','i') ✓
STRING write 'world' → IECStringVar.length()=5, c_str()='world' ✓
STRING force 'forced'→ is_forced=1, c_str()='forced' ✓
STRING unforce → is_forced=0, c_str()='world' (back) ✓
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Jun 2, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the four
*_string_stubplaceholders indebug_dispatch.hppwith real implementations againstIECStringVar<254>/IECWStringVar<254>. Net effect for the editor: STRING / WSTRING variables in the debug watch panel will show their actual values instead of-.Root cause
The stubs were a deliberate Phase-4a placeholder. The dispatcher's
handle_readshort-circuits with zero bytes whentype_ops[].size == 0, andhandle_set/handle_writereject any payload withSTATUS_DATA_TOO_LARGE. Both STRING and WSTRING rows hadsize = 0.Wire format (already expected by the editor decoder)
Matches the
len8-utf8/len8-utf16learms inopenplc-web/src/frontend/utils/variable-sizes.ts::decodeWireValue:[ uint8 length ][ 126 bytes UTF-8 ][ uint8 length ][ 126 char16_t LE code units ]WSTRING serialises char16_t as explicit little-endian byte pairs so the wire format stays host-endianness-independent.
Force semantics
.length()/.c_str()proxies (added in v0.5.1) which route throughforced_value_when forcing is active — so a debugger watch shows the forced value, not the underlying program-side value.IECStringVar::set, which is itself a no-op when the variable is forced. Matches OPC-UA / debug-soft-write semantics: soft writes don't override a force.IECStringVar::force; unforce clears viaIECStringVar::unforce.Why widths matter
Setting
size = 127/253meanshandle_readreturns the full window every poll. The editor's decoder treats the leading length byte as authoritative and only rendersmin(length, 126)characters; the runtime zero-fills the trailing window so stale bus contents from a previous read can't leak into the displayed value.Verified end-to-end
Direct C++ smoke test (compiled with clang++ against the patched header):
Test plan
MANUAL_OVERRIDE0.test_string.Downstream
This unblocks the debugger STRING display in openplc-editor / openplc-web. After this lands and v0.5.3 is tagged, the version bumps in both repos'
binary-versions.jsonpropagate the fix.🤖 Generated with Claude Code