gdb.info: Debug Session

Go backward to Bootstrapping
Go up to remote stub
Go to the top op gdb

Putting it all together

In summary, when your program is ready to debug, you must follow these
steps.
  1. Make sure you have defined the supporting low-level routines
     (*note What you must do for the stub: Bootstrapping.):
          `getDebugChar', `putDebugChar',
          `flush_i_cache', `memset', `exceptionHandler'.
  2. Insert these lines near the top of your program:
          set_debug_traps();
          breakpoint();
  3. For the 680x0 stub only, you need to provide a variable called
     `exceptionHook'.  Normally you just use:
          void (*exceptionHook)() = 0;
     but if before calling `set_debug_traps', you set it to point to a
     function in your program, that function is called when `GDB'
     continues after stopping on a trap (for example, bus error).  The
     function indicated by `exceptionHook' is called with one
     parameter: an `int' which is the exception number.
  4. Compile and link together: your program, the GDB debugging stub for
     your target architecture, and the supporting subroutines.
  5. Make sure you have a serial connection between your target machine
     and the GDB host, and identify the serial port on the host.
  6. Download your program to your target machine (or get it there by
     whatever means the manufacturer provides), and start it.
  7. Start GDB on the host, and connect to the target (*note Connecting
     to a remote target: Connecting.).