This repository contains a gdb plugin for micropython on the rp2040, debugged under gdb.
To use this plugin you need a firmware.elf-file from the target firmware with debug symbols (the binary can be compiled in release mode though). Additionally, for feeding stdin, and capturing ethernet/bluetooth, you need debugging-hook.patch. This patch adds "trap" instructions to strategic positions, which allows breaking there without sacrificing one of the two precious hardware breakpoings.
The following gdb commands are implemented:
set debugging=3,feed_stdin 1+2: Send "1+2" to the REPL wait for a response and print the captured stdout it. Ifdebuggingis not set, only stdin is set, and the execution needs to be resumed manually withcontinue.poll_stdout, look for output buffered in stdout.pcap: start capturing all ethernet frames and write a pcap file to/tmp/picotrace.pcap. That file can be live inspected with wireshark:tail -n+0 -f /tmp/picotrace.pcap | wireshark -k -i -bpcap: start capturing all bluetooth hci frame and write a pcap file to/tmp/picoblue.pcap. That file can be live inspected with wireshark:tail -n+0 -f /tmp/picoblue.pcap | wireshark -k -i -qstr 42: locate qstring 42 and print itpystateprint all python objects for the current method'scode_state.pyobj 0xpyobjprint the micropython object0xpyobj.pydis 0xpyobjdisassemble the code of amp_fun_bc-object. You might need to make sure gdb findsmp-toolfrommicropython/toolsfor this command.
Also backtrace has been enriched with a frame filter to display python function calls and parameters instead of execute_bytecode.
Other features I thought about:
- Line info is also there and could be parsed, to enable source-line-stepping from bytecode-instruction-stepping.
- In order to step single bytecode instructions I would need to identify an instruction inside
execute_bytecodethat dispatches the next instruction, and that seems non-trivial. Especially as the source tries to avoid the existance of such an instruction.