[mod.computers.vax] Useful VMS routine: del_handler

ted@blia.UUCP.UUCP (04/10/87)

I recently wrote a subroutine for a colleague and it seems like such a useful
little thing that I decided to post it.

My colleague is writing a shareable image to replace an existing one. He is
debugging it by running an outside supplied program designed to use the
original shareable image. The problem is that this program establishes an
exception handler which prevents him from getting control in the debugger if
his code gets an exception.

My answer was the attached MACRO-32 subroutine: del_handler. It backs up
through the stack looking for call frames with handlers established. When
it fins one, it "deletes" the handler by establishing in its place a dummy
handler that simply re-signals the the exception. The one argument is the
number of handlers to delete. If called with no arguments, it defaults to 1.

Note that because the handler address in the frames is changed, not zeroed,
successive calls to del_handler will affect the same frames.

As an example, routine A establishes a handler and calls B. B establishes a
handler and calls C. C calls D. D establishes a handler and calls E. E calls
F. F calls del_handler(2) and then signals an exception. The handlers
established by D and B are disabled and the one established by A gets first
crack at the exception.

-- 
===============================================================================
            Ted Marshall
            Britton Lee, Inc.
p-mail:     14600 Winchester Blvd, Los Gatos, Ca 95030
voice:      (408)378-7000
uucp:       ...!ucbvax!mtxinu!blia!ted
ARPA:       mtxinu!blia!ted@Berkeley.EDU
disclaimer: These opinions are my own and may not reflect those of my employer;
            I leave them alone and they leave me alone.

-------------------------------------cut here----------------------------------
$ ! This is a VMS DCL archive. Remove all lines above this one and run as a
$ ! command file.
$
$ create delhandler.mar
$ deck/dollars="4SCOREAND7"
	.title	DELHANDLER -- delete previously established exception handlers

; routine name: del_handler
;
; This routine backs up through call frames on the stack deleting the
; specified number of exception handler establishments. If called with
; no arguments, it un-establishes the one most recently established handler.
; If called with an argument, that argument is the number of handlers to
; un-establish.
;
; A handler is un-established by replacing it with a dummy handler that just
; re-signals the exception. This way, calling the routine twice with an
; argument of 3 will delete 3 handlers, not 6.
;
; Author:	Ted Marshall	10-April-1987
;
; Copyright 1987, Britton Lee, Inc.
; 14600 Winchester Blvd, Los Gatos, CA 95030
; Permission granted for free and unlimited use and distribution so long as
; this copyright notice is retained in full in the source.
;
; This software is provided "as-is" and the author and Britton Lee, Inc.
; assume no responsibility for its correct operation or the effects of its
; use.
;

	.psect	dhcode,rd,nowrt,shr,exe,pic

	.entry	del_handler,0

	movl	#1,r1			; Default to deleting one handler.
	tstl	0(ap)			; Did they give an argument?
	beql	10$
	movl	4(ap),r1		; Yes- that's the number to delete.
	beql	99$			; If arg = 0, just return.
10$:
	movl	fp,r0			; Get the address of the current frame.
20$:					; Start of loop.
	movl	12(r0),r0		; Get the previous frame.
	tstl	(r0)			; Is there an exception handler?
	beql	20$			; No- keep looping.

	movab	_mydummyhndlr,(r0)	; Yes- substitute a dummy handler.
	sobgtr	r1,20$			; If more to delete, keep looping.

99$:
	ret


	.entry	_mydummyhndlr,0

	clrl	r0			; Resignal.
	ret

	.end
4SCOREAND7
$ checksum delhandler.mar
$ if checksum$checksum .eq. 223311206 then goto ok
$ write sys$output "Incorrect checksum! File is munged, sorry!"
$ exit 42
$
$ ok:
$ write sys$output "DELHANDLER.MAR correctly created."
$ exit