panic!

The panic! macro also sends its output to the ITM!

Change the main function to look like this:

  1. #[entry]
  2. fn main() -> ! {
  3. panic!("Hello, world!");
  4. }

Let’s try this program. But before that let’s update openocd.gdb to run that monitor stuff forus during GDB startup:

  1. target remote :3333
  2. set print asm-demangle on
  3. set print pretty on
  4. load
  5. +monitor tpiu config internal itm.txt uart off 8000000
  6. +monitor itm port 0 on
  7. break main
  8. continue

OK, now run it.

  1. $ cargo run
  2. (..)
  3. Breakpoint 1, main () at src/06-hello-world/src/main.rs:10
  4. 10 panic!("Hello, world!");
  5. (gdb) next

You’ll see some new output in the itmdump terminal.

  1. $ # itmdump terminal
  2. (..)
  3. panicked at 'Hello, world!', src/06-hello-world/src/main.rs:10:5

Another thing you can do is catch the panic before it does the logging byputting a breakpoint on the rust_begin_unwind symbol.

  1. (gdb) monitor reset halt
  2. (..)
  3. target halted due to debug-request, current mode: Thread
  4. xPSR: 0x01000000 pc: 0x080026ba msp: 0x10002000
  5. (gdb) break rust_begin_unwind
  6. Breakpoint 2 at 0x80011d2: file $REGISTRY/panic-itm-0.4.0/src/lib.rs, line 46.
  7. (gdb) continue
  8. Continuing.
  9. Breakpoint 2, rust_begin_unwind (info=0x10001fac) at $REGISTRY/panic-itm-0.4.0/src/lib.rs:46
  10. 46 interrupt::disable();

You’ll notice that nothing got printed on the itmdump console this time. Ifyou resume the program using continue then a new line will be printed.

In a later section we’ll look into other simpler communication protocols.