Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Registers with gdb

You can start gdb with:

probe-rs gdb --chip RP235x --gdb gdb-multiarch ./target/thumbv8m.main-none-eabihf/debug/pico-simple -- -q -ex "set mem inaccessible-by-default off" -ex "break src/main.rs:21

And replace 21 above with any line you want the debugger to break at. Once you start the debugger, it halts the core execution.

Note: the set mem inaccessible-by-default off is important to be able to access those special registers.

Here’s a few interesting commands for gdb (see x command reference):

  • x/bx 0x40028004: print the byte at this address in hexadecimal format.
  • x/bt 0x40028004: print the byte at this address in binary format.
  • x/wx 0x40028004: print the word (4 bytes) at this address in hexadecimal format.
  • x/20wx 0x40028004: print the 20 first words (4 bytes each) at starting this address in hexadecimal format.
  • x/10i 0x1002013D: print the 10 first instructions starting at this address.
  • set *(0x2000000c as *mut u8) = 0x04: set the byte address to be 0x04.
  • set *(0x2000000c as *mut u32) = 0xff030104: set the word address to be 0xff030104.
  • info registers: print the value of all processor registers (not be confused with special function registers).
  • p $pc: print the value of register pc.
  • info local: print value of all local variables.
  • p led: print the value of the variable named led.

Restart before halting

One caveat in all this, when the debug command is run, it will halt execution of the program running in the RPi Pico 2 for you, but it might have run past the your desired break point already, so you can pass the flag --reset-halt to the command above the restart before halting… except that it doesn’t work… or at least I haven’t found a way to do that yet (it might work with some other tool).

Ideally, there should be an easy way to do that, but in the absence of something better, you can just put asm::wfi(); twice in the very beginning of your main function and once the debugger starts, send a continue, and it will work.