@@ -115,6 +115,103 @@ identical numbers. When they do, a difference between real arms is attributable
115115to the firmware. Every run records the checksum of each binary it attached, so
116116"which build produced this number" is answerable from the results.
117117
118+ ## Attaching a debugger
119+
120+ ` node.debug ` makes a running node debuggable and says how to attach. The
121+ firmware is the real firmware, so the debugger is the ordinary one: gdb, lldb,
122+ or VS Code with the C/C++ extension. The node must be running firmware; a node
123+ that is not is refused with `is not running firmware, so there is nothing to
124+ debug`.
125+
126+ ::: ways
127+ :: gui
128+ Open the node's row menu in the Nodes panel and choose ** Debug this node** . The
129+ entry is there only while the node is running. The status line shows the
130+ command to attach with.
131+ :: socket
132+ ``` json
133+ {"id" :1 ,"method" :" node.debug" ,"params" :{"node" :" West Lomond" }}
134+ ```
135+ :: python
136+ ``` python
137+ print (wb.call(" node.debug" , {" node" : " West Lomond" })[" attach" ])
138+ ```
139+ :: go
140+ ``` go
141+ ans , err := wb.Call (ctx, " node.debug" , map [string ]any{" node" : " West Lomond" })
142+ ```
143+ :::
144+
145+ The answer carries ` attach ` , a debugger command line, and ` vscode ` , a
146+ configuration to paste into ` launch.json ` . From the first call ` sim.state `
147+ reports the run as not reproducible, because a debugger stopping a node moves
148+ its clock. ` {"node": ..., "off": true} ` stops debugging.
149+
150+ ### A native node
151+
152+ A native node is an ordinary process on this machine, and the debugger attaches
153+ to it by its process ID:
154+
155+ gdb -p 2104750 ~/.cache/meshbench/firmware/native/.../meshcore-simple_repeater-linux-amd64
156+
157+ The answer has ` pid ` , ` binary ` and ` symbols ` : ` debug ` when the binary carries
158+ DWARF, ` symbols ` when it has a symbol table only, ` stripped ` when it has
159+ neither, and ` unknown ` when it cannot be read as ELF. For source-level
160+ debugging, build the firmware from a checkout with ` meshbench dev ` .
161+
162+ ** A breakpoint holds the node rather than failing it.** A native node normally
163+ has to answer every tick within the deadline or it is marked down. While it is
164+ being debugged, a node that does not answer within two seconds is held instead:
165+ the rest of the mesh carries on without it, and when the debugger lets it go it
166+ catches up to the run's clock and rejoins. Its clock jumps by however long it
167+ was stopped, as a real board stopped by a JTAG probe does. ` off ` gives it its
168+ deadline back.
169+
170+ - ** Nothing listens on the network.** No port is opened for a native node;
171+ attaching is the operating system's own process debugging, from this machine
172+ only. On Linux that needs ptrace permission: ` kernel.yama.ptrace_scope ` set
173+ to 0, or the debugger run as root.
174+ - ** Boot cannot be caught.** A native node runs ` setup() ` as soon as it starts,
175+ so by the time anything can attach it has booted. ` wait ` is refused for a
176+ native node for that reason.
177+
178+ ### An emulated board
179+
180+ An emulated board's firmware runs inside QEMU or Renode, and the way in is the
181+ emulator's GDB stub. ` node.debug ` restarts the board with one.
182+
183+ ``` json
184+ {"id" :2 ,"method" :" node.debug" ,"params" :{"node" :" Deck" ,"wait" :true }}
185+ ```
186+
187+ - ` gdb_port ` is where the stub listens. Pass ` port ` to choose it, a whole
188+ number from 1 to 65535; without it a free port is picked.
189+ - ` wait ` holds the CPU at reset until a debugger continues, so boot can be
190+ stepped through.
191+ - ` debugger ` is the gdb that speaks the board's architecture:
192+ ` xtensa-esp32-elf-gdb ` or ` xtensa-esp32s3-elf-gdb ` for an ESP32 board under
193+ QEMU, ` arm-none-eabi-gdb ` (or ` gdb-multiarch ` ) for an nRF52 board under
194+ Renode.
195+
196+ The image a board runs is a flashable ` .bin ` or ` .uf2 ` with no symbols. Point
197+ the debugger at the ` firmware.elf ` the same build produced, for a PlatformIO
198+ build ` .pio/build/<env>/firmware.elf ` :
199+
200+ arm-none-eabi-gdb -ex 'target remote 127.0.0.1:3333' .pio/build/RAK_4631_repeater/firmware.elf
201+
202+ ` off ` restarts the board without the stub.
203+
204+ ** Where the stub listens differs by emulator, and the difference matters.** A
205+ GDB stub is the whole machine: anything connected to it can read and write the
206+ board's memory and registers, and stop or change the firmware.
207+
208+ - ** QEMU** binds its stub to ` 127.0.0.1 ` , so only this machine can reach it.
209+ - ** Renode's stub listens on every network interface** , not only this
210+ machine's own. While debugging is on, anyone who can reach the port over the
211+ network has full read and write access to the emulated board. Debug a Renode
212+ board only on a network you trust, or with the port blocked by a firewall,
213+ and turn it ` off ` when finished.
214+
118215## Versions are per role
119216
120217MeshCore tags one role at a time. ` repeater-v1.17.0 ` and ` companion-v1.17.0 ` are
0 commit comments