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

Change the main function to look like this:

fn main() -> ! {
    panic!("Hello, world!");

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

 target remote :3333
 set print asm-demangle on
 set print pretty on
+monitor tpiu config internal itm.txt uart off 8000000
+monitor itm port 0 on
 break main

OK, now run it.

$ cargo run
Breakpoint 1, main () at src/06-hello-world/src/
10          panic!("Hello, world!");

(gdb) next

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

$ # itmdump terminal
panicked at 'Hello, world!', src/06-hello-world/src/

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

(gdb) monitor reset halt
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080026ba msp: 0x10002000

(gdb) break rust_begin_unwind
Breakpoint 2 at 0x80011d2: file $REGISTRY/panic-itm-0.4.0/src/, line 46.

(gdb) continue

Breakpoint 2, rust_begin_unwind (info=0x10001fac) at $REGISTRY/panic-itm-0.4.0/src/
46          interrupt::disable();

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

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