user manual

Preserving the Debugger Operating Environment
B-41
B
It may happen that your program uses one or more of the exception
vectors that are required for debugger operation. Debugger
facilities may still be used, however, if your exception handler can
determine when to handle the exception itself and when to pass the
exception to the debugger.
When an exception occurs which you want to pass on to the
debugger; i.e., ABORT, your exception handler must read the
vector offset from the format word of the exception stack frame.
This offset is added to the address of the 177Bug target program
vector table (which your program saved), yielding the address of
the 177Bug exception vector. The program then jumps to the
address stored at this vector location, which is the address of the
177Bug exception handler.
Your program must make sure that there is an exception stack
frame in the stack, and that it is exactly the same as the processor
would have created for the particular exception before jumping to
the address of the exception handler.
The following is an example of an exception handler which can pass
an exception along to the debugger:
*
*** EXCEPT - Exception handler ****
*
EXCEPT SUBQ.L #4,A7 Save space in stack for a PC value.
LINK A6,#0 Frame pointer for accessing PC space.
MOVEM.L A0-A5/D0-D7,-(SP) Save registers.
:
: decide here if your code handles exception, if so, branch...
:
MOVE.L BUFVBR,A0 Pass exception to debugger; Get saved VBR.
MOVE.W 14(A6),D0 Get the vector offset from stack frame.
AND.W #$0FFF,D0 Mask off the format information.
MOVE.L (A0,D0.W),4(A6) Store address of debugger exc handler.
MOVEM.L (SP)+,A0-A5/D0-D7 Restore registers.
UNLK A6
RTS Put addr of exc handler into PC and go.