paavohtl Claude Opus 4.6 (1M context) commited on
Commit
3db1f09
Β·
1 Parent(s): 5f22f7f

docs: update CLAUDE.md and debug-cli skill for new debug tools

Browse files

Document inspect/objects commands, symbolic address expressions,
ValueKind enum, FieldFormatter trait, #[field(kind)] attribute,
and field_format.rs in both CLAUDE.md and the debug-cli skill.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files changed (2) hide show
  1. .claude/skills/debug-cli/SKILL.md +98 -23
  2. CLAUDE.md +33 -2
.claude/skills/debug-cli/SKILL.md CHANGED
@@ -47,12 +47,57 @@ target/i686-pc-windows-msvc/release/openwa-debug read <addr> [len] [--format hex
47
  ```
48
 
49
  **Arguments:**
50
- - `<addr>` (required): Address expression (see syntax below). Accepts hex (`0x56E220`) or decimal.
51
  - `[len]` (optional): Bytes to read. Default: 256. Max: 1 MB.
52
  - `--format hex` (default): Hex dump with ASCII sidebar + pointer annotations.
53
  - `--format raw`: Binary output, suitable for piping to a file.
54
  - `--port N`: Override default port 19840.
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  ### suspend / resume / step / frame / break
57
 
58
  Frame-level debugging commands. Pause the game at exact frame boundaries for memory inspection.
@@ -73,7 +118,7 @@ openwa-debug break clear # Clear breakpoint
73
 
74
  ## Address Syntax
75
 
76
- All address forms can be used with the `read` command. **Always quote the address argument** to prevent shell interpretation.
77
 
78
  | Syntax | Meaning |
79
  |--------|---------|
@@ -84,6 +129,16 @@ All address forms can be used with the `read` command. **Always quote the addres
84
  | `0x669F8C[0x10]` | Bracket notation (same as +0x10) |
85
  | `"0x7A0884->0xA0->0x2C"` | Pointer chain (quote required!) |
86
  | `"0x7A0884->0xA0+0x10->0x0"` | Chain with compound offset in segment |
 
 
 
 
 
 
 
 
 
 
87
 
88
  ### Pointer Chains
89
 
@@ -114,23 +169,27 @@ The output shows each step of the chain walk before the hex dump, so you can ver
114
 
115
  ## Key Address Chains
116
 
117
- These chains are useful starting points for inspecting game state:
118
 
119
  ```bash
120
- # DDGame (the main game object):
121
- # g_GameSession(0x7A0884) -> DDGameWrapper at +0xA0 -> DDGame at +0x488
122
- openwa-debug read "0x7A0884->0xA0->0x488" 0x100
123
 
124
- # DDGame sub-field (e.g. weapon_table pointer at DDGame+0x510):
125
- openwa-debug read "0x7A0884->0xA0->0x488->0x510" 4
126
 
127
- # Weapon table contents (deref the pointer, read raw entries):
128
- # Get pointer first, then use abs: with the result
129
- openwa-debug read "0x7A0884->0xA0->0x488->0x510" 4
130
- openwa-debug read "abs:<ptr_from_above>" 0x80B0 --format raw > /tmp/weapon_table.bin
 
 
 
 
 
131
  ```
132
 
133
- **Common mistake:** `0x7A0884->0xA0->0x0` does NOT reach DDGame. It reads DDGameWrapper+0x0 (the vtable). DDGame is at DDGameWrapper+0x488.
134
 
135
  ## Output
136
 
@@ -150,24 +209,40 @@ openwa-debug read "abs:<ptr_from_above>" 0x80B0 --format raw > /tmp/weapon_table
150
 
151
  ## Common Patterns
152
 
153
- ### Inspect a struct via pointer chain
154
 
155
  ```bash
156
- # Follow g_GameSession -> DDGameWrapper -> DDGame, read 0x100 bytes
157
- openwa-debug read "0x7A0884->0xA0->0x488" 0x100
 
 
 
158
 
159
- # Read team arena state (DDGame+0x4628)
160
- openwa-debug read "0x7A0884->0xA0->0x488->0x4628" 0x200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  ```
162
 
163
  ### Dump a large region for offline analysis
164
 
165
  ```bash
166
- # Dump weapon table (71 x 0x1D0 = 0x80B0 bytes) to file
167
  openwa-debug read "abs:<weapon_table_ptr>" 0x80B0 --format raw > /tmp/weapon_table.bin
168
-
169
- # Analyze with Python script
170
- python tools/analyze_weapon_table.py /tmp/weapon_table.bin
171
  ```
172
 
173
  ### Read at an absolute heap address
@@ -186,7 +261,7 @@ openwa-debug read 0x669F8C 32
186
 
187
  ### Validate a struct field
188
 
189
- Read the struct base, check that the DWORD at the expected offset matches what you expect (vtable address, known constant, pointer kind).
190
 
191
  ## Limitations
192
 
 
47
  ```
48
 
49
  **Arguments:**
50
+ - `<addr>` (required): Address expression (see syntax below). Accepts hex (`0x56E220`), decimal, or symbolic names.
51
  - `[len]` (optional): Bytes to read. Default: 256. Max: 1 MB.
52
  - `--format hex` (default): Hex dump with ASCII sidebar + pointer annotations.
53
  - `--format raw`: Binary output, suitable for piping to a file.
54
  - `--port N`: Override default port 19840.
55
 
56
+ ### inspect
57
+
58
+ Typed struct inspection β€” reads all named fields from a FieldRegistry and formats them by ValueKind.
59
+
60
+ ```bash
61
+ openwa-debug inspect <class_name> <addr>
62
+ ```
63
+
64
+ **Examples:**
65
+ ```bash
66
+ openwa-debug inspect DDGame ddgame # All 84 DDGame fields
67
+ openwa-debug inspect CTaskWorm "abs:0x1DB439F0" # Worm at known address
68
+ openwa-debug inspect CGameTask "ddgame->task_land" # Follow pointer, show base class
69
+ openwa-debug inspect DDGameWrapper "gamesession->ddgame_wrapper" # Multi-step chain
70
+ ```
71
+
72
+ **Output format:**
73
+ ```
74
+ DDGame at ghidra:0x00XXXXXX (runtime:0xYYYYYYYY)
75
+ +0x0000 keyboard [ 4] 0x040ACA40 (DDKeyboard*)
76
+ +0x0084 pos_x [ 4] 388.4320 (0x01846E96)
77
+ +0x02F0 worm_name [17] "Ainsley"
78
+ +0x054C task_land [ 4] 0x1DB27938 (CTaskLand*)
79
+ ```
80
+
81
+ Fields are formatted by their `ValueKind`: pointers resolved to class names, Fixed as float + raw hex, CString as quoted strings, scalars as decimal.
82
+
83
+ ### objects
84
+
85
+ List all tracked live objects (registered via `register_live_object` in the DLL).
86
+
87
+ ```bash
88
+ openwa-debug objects
89
+ ```
90
+
91
+ **Output:**
92
+ ```
93
+ Tracked objects (3):
94
+ GameSession runtime:0x155FDD38 size:0x120 fields:27
95
+ DDGameWrapper runtime:0x15580048 size:0x6F00 fields:15
96
+ DDGame runtime:0x1C3F8E40 size:0x98D8 fields:84
97
+ ```
98
+
99
+ Object names work as symbolic addresses: `ddgame`, `gamesession`, `ddgamewrapper` (case-insensitive).
100
+
101
  ### suspend / resume / step / frame / break
102
 
103
  Frame-level debugging commands. Pause the game at exact frame boundaries for memory inspection.
 
118
 
119
  ## Address Syntax
120
 
121
+ All address forms can be used with `read`, `inspect`, and any command that takes an address. **Always quote chain addresses** to prevent shell interpretation.
122
 
123
  | Syntax | Meaning |
124
  |--------|---------|
 
129
  | `0x669F8C[0x10]` | Bracket notation (same as +0x10) |
130
  | `"0x7A0884->0xA0->0x2C"` | Pointer chain (quote required!) |
131
  | `"0x7A0884->0xA0+0x10->0x0"` | Chain with compound offset in segment |
132
+ | `ddgame` | Named alias (resolved via server, case-insensitive) |
133
+ | `ddgame+frame_counter` | Named alias + field offset (no deref) |
134
+ | `"ddgame->task_land"` | Field-name chain: offset to field, then deref |
135
+ | `"gamesession->ddgame_wrapper->display"` | Multi-step field chain |
136
+
137
+ ### Symbolic Names
138
+
139
+ Named live objects (`ddgame`, `gamesession`, `ddgamewrapper`) resolve to runtime addresses via the server. Field names in `+offset` or `->chain` segments resolve via FieldRegistry lookups, including CTask inheritance chains.
140
+
141
+ Field-name chain semantics differ from hex chains: `ddgame->task_land` means "add task_land's offset (0x54C) to DDGame base, then deref" (offset-then-deref). Hex chains like `0x7A0884->0xA0` mean "deref 0x7A0884, then add 0xA0" (deref-then-offset). This matches the natural user intent in each case.
142
 
143
  ### Pointer Chains
144
 
 
169
 
170
  ## Key Address Chains
171
 
172
+ With symbolic addresses, most chains are now human-readable:
173
 
174
  ```bash
175
+ # Typed DDGame inspection (all 84 named fields):
176
+ openwa-debug inspect DDGame ddgame
 
177
 
178
+ # Typed worm inspection at a known address:
179
+ openwa-debug inspect CTaskWorm "abs:0x1DB439F0"
180
 
181
+ # Follow a pointer field and inspect the target:
182
+ openwa-debug inspect CGameTask "ddgame->task_land"
183
+
184
+ # Read raw memory using symbolic names:
185
+ openwa-debug read ddgame 0x100
186
+ openwa-debug read "ddgame+frame_counter" 4
187
+
188
+ # Old hex chains still work:
189
+ openwa-debug read "0x7A0884->0xA0->0x488" 0x100
190
  ```
191
 
192
+ **Common mistake:** `0x7A0884->0xA0->0x0` does NOT reach DDGame. It reads DDGameWrapper+0x0 (the vtable). DDGame is at DDGameWrapper+0x488. With symbolic names, just use `ddgame`.
193
 
194
  ## Output
195
 
 
209
 
210
  ## Common Patterns
211
 
212
+ ### Typed struct inspection (preferred)
213
 
214
  ```bash
215
+ # Full DDGame with all named fields, typed formatting
216
+ openwa-debug inspect DDGame ddgame
217
+
218
+ # Worm at a known address β€” shows name, team, position, inputs
219
+ openwa-debug inspect CTaskWorm "abs:0x1DFB4B10"
220
 
221
+ # Follow pointer and inspect base class for position/speed
222
+ openwa-debug inspect CGameTask "ddgame->task_land"
223
+
224
+ # DDGameWrapper from GameSession
225
+ openwa-debug inspect DDGameWrapper "gamesession->ddgame_wrapper"
226
+ ```
227
+
228
+ ### Raw memory reads
229
+
230
+ ```bash
231
+ # Read specific field by name
232
+ openwa-debug read "ddgame+frame_counter" 4
233
+
234
+ # Read team arena state
235
+ openwa-debug read "ddgame+team_arena" 0x200
236
+
237
+ # Old-style hex chain still works
238
+ openwa-debug read "0x7A0884->0xA0->0x488" 0x100
239
  ```
240
 
241
  ### Dump a large region for offline analysis
242
 
243
  ```bash
244
+ # Dump weapon table to file
245
  openwa-debug read "abs:<weapon_table_ptr>" 0x80B0 --format raw > /tmp/weapon_table.bin
 
 
 
246
  ```
247
 
248
  ### Read at an absolute heap address
 
261
 
262
  ### Validate a struct field
263
 
264
+ Use `inspect` to see all named fields with formatted values, or `read` with a field name for raw bytes.
265
 
266
  ## Limitations
267
 
CLAUDE.md CHANGED
@@ -98,12 +98,26 @@ OPENWA_BREAK_FRAME=1350 OPENWA_DEBUG_SERVER=1 \
98
 
99
  Key commands:
100
  - `openwa-debug read "0x7A0884->0xA0->0x488" 0x100` β€” read memory via pointer chains
 
 
 
101
  - `openwa-debug suspend` / `resume` / `step N` β€” frame-level control
102
  - `openwa-debug snapshot` β€” canonicalized game state dump (for diffing)
103
  - `openwa-debug break 1350` β€” set frame breakpoint
104
 
105
  Address syntax: Ghidra VAs (auto-rebased), `abs:` prefix for absolute, `+offset` / `[offset]`, `->` for pointer chains. **Always quote chain addresses** (`"0x7A0884->0xA0->0x488"`).
106
 
 
 
 
 
 
 
 
 
 
 
 
107
  Key env vars:
108
  - `OPENWA_DEBUG_SERVER=1` β€” enable TCP debug server (port 19840)
109
  - `OPENWA_BREAK_FRAME=N` β€” auto-pause at frame N
@@ -166,7 +180,7 @@ See `docs/re-notes/desync-investigation.md` for a detailed case study.
166
 
167
  ## Hardware Watchpoint Debugger
168
 
169
- `crates/openwa-wormkit/src/debug_watchpoint.rs` β€” self-contained x86 debug register instrumentation. Sets DR0–DR3 write watchpoints on DDGame offsets via an INT3β†’VEH trick (no external debugger needed). Logs the exact Ghidra VA of every write.
170
 
171
  **Usage:** Call `prepare()` + `on_ddgame_alloc(ptr)` around the constructor, `teardown()` after. For the original WA constructor, use `prepare_with_malloc_hook()` which intercepts `wa_malloc(0x98D8)` to arm watchpoints from inside the constructor. Configure offsets in `WATCH_OFFSETS` (max 4 per run, hardware limit).
172
 
@@ -175,7 +189,8 @@ Currently dormant β€” no hooks wired up. Activate by adding calls in `game_sessi
175
  ## Key Files
176
 
177
  - `crates/openwa-core/src/address.rs` β€” Known WA.exe addresses (segment boundaries + re-exports from home modules)
178
- - `crates/openwa-core/src/registry.rs` β€” Structured address registry, field registries, live object tracker, query API
 
179
  - `crates/openwa-core/src/macros.rs` β€” `define_addresses!`, `vcall!`, and `vtable_replace!` macros
180
  - `crates/openwa-core/src/mem.rs` β€” Pointer classification and `identify_pointer()` for debug tools
181
  - `crates/openwa-core/src/wa_call.rs` β€” Helpers for calling WA functions (thiscall, stdcall wrappers)
@@ -224,14 +239,30 @@ crate::define_addresses! {
224
 
225
  Auto-generates a field map for `#[repr(C)]` structs using `offset_of!()`. Fields prefixed `_unknown`/`_pad` are skipped. Applied to all key structs (DDGame, CTask, CTaskWorm, etc.). Enables runtime offset β†’ field name lookups.
226
 
 
 
 
 
 
 
227
  ```rust
228
  #[derive(FieldRegistry)]
229
  #[repr(C)]
230
  pub struct CTask { ... }
231
  // Generates: CTask::field_registry() -> &'static StructFields
232
  // Also registers in global inventory for struct_fields_for("CTask")
 
 
 
 
233
  ```
234
 
 
 
 
 
 
 
235
  ### Query API (`registry::*`)
236
 
237
  - `lookup_va(ghidra_va)` β€” find address entry by VA (exact or nearest-below)
 
98
 
99
  Key commands:
100
  - `openwa-debug read "0x7A0884->0xA0->0x488" 0x100` β€” read memory via pointer chains
101
+ - `openwa-debug inspect DDGame ddgame` β€” typed struct inspection with named fields
102
+ - `openwa-debug inspect CTaskWorm "ddgame->task_land"` β€” follow field-name pointer chains
103
+ - `openwa-debug objects` β€” list tracked live objects (DDGame, DDGameWrapper, GameSession)
104
  - `openwa-debug suspend` / `resume` / `step N` β€” frame-level control
105
  - `openwa-debug snapshot` β€” canonicalized game state dump (for diffing)
106
  - `openwa-debug break 1350` β€” set frame breakpoint
107
 
108
  Address syntax: Ghidra VAs (auto-rebased), `abs:` prefix for absolute, `+offset` / `[offset]`, `->` for pointer chains. **Always quote chain addresses** (`"0x7A0884->0xA0->0x488"`).
109
 
110
+ ### Symbolic addresses
111
+
112
+ Named aliases and field names can be used anywhere an address is accepted:
113
+ - `ddgame` β€” resolves to DDGame's runtime address (any tracked live object name works, case-insensitive)
114
+ - `ddgame+frame_counter` β€” DDGame base + field offset (no deref)
115
+ - `ddgame->task_land` β€” follow the task_land pointer (offset + deref)
116
+ - `gamesession->ddgame_wrapper->display` β€” multi-step field chains
117
+ - Mixed: `ddgame->0x54C` still works (hex offsets alongside names)
118
+
119
+ Field names are resolved via the server's FieldRegistry, including CTask inheritance chains.
120
+
121
  Key env vars:
122
  - `OPENWA_DEBUG_SERVER=1` β€” enable TCP debug server (port 19840)
123
  - `OPENWA_BREAK_FRAME=N` β€” auto-pause at frame N
 
180
 
181
  ## Hardware Watchpoint Debugger
182
 
183
+ `crates/openwa-wormkit/src/debug_watchpoint.rs` β€” self-contained x86 debug register instrumentation. Sets DR0–DR3 write watchpoints on DDGame offsets via an INT3β†’VEH trick (no external debugger needed). Logs symbolicated stack traces via `registry::format_va()` (e.g., `CONSTRUCT_DD_GAME+0x220` instead of raw hex).
184
 
185
  **Usage:** Call `prepare()` + `on_ddgame_alloc(ptr)` around the constructor, `teardown()` after. For the original WA constructor, use `prepare_with_malloc_hook()` which intercepts `wa_malloc(0x98D8)` to arm watchpoints from inside the constructor. Configure offsets in `WATCH_OFFSETS` (max 4 per run, hardware limit).
186
 
 
189
  ## Key Files
190
 
191
  - `crates/openwa-core/src/address.rs` β€” Known WA.exe addresses (segment boundaries + re-exports from home modules)
192
+ - `crates/openwa-core/src/registry.rs` β€” Structured address registry, field registries (`ValueKind`), live object tracker, query API
193
+ - `crates/openwa-core/src/field_format.rs` β€” `FieldFormatter` trait, `format_field()`, default formatters for all `ValueKind` variants
194
  - `crates/openwa-core/src/macros.rs` β€” `define_addresses!`, `vcall!`, and `vtable_replace!` macros
195
  - `crates/openwa-core/src/mem.rs` β€” Pointer classification and `identify_pointer()` for debug tools
196
  - `crates/openwa-core/src/wa_call.rs` β€” Helpers for calling WA functions (thiscall, stdcall wrappers)
 
239
 
240
  Auto-generates a field map for `#[repr(C)]` structs using `offset_of!()`. Fields prefixed `_unknown`/`_pad` are skipped. Applied to all key structs (DDGame, CTask, CTaskWorm, etc.). Enables runtime offset β†’ field name lookups.
241
 
242
+ Each field gets a `ValueKind` for typed formatting, auto-inferred from the Rust type:
243
+ - `u8/u16/u32/i8/i16/i32` β†’ scalar variants, `bool` β†’ `Bool`, `Fixed` β†’ `Fixed`
244
+ - `*mut T` / `*const T` β†’ `Pointer`, `ClassType` β†’ `Enum`
245
+ - Arrays and unknown types β†’ `Raw`
246
+ - Override with `#[field(kind = "CString")]` for null-terminated string fields, etc.
247
+
248
  ```rust
249
  #[derive(FieldRegistry)]
250
  #[repr(C)]
251
  pub struct CTask { ... }
252
  // Generates: CTask::field_registry() -> &'static StructFields
253
  // Also registers in global inventory for struct_fields_for("CTask")
254
+
255
+ // String fields use #[field(kind = "...")] override:
256
+ #[field(kind = "CString")]
257
+ pub worm_name: [u8; 0x11], // Displays as "Ainsley" instead of raw hex
258
  ```
259
 
260
+ ### Field formatting (`field_format.rs`)
261
+
262
+ `format_field(&mut dyn fmt::Write, data, field, ctx)` writes human-readable values based on `ValueKind`: scalars as decimal, Fixed as float (e.g., `388.43`), pointers resolved via registry (e.g., `DDDisplay*`), CString as quoted strings. Zero allocations β€” writes to any `fmt::Write` target.
263
+
264
+ Custom formatters can be registered via `inventory::submit!(Box::new(MyFormatter) as Box<dyn FieldFormatter>)` from any crate. The `FieldFormatter` trait has `handles() -> &[ValueKind]` and `format_field(&mut dyn Write, ...)`.
265
+
266
  ### Query API (`registry::*`)
267
 
268
  - `lookup_va(ghidra_va)` β€” find address entry by VA (exact or nearest-below)