33.1. Baremetal GDB step debug

GDB step debug works on baremetal exactly as it does on the Linux kernel, which is described at: Section 3, “GDB step debug”.

Except that is is even cooler here since we can easily control and understand every single instruction that is being run!

For example, on the first shell:

./run --arch arm --baremetal userland/c/hello.c --gdb-wait

then on the second shell:

./run-gdb --arch arm --baremetal userland/c/hello.c -- main

Or if you are a tmux pro, do everything in one go with:

./run --arch arm --baremetal userland/c/hello.c --gdb

Alternatively, to start from the very first executed instruction of our tiny Baremetal bootloaders:

./run \
  --arch arm \
  --baremetal userland/c/hello.c \
  --gdb-wait \
  --tmux-args=--no-continue \
;

analogously to what is done for Freestanding programs.

Now you can just stepi to when jumping into main to go to the C code in userland/c/hello.c.

This is specially interesting for the executables that don’t use the bootloader from under baremetal/arch/<arch>/no_bootloader/*.S, e.g.:

./run \
  --arch arm \
  --baremetal baremetal/arch/arm/no_bootloader/semihost_exit.S \
  --gdb-wait \
  --tmux-args=--no-continue \
;

The cool thing about those examples is that you start at the very first instruction of your program, which gives more control.

Examples without bootloader are somewhat analogous to user mode Freestanding programs.