Next: , Previous: , Up: GDB   [Contents]


4.2 A linked in exception handler

A GDB stub consists of two parts, support for the exception handler, and the exception handler itself. The exception handler needs to communicate to GDB on the host whenever there is a breakpoint exception. When GDB starts a program running on the target, it’s polling the serial port during execution looking for any debug packets. So when a breakpoint occurs, the exception handler needs to save state, and send a GDB remote protocol packet to GDB on the host. GDB takes any output that isn’t a debug command packet and displays it in the command window.

Support for the exception handler varies between processors, but the minimum supported functions are those needed by GDB. These are functions to support the reading and writing of registers, the reading and writing of memory, start execution at an address, single step, and last signal. Sometimes other functions for adjusting the baud rate, or resetting the hardware are implemented.

Once GDB gets the command packet from the breakpoint, it will read a few registers and memory locations an then wait for the user. When the user types run or continue a continue command is issued to the backend, and control returns from the breakpoint routine to the application.