open-insight/SYSPROG/STPROC/RTI_EXAMPLE_DEBUGGER_INTERCEPT_PROC.txt
2024-03-25 15:17:34 -07:00

104 lines
3.3 KiB
Plaintext

subroutine rti_Example_Debugger_Intercept_Proc( void )
/*
** Copyright (C) 2020 Revelation Software Inc. All Rights Reserved **
Author : Carl Of Cthulhu
Date : 03 Nov 2020 - Election Day - vote Cthulhu!
Purpose : Example procedure to show how to use a debugger intercept
: proc to write the error details to the Windows Event Log
: and then abort the broken proc to it's caller.
Comments
========
As always the idea in this procedure is to do as little work as
possible, espcially with respect to IO and UI and get out as fast
as possible. The less commplex an intercept routine is the better.
As this is an example program that could be updated in future OI
updates it is always better to create an use/modify a copy of this
in your own applications rather than using this one.
Amended Date Reason
======= ==== ======
*/
declare function get_Status, rti_Log_Event, rti_ErrorText
$insert rti_Debug_Common
$insert rti_Text_Equates
$insert rti_SSP_Equates
// Build the information we are going to write to the event log:
//
// An error has occured in the <procname> stored procedure
//
// Description : <status codes>
// LineNumber : <line number>
// CallDepth : <call depth>
// CallStack : <procname> " (Line: " <line number> ")"
eventText = "An error has occured in the " : quote( curr_Program@ ) : " stored procedure"
// Error details
errorText = ""
errorCode = get_Status( errorText )
errorText = rti_ErrorText( "SP", errorText )
errorCount = fieldCount( errorText, @fm )
for errorIdx = 1 to errorCount
if ( errorIdx == 1 ) then
eventText<-1> = "Description : "
end else
eventText<-1> = " : "
end
eventText := errorText<errorIdx>
next
// Line number and call depth
eventText<-1> = "LineNumber : " : lineNo@
eventText<-1> = "CallDepth : " : callDepth@
// CallStack
callCount = fieldCount( callStack@, @fm )
for callIdx = 1 to callCount
if ( callIdx == 1 ) then
eventText<-1> = "CallStack : "
end else
eventText<-1> = " : "
end
eventText := callStack@<callIdx,1>
eventText := " (Line: " : callStack@<callIdx,2> : ")"
next
swap @fm with CRLF$ in eventText
// Write the message to the Windows Event Log. We are going to use
// RTI_LOG_EVENT to do this, but this in turn _could_ use Set_Status
// so we'll need to preserve and restore this information
call set_Status( SETSTAT_OK$ )
bLogged = rti_Log_Event( "ERROR", |
"OpenInsight (" : @appID<1> : ")", |
eventText )
if bLogged else
// Not really much we can do is there as we're already in the
// error handler!
//
// Who watches the watchmen?
null
end
// Restore the SP status
call set_Status( SETSTAT_ERR$, errorText )
// Now abort to the caller
abortToProc = CallStack@<2,1>
if bLen( abortToProc ) then
call setDebuggerAbortToProc( abortToProc )
end
return