From: | Duane McDonnell |
Date: | 20 Aug 2001 at 14:28:24 |
Subject: | [amiga-c] Re: 680x0 Status Register |
--- In amiga-c@y..., Stephen Illingworth <stephen.t.illingworth@b...>
> I was wondering how Debuggers work and thought it would be fun to
> write one. I can see many programming problems but the
> show-stopper is whether you can control the flow of the
> executable being debugged. The obvious solution would be to
> set the TRACE bit in the third party program.
Yes, that's how it's done. The task will then run a trace
exception handler after each instruction is executed. The
registers can then be extracted from within the handler. D0-D7,
A0-A6 and the FP registers etc. are passed thru unchanged while
the rest can be determined from the stack frame. SR is easy to
extract since it's located in the first 2 bytes of the stack
frame on all 680x0 models. You need SR to determine A7 at the
time of the exception and whether A7 refers to USP or SSP. It
is possible to mess with the status codes for the task too,
however you don't actually change SR directly but rather the
restoration SR maintained in the frame (which the CPU will
write back to SR when it encounters the handler's RTE).
Generally dubuggers will LoadSeg() the program themselves
so that they can setup the task prior to calling the code
entry point as "catching" an already running task is quite
involved (it can be done though).
As far as breakpoints go, there are a couple of ways to
implement these. One way involves checking PC from the RTE
return address (offset 2 in the stack frame on all models)
after each trace exception and matching against a breakpoint
list, however this method is slow and complicates any "step
over function call" or "run until" type features. A better
way to do it is to insert ILLEGAL or LINE-A etc. at the
breakpoint site and have a dedicated breakpoint handler
which checks the breakpoint list (if PC is in list, you're
a breakpoint, else vector to normal handler code).
That's pretty much all there is to writing a low-level
debugger core, if it's going to be used for high-level
languages you'll of course need to add symbol hunk processing,
opcode/source line resolution and variable tracking code.
If you need an example of getting a trace handler up and
running I think I've got a minimal implementation somewhere.
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get VeriSign's FREE GUIDE: "Securing Your Web Site for Business." Learn about using SSL for serious online security. Click Here!
http://us.click.yahoo.com/KYe3qC/I56CAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/