You might check out the "Free Software Foundation's" code for gdb, available
from prep.ai.mit.edu and other archive sites.

You might like to look through various assembly language books since
writing debuggers is a nice exercise. One I can think of now is
"Programming the M68000" by King and Knight, chapter nine. The title
of the chapter is "A complete example".