In summary, when your program is ready to debug, you must follow these steps.
getDebugChar, putDebugChar, flush_i_cache, memset, exceptionHandler.
Insert these lines in your program’s startup code, before the main procedure is called:
On some machines, when a breakpoint trap is raised, the hardware
automatically makes the PC point to the instruction after the
breakpoint. If your machine doesn’t do that, you may need to adjust
handle_exception to arrange for it to return to the instruction
after the breakpoint on this first invocation, so that your program
doesn’t keep hitting the initial breakpoint instead of making
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.